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

ALPBIND.m

Go to the documentation of this file.
ALPBIND ;OIFO-DALLAS/SED/KC/MW  BCMA-BCBU INPT TO HL7 INIT ;07/06/16 7:06am
 ;;3.0;BAR CODE MED ADMIN;**8,73,87,115**;Mar 2004;Build 3
 ;
 ; Reference/IA
 ; DPT/10035
 ; DIC(42/10039
 ; DIC(42/2440
 ; EN^PSJBCBU/3876
 ;
 ;*87 - Fix VistA Init by DIV option where Clinic orders will check if
 ;      they point to DIV requested.
 Q
OPT ;Entry point for the option
 ;Select Workstations assigned to Default.
DFT K ALPHLL,DIR,ALPDIV,DTOUT,DUOUT,DIRUT,DIROUT,ALPHLINI
 D GET^ALPBPARM(.ALPHLL,"")
 I '$D(ALPHLL) W !,"No workstations defined for default " G EXIT
 D ALLWKS
 ;D:'$D(DIRUT) QUE
 D QUE
 G EXIT
 ;
ALLWKS ;If no then set allow the user to select the workstation
 K DTOUT,DUOUT,DIRUT,DIROUT,DIR
 S DIR(0)="Y",DIR("B")="YES"
 S DIR("A")="Enter Yes or No"
 S DIR("A",1)="Include all workstations"
 D ^DIR
 I $D(DIRUT) Q
 S ALPWKS=+Y
 I +ALPWKS>0 Q
 ;
WRKSTN ;Now select which workstations to be initialized
 K ALPSCRN,ALPBANS
 ;Set up screen
 S ALP=0 F  S ALP=$O(ALPHLL("LINKS",ALP))  Q:+ALP'>0  D
 . S ALPSCRN($P(ALPHLL("LINKS",ALP),U,2),ALP)=ALPHLL("LINKS",ALP)
 K ALPHLL
 F  D LP Q:$D(DIRUT)
 ;I $D(DIRUT)&($D(ALPHLL)) W !!,"No Selected Workstations" G ALLWKS
 I '$D(ALPBANS)!$D(ALPHLL) W !!,"No Selected Workstations" G ALLWKS
 Q:'$D(ALPBANS)
 S ALP="",ALPCNT=1
 F  S ALP=$O(ALPBANS(ALP)) Q:ALP=""  D
 . S ALPHLL("LINKS",ALPCNT)=ALPSCRN(ALP,$O(ALPSCRN(ALP,0)))
 . S ALPHLINI(ALPHLL("LINKS",ALPCNT))=""
 . S ALPCNT=ALPCNT+1
 K ALPSCRN,ALPBANS
 Q
 ;
LP ;Multiple entries
 K DIR,DTOUT,DUOUT,DIRUT,DIROUT
 S DIR(0)="PO^870:EMZ",DIR("A")="Select WorkStation Link "
 S DIR("?")="Answer with WorkStation Link to update "
 S DIR("S")="I $D(ALPSCRN($P(^HLCS(870,+Y,0),U,1)))"
 D ^DIR
 Q:$D(DIRUT)
 S ALPBANS($P(Y,U,2),+Y)=""
 W #,!!,"Selected Workstations",!!
 S ALPB=""
 F ALP=1:1 S ALPB=$O(ALPBANS(ALPB)) Q:ALPB=""  D
 .W ?$S(ALP#2:1,1:40),ALPB
 .W:ALP#2'>0 !
 Q
 ;
QUE ;Que the job
 S ZTRTN="EN^ALPBIND"
 S ZTDESC="PSB - Initialize Default Contingency Workstation"
 S ZTIO="",ZTSAVE("ALPWKS")=""
 I $D(ALPHLL) S ZTSAVE("ALPHLL(")=""
 I $D(ALPHLINI) S ZTSAVE("ALPHLINI(")=""
 D ^%ZTLOAD
 W:$D(ZTSK) !,ZTSK
 K ZTIO,ZTDESC,ZTRTN,ZTSK
 Q
EN ;Loop through the inpatient list.
 Q:'$D(ALPHLL)
 S ALPDTS=$$FMTE^XLFDT($$NOW^XLFDT)
 K ALPSCR
 S ALPSTOP=0,ALPOK=1
 S ALPCN=""
 F  S ALPCN=$O(^DPT("CN",ALPCN)) Q:ALPCN=""!(ALPSTOP)  D  ;Ward Location(CN)
 . ;DIVISION SCREEN HERE
 . S ALPCNI=$O(^DIC(42,"B",ALPCN,0))  ;Ward Name(B)
 . Q:+ALPCNI'>0  ;Quit if I can't decipher the Ward Location
 . S ALPDIV=$P($G(^DIC(42,ALPCNI,0)),U,11)
 . ;Check to see is the Division has Machines defined to it.
 . ;if it does then it is not to go to default
 . K ALPTEST
 . D GET^ALPBPARM(.ALPTEST,ALPDIV,1)
 . Q:$D(ALPTEST)
 . S ALPSTOP=$$S^%ZTLOAD()
 . S ALDFN=0
 . F  S ALDFN=$O(^DPT("CN",ALPCN,ALDFN)) Q:+ALDFN'>0!(ALPSTOP)  D PAT("")   ;null selected Div param *87
 ;
 N ALPNOWCL S ALPNOWCL=$$NOW^XLFDT()
 D UDCLIN(ALPNOWCL,"")                      ;null selected Div par *87
 D IVCLIN(ALPNOWCL,"")                      ;null selected Div par *87
 ;
 K XQA,XQAMSG
 S ALPDTE=$$FMTE^XLFDT($$NOW^XLFDT)
 S XQA(DUZ)=""
 S XQAMSG="BCBU WORKSTATION INIT Started "_ALPDTS_" and finished "_ALPDTE_". "
 ;_ALPBK_" entries sent."
 D SETUP^XQALERT
EXIT ;
 K ALPDTS,ALPDTE,ALPCNT
 K ALPB,ALPBI,ALPBJ,ALPCN,ALDFN,ALPMDT,ALPML,ALPORDR,MSCTR,MSH,ORC
 K PID,PV1,ALPHLL,ALPALL,DIR,Y,DTOUT,DUOUT,DIRUT,DIROUT,ALPDIV,ALPHLINI
 K ALPTST,ALPSTOP,ALPOK,ZTSAVE,ALPCNI,ALPCNT,ALP,ALPDVN,ALPSLT,ALPWKS
 K PID,PV1,^TMP("PSJ",$J),^TMP("PSJBU",$J)
 ;
 Q
MLOG ;Need to loop though the Med log file to get all med logs
 ;associated with the order
 Q:'$D(^PSB(53.79,"AORDX",ALDFN,ALPORDR))
 S X=+$$GET^XPAR("PKG.BAR CODE MED ADMIN","PSB BKUP MEDLG",1,"Q")
 S X=$S(X>0:"T-"_X,1:"T-30")
 D ^%DT
 Q:+Y'>0  ;Cannot get a valid date
 S ALPMDT=Y
 F  S ALPMDT=$O(^PSB(53.79,"AORDX",ALDFN,ALPORDR,ALPMDT)) Q:+ALPMDT'>0  D
 . S ALPML=0
 . F  S ALPML=$O(^PSB(53.79,"AORDX",ALDFN,ALPORDR,ALPMDT,ALPML)) Q:+ALPML'>0  D
 . . Q:+$P($G(^PSB(53.79,ALPML,0)),U,1)'>0  ; Bad Med-log
 . . S ALPRSLT=$$MEDL^ALPBINP(ALPML)
 Q
MESS ;BUILD AND SEND MESSAGE
 K ALPB
 D EN^PSJBCBU(ALDFN,ALPORDR,.ALPB)
 S ALPBI=0
 F  S ALPBI=$O(ALPB(ALPBI)) Q:ALPBI'>0  D
 . I $E(ALPB(ALPBI),1,3)="MSH" S MSH=ALPBI
 . I $E(ALPB(ALPBI),1,3)="PID" S PID=ALPBI
 . I $E(ALPB(ALPBI),1,3)="PV1" S PV1=ALPBI
 . I $E(ALPB(ALPBI),1,3)="ORC" S ORC=ALPBI
 I +MSH'>0 Q   ;MISSING MSH SEGMENT BAD MESSAGE
 S MSCTR=$E(ALPB(MSH),4,8),ALPORD=ALPORDR
 S X=$$INI^ALPBINP()
 Q
SNDPT ;Send a Single Patient
 K DIR,DTOUT,DUOUT,DIRUT,DIROUT
 S DIR(0)="PO^2:EM",DIR("A")="Select Patient "
 D ^DIR
 Q:$D(DIRUT)
 Q:+Y'>0
 S ALDFN=+Y
 W !!,"Please Hold On While I send the orders",!!
 D PAT("")
 Q
 ;
PAT(ALPDIV2) ;Process and send patients  ;add DIV par specl for DIV init *87
 ;New Div variable, reused in some downstream function calls    ;*87
 N ALPDIV
 K ^TMP("PSJBU",$J)
 S X=+$$GET^XPAR("PKG.BAR CODE MED ADMIN","PSB BKUP IPH",1,"Q")
 S X=$S(X>0:"T-"_X,1:"T-15")
 D ^%DT
 Q:+Y'>0  ;Cannot get a valid date
 D EN2^PSJBCBU(ALDFN,Y)
 Q:'$D(^TMP("PSJBU",$J))  ; NO DATA
 S ALPBJ=0
 F  S ALPBJ=$O(^TMP("PSJBU",$J,ALPBJ)) Q:+ALPBJ'>0  D
 . Q:'$D(^TMP("PSJBU",$J,ALPBJ,0))
 . S ALPORDR=$P(^TMP("PSJBU",$J,ALPBJ,0),U,3)
 . Q:+ALPORDR'>0
 . D MESS
 . Q:ALPORDR["P"  ;If not pending do Med-Log
 . D MLOG
 S ALPSTOP=$$S^%ZTLOAD()
 Q
 ;
UDCLIN(ALPNOW,ALPDIV2) ; Unit Dose Clinic Orders                     ;*87
 N ALPSEND,ALPCSTPD,ALPCN,ALPDFNAR S ALPCSTPD=ALPNOW
 F  S ALPCSTPD=$O(^PS(55,"AUDC",ALPCSTPD)) Q:ALPCSTPD=""  S ALPCN="" F  S ALPCN=$O(^PS(55,"AUDC",ALPCSTPD,ALPCN)) Q:ALPCN=""  D
 . ;DIVISION SCREEN
 . Q:+ALPCN'>0                                               ;*87
 . S ALPSEND=0                                               ;*87
 . S ALPDIV=$P($G(^SC(ALPCN,0)),"^",15)                      ;*87
 . ;Screen If DIV Init, If Clinic is in DIV send it.  If ALPDIV2=0, ALL DIV was selected in ^ALPBIN  ;*87
 . S ALPSEND=$S(ALPDIV2&(ALPDIV2=ALPDIV):1,ALPDIV2=0:1,1:0)  ;*87
 . ;Check for DFT                                            ;*87
 . K ALPTEST
 . D GET^ALPBPARM(.ALPTEST,ALPDIV,1)
 . ;If Links defined and Init was not a Divisional init then Q  ;*87
 . Q:$D(ALPTEST)&($G(ALPSEND)=0)                                ;*87
 . S ALPSTOP=$$S^%ZTLOAD()
 . S ALDFN=0
 . F  S ALDFN=$O(^PS(55,"AUDC",ALPCSTPD,ALPCN,ALDFN)) Q:'ALDFN  S ALPDFNAR(ALDFN)=""
 S ALDFN=0
 F  S ALDFN=$O(ALPDFNAR(ALDFN)) Q:'ALDFN!$G(ALPSTOP)  D PAT(ALPDIV2)    ;pass Div par *87
 Q
 ;
IVCLIN(ALPNOW,ALPDIV2) ; IV Clinic Orders
 N ALPSEND,ALPCSTPD,ALPCN,ALPDFNAR S ALPCSTPD=ALPNOW
 F  S ALPCSTPD=$O(^PS(55,"AIVC",ALPCSTPD)) Q:ALPCSTPD=""  S ALPCN="" F  S ALPCN=$O(^PS(55,"AIVC",ALPCSTPD,ALPCN)) Q:ALPCN=""  D
 . ;DIVISION SCREEN
 . Q:+ALPCN'>0                                               ;*87
 . S ALPSEND=0                                               ;*87
 . S ALPDIV=$P($G(^SC(ALPCN,0)),"^",15)                      ;*87
 . ;Screen If DIV Init, If Clinic is in DIV send it.  If ALPDIV2=0, ALL DIV was selected in ^ALPBIN  ;*87
 . S ALPSEND=$S(ALPDIV2&(ALPDIV2=ALPDIV):1,ALPDIV2=0:1,1:0)  ;*87
 . ;Check for DFT                                            ;*87
 . K ALPTEST
 . D GET^ALPBPARM(.ALPTEST,ALPDIV,1)
 . ;If Links defined and Init was not a Divisional init then Q  ;*87
 . Q:$D(ALPTEST)&($G(ALPSEND)=0)                                ;*87
 . S ALPSTOP=$$S^%ZTLOAD()
 . S ALDFN=0
 . F  S ALDFN=$O(^PS(55,"AIVC",ALPCSTPD,ALPCN,ALDFN)) Q:'ALDFN  S ALPDFNAR(ALDFN)=""
 S ALDFN=0
 F  S ALDFN=$O(ALPDFNAR(ALDFN)) Q:'ALDFN!$G(ALPSTOP)  D PAT(ALPDIV2)    ;pass Div par *87
 Q