Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: AMERBSDU

AMERBSDU.m

Go to the documentation of this file.
AMERBSDU ; IHS/OIT/SCR - PRIMARY ROUTINE FOR INTERFACE WITH PIMS OUTSIDE OF AMER NAMESPACE
 ;;3.0;ER VISIT SYSTEM;**1,2,5**;MAR 03, 2009;Build 14
 ;
APPNTMNT(AMERDFN,AMERTALK,AMERTIME,AMERARR) ; EP FROM AMER1 and ERCHECKIN
 ; called by AMER1 to display scheduled appoitments for all clinics from day of admission forward
 ; called by ERCHEKIN to populate array of scheduled appointments for further refinement
 ;
 ; AMERTALK=1 means display results to current device
 ; AMERTALK=0 means be silent
 ; AMERTIME = DATE/TIME OF ER ADMISSION
 ; AMERARR = "AMERARR("  -->PASSED BY REFERENCE - DATA IS RETURNED IN ARRAY AMERARR(
 ;    array(2-9999)=date^clinic name^other info
 ; AMERARR="" NO ARRAY IS POPULATED
 ;
 NEW AMERLN,AMERDT,AMERCNT,X,I,AMERNODE,AMERSP
 S AMERSP=$S(AMERTALK:"  ",1:U)                ;data item separator
 S AMERCNT=1,AMERDT=$P(AMERTIME,".",1) ;start with day of appointment
 F  S AMERDT=$O(^DPT(AMERDFN,"S",AMERDT)) Q:'AMERDT  D
 .S AMERNODE=$G(^DPT(AMERDFN,"S",AMERDT,0))  Q:'AMERNODE
 .Q:$P(AMERNODE,U,2)["C"                        ;skip if canceled
 .I $P(AMERNODE,U,2)["N",$P(AMERNODE,U,2)'="NT" Q   ;skip if no-show
 .; if lab, x-ray or ekg appts set, display first
 .F I=3,4,5 S X=$P(AMERNODE,U,I) Q:X[""  D
 ..S AMERCNT=AMERCNT+1
 ..S AMERLN(AMERCNT)=$$FMTE^XLFDT(X)_AMERSP_$P("LAB^X-RAY^EKG",U,I-2)
 .; then display this appt
 .S AMERCNT=$G(AMERCNT)+1
 .S X=$$FMTE^XLFDT(AMERDT)_AMERSP_$$GET1^DIQ(44,+AMERNODE,.01)
 .S AMERLN(AMERCNT)=$$PAD(X,43)_AMERSP_$E($$OI^BSDU2(AMERDFN,+AMERNODE,AMERDT),1,34)
 .S AMERLN(AMERCNT,0)=+AMERNODE
 I AMERCNT>1 D
 .S AMERLN(1,"F")="!!?20",AMERLN(1)="**** APPOINTMENTS FROM TODAY FORWARD ****"
 .F I=1:1:AMERCNT S AMERLN(AMERCNT,"F")="!"
 E  S AMERLN(1)="No Pending Appointments",AMERLN(1,"F")="!"
 I $G(AMERTALK) D EN^DDIOL(.AMERLN) ;print to current device
 ;return data in array
 I $D(AMERARR) D
 .NEW %X,%Y
 .S %X="AMERLN(",%Y=AMERARR
 .D %XY^%RCR
 Q
 ;
GETAPPS(AMERDFN,AMERTIME,AMERARR)  ;
 ;This sub-routine GETS any ER appointmentS for this patient on the day of the ER VISIT
 ;If an appointment exists (that has not been canceled)
 ;
 ;RETURNS AMERARR - AN ARRAY OF ER APPOINTMENTS FOR THIS DFN ON THE DATE OF AMERTIME
 ;                PASSED BY VALUE AND POPULATED UPON RETURN
 ;
 ;array(2-9999)=date^clinic name^other info^isCheckedIn
 ;
 ;INPUT: AMERDFN - THE PATIENT WHO'S APPOINTMENTS ARE BEING LOOKED UP
 ;       AMERTIME : THE DATE/TIME OF THE ER VISIT 
 ;
 ;
 N AMERCNT,AMERSDTM,AMERSDCL,AMERLOC,AMERQUIT,AMERCNT2,AMERSCIE
 S AMERCNT=0,AMERQUIT=0
 D APPNTMNT^AMERBSDU(AMERDFN,0,AMERTIME,.AMERARR)
 I $G(AMERARR(2))'="" D  ;THERE ARE SCHEDULED VISITS FOR THIS PATIENT - NOW FIND OUT IF ONE OF THEM IS FOR TODAY AT THIS CLINIC
 .S AMERCNT=1,AMERCNT2=0
 .F  S AMERCNT=$O(AMERARR(AMERCNT)) Q:AMERCNT=""  D
 ..S AMERSDCL=$G(AMERARR(AMERCNT,0))  ;SCHEDULED CLINIC
 ..S AMERLOC=$G(^AMER(2.5,+$G(DUZ(2)),"SD")) ;THIS IS A POINTER TO THE HOSPITAL LOCATION FILE THAT IDENTIFIES THE ERS CLINIC
 ..Q:AMERLOC=""
 ..I AMERLOC=AMERSDCL D   ;IF THE SCHEDULED CLINIC IS THE CLINIC THAT IS RUNNING THIS PACKAGE
 ...S AMERSDTM=$P(AMERARR(AMERCNT),U,1)  ;SCHEDULED TIME
 ...S %DT="T",X=AMERSDTM D ^%DT S AMERSDTM=Y K %DT ;SCHEDULED TIME IN FM FORMAT
 ...S AMERSCIE=$$SCIEN^BSDU2(AMERDFN,AMERSDCL,AMERSDTM) ;get schedule ien
 ...;S $P(AMERRARR(AMERCNT),U,4)=$$CI^BSDU2(AMERDFN,AMERSDCL,AMERSDTM,AMERSCIE)  ;find out if patient is checked in
 ...S $P(AMERARR(AMERCNT),U,4)=$$CI^BSDU2(AMERDFN,AMERSDCL,AMERSDTM,AMERSCIE)  ;find out if patient is checked in
 ...I $P(AMERSDTM,".",1)=$P(AMERTIME,".",1) D   ;IF THE APPOINTMENT IS FOR SOME TIME of the day of admission...
 ....S AMERCNT2=AMERCNT2+1
 ....D EN^DDIOL("***THIS PATIENT HAS AN APPOINTMENT IN THIS CLINIC TODAY***","","!?4")
 ....D EN^DDIOL($P(AMERARR(AMERCNT),U,2)_" FOR : "_$P(AMERARR(AMERCNT),U,1),"","!?10")
 ....Q
 ...I $P(AMERSDTM,".",1)'=$P(AMERTIME,".",1) S AMERRARR(AMERCNT)="" ;IF THE APPOINTMENT IS NOT FOR TODAY, REMOVE FROM ARRAY
 ...Q
 ..I AMERLOC'=AMERSDCL S AMERARR(AMERCNT)=""
 ..Q
 .Q
 Q
ERCHCKIN(AMERDFN,AMERTIME) ; EP FROM AMER0 after admission information has been collected
 ; INPUT: AMERDFN - PATIENT IEN OF PATIENT BEING CHECKED INTO SCHEDULING
 ;        AMERTIME - TIME OF ADMISSION COLLECTED FROM ERS INTERFACE
 ;
 ; RETURNS: AMERPCC - THE IEN OF THE PCC VISIT FILE THAT WAS CREATED FOR THIS APPOINTMENT
 N AMERARR,AMERNUM,AMERPCC,AMERANS,DIR,Y,AMERSDTM,AMERDONE,X
 S AMERPCC=0,AMERDONE=0
 S AMERARR="AMERARR("
 D GETAPPS(AMERDFN,AMERTIME,.AMERARR)  ; THIS RETURNS AN ARRAY OF APPOINMENTS for this date
 ;AMERARR(2-9999)=date^clinic name^other info^isCheckedIn
 S AMERNUM=0,AMERNUM=$O(AMERARR(0))
 ;ASK A USER TO SELECT ONE OF THE TIMES IN THE ARRAY
 F  Q:AMERNUM=""!(AMERPCC'=0)  D
 .S AMERNUM=$O(AMERARR(AMERNUM))
 .Q:AMERNUM=""
 .I $G(AMERARR(AMERNUM))'="" D
 ..D EN^DDIOL("PATIENT IS SCHEDULED FOR: "_$P(AMERARR(AMERNUM),U,1),"","!!")
 ..I $P(AMERARR(AMERNUM),U,2)'="" D EN^DDIOL("OTHER INFO: : "_$P(AMERARR(AMERNUM),U,3),"","!")
 ..;IHS/OIT/SCR 05/21/09 don't ask to check in unless ER Visit day is same as scheduled day
 ..S X=$P($P(AMERARR(AMERNUM),U,1),"@",1)
 ..D ^%DT
 ..Q:Y'=$P(AMERTIME,".",1)
 ..S DIR("A")="Check-in to this scheduled visit"
 ..S DIR(0)="Y",DIR("B")="NO"
 ..D ^DIR
 ..S AMERANS=Y
 ..I AMERANS=1 D
 ...S %DT="T",X=$P(AMERARR(AMERNUM),U,1) D ^%DT S AMERSDTM=Y K %DT  ;PUT SCHEDULED TIME IN FM FORMAT
 ...S AMERPCC=$$SCHEDULD^AMERPCC(AMERDFN,AMERTIME,AMERSDTM)
 ...I +AMERPCC>0 D
 ....D EN^DDIOL("CREATED PCC VISIT "_AMERPCC_" FOR ER APPOINTMENT : "_$P(AMERARR(AMERNUM),U,1),"","!!")
 ....D EN^AMERCLP(AMERDFN)
 ....D RTNGSLP^AMERVSIT(AMERDFN,AMERTIME)
 ....Q
 ...I +AMERPCC<0 D
 ....;D EN^DDIOL("THERE WAS A PROBLEM WITH THE ER - PIMS INTERFACE","","!") ;IHS/OIT/SCR 060109 removed patch 1
 ....;D EN^DDIOL($P(AMERPCC,U,2),"","!")
 ....;D EN^DDIOL("NO PCC VISIT CREATED","","!")
 ....H 2
 ....Q
 ..I AMERANS'=1  D
 ...D EN^DDIOL("BY-PASSING THIS APPOINTMENT: "_$P(AMERARR(AMERNUM),U,1),"","!!")
 ..Q
 .Q
 I AMERPCC=0 D  ;NO ER APPOINTMENT WAS SELECTED FOR CHECK-IN
 .S AMERPCC=$$VISIT^AMERPCC(AMERDFN,AMERTIME) ;CREATES AND CHECKS-IN A WALK-IN VISIT FOR THIS TIM
 .I $P(AMERPCC,U,1)>0 D
 ..D EN^AMERCLP(AMERDFN)
 ..D RTNGSLP^AMERVSIT(AMERDFN,AMERTIME)
 ..Q
 .I $P(AMERPCC,U,1)<0 D
 ..;D EN^DDIOL("THERE WAS A PROBLEM WITH THE ER - PIMS INTERFACE","","!")
 ..D EN^DDIOL($P(AMERPCC,U,2),"","!")
 ..;D EN^DDIOL("NO PCC VISIT CREATED","","!")
 ..H 2
 ..Q
 .Q
 Q +AMERPCC
PAD(D,L) ;localcopy of BSDU2^PAD
 ; -- D=data L=length
 Q $E(D_$$REPEAT^XLFSTR(" ",L),1,L)
CANCEL(AMERDFN,AMERTIME) ;EP FROM 
 ;IHS/OIT/SCR 10/27/08 CANCEL PIMS SCHEDULED ER VISIT WHEN THE VISIT IS DELETED
 ; Make call using: S ERR=$$CANCEL^BSDAPI(.ARRAY)
 ;
 ; Input Array -
 ; BSDR("PAT") = ien of patient in file 2
 ; BSDR("CLN") = ien of clinic in file 44
 ; BSDR("TYP") = C for canceled by clinic; PC for patient canceled
 ; BSDR("ADT") = appointment date and time
 ; BSDR("CDT") = cancel date and time
 ; BSDR("USR") = user who canceled appt
 ; BSDR("CR")  = cancel reason - pointer to file 409.2
 ; BSDR("NOT") = cancel remarks - optional notes to 160 characters
 ;
 ;Output: error status and message
 ;   = 0 or null:  everything okay
 N AMERBSDR,AMERINDX,%
 S AMERBSDR("PAT")=AMERDFN
 S AMERCLN=$G(^AMER(2.5,DUZ(2),"SD"))
 S AMERBSDR("CLN")=AMERCLN
 S AMERBSDR("TYP")="C"
 S AMERBSDR("ADT")=AMERTIME
 D NOW^%DTC
 S AMERBSDR("CDT")=%
 S AMERBSDR("USR")=DUZ
 S DIC="^SD(409.2,",DIC(0)="XZ",X="OTHER"
 D ^DIC
 S AMERBSDR("CR")=+Y
 S AMERBSDR("NOT")="PATIENT REGISTERED IN ERROR THROUGH ERS"
 S AMERERR=$$CANCEL^BSDAPI(.AMERBSDR)
 D:AMERERR EN^DDIOL("UNABLE TO CANCEL THE SCHEDULED PIMS APPOINTMENT!","","!")
 Q