PSBAPIPM ;BIRMINGHAM/EFC-BCMA API TO IPM FOR ORDER RENEWAL ;Mar 2004
;;3.0;BAR CODE MED ADMIN;**6,15**;Mar 2004
;
;
EN(PSBDFN,PSBORDX) ;
;
; PSBLADT=date/time of the last action
; PSBADMDT=scheduled time of the last action
; PSBSTUS=last action (given, held, refused, etc.)
;
;
S (PSBCNT,PSBFLAG)=0,Y=""
S PSBSTR=""
I '$D(^PSB(53.79,"AORDX",PSBDFN,PSBORDX)) Q ""
F S Y=$O(^PSB(53.79,"AORDX",PSBDFN,PSBORDX,Y),-1) Q:Y="" Q:PSBFLAG=1 D
.S PSBLADT=$S(Y:Y,1:"")
.S X="" F S X=$O(^PSB(53.79,"AORDX",PSBDFN,PSBORDX,Y,X),-1) Q:X="" D
..S PSBSTUS=$P(^PSB(53.79,X,0),U,9) I PSBSTUS'="N" S PSBFLAG=1
..S PSBADMDT=$P(^PSB(53.79,X,.1),U,3)
..D:PSBSTUS="N"
...S (PSBLADT,PSBSTUS,PSBADMDT)=""
...S Z="" F S Z=$O(^PSB(53.79,X,.9,Z),-1) Q:'Z Q:PSBFLAG=1 S PSBDATA=$G(^(Z,0)) D
....I (PSBDATA["Set to 'NOT GIVEN'")!(PSBDATA["Set to 'GIVEN'")!(PSBDATA["Set to 'REFUSED'")!(PSBDATA["Set to 'HELD'")!(PSBDATA["Set to 'MISSING DOSE'")!(PSBDATA["Set to 'REMOVED'") S PSBCNT=PSBCNT+1
....I (PSBDATA["STATUS 'HELD'")!(PSBDATA["STATUS 'GIVEN'")!(PSBDATA["STATUS 'REFUSED'")!(PSBDATA["STATUS 'MISSING DOSE'")!(PSBDATA["STATUS 'REMOVED'") S PSBCNT=PSBCNT+1
....I PSBCNT#2=0,PSBDATA["'REFUSED'" S PSBSTUS="R",PSBADMDT=$P(^PSB(53.79,X,.1),U,3) D LAST
....I PSBCNT#2=0,PSBDATA["'HELD'" S PSBSTUS="H",PSBADMDT=$P(^PSB(53.79,X,.1),U,3) D LAST
....I PSBCNT#2=0,PSBDATA["'MISSING DOSE'" S PSBSTUS="M",PSBADMDT=$P(^PSB(53.79,X,.1),U,3) D LAST
....I PSBCNT#2=0,PSBDATA["'REMOVED'" S PSBSTUS="RM",PSBADMDT=$P(^PSB(53.79,X,.1),U,3) D LAST
I PSBSTUS'="" S PSBSTR=PSBADMDT_U_PSBLADT_U_PSBSTUS
Q PSBSTR
;
LAST ;
S PSBCC=0
S ZZ="" F S ZZ=$O(^PSB(53.79,X,.3,ZZ),-1) Q:'ZZ Q:PSBFLAG=1 S PSBDATA2=$G(^(ZZ,0)) D
.S PSBCC=PSBCC+1
.I PSBCC=2 S PSBLADT=$P(PSBDATA2,U,3),PSBFLAG=1
Q
MOB(PSBDFN,PSBCORN) ;
I '$D(^TMP("PSBMO",$J,PSBDFN,PSBCORN)) S ^TMP("PSB",$J,0)=-1 Q
M ^TMP("PSB",$J)=^TMP("PSBMO",$J,PSBDFN,PSBCORN)
K ^TMP("PSB",$J,"PSB")
Q
;
MOBR(PSBDFN,PSBCORN,PSBORDN) ;
I $G(PSBORDN)="" K ^TMP("PSB",$J) Q
S PSBDUZ=DUZ,PSBDUZ(2)=DUZ(2),DFN=PSBDFN
S DUZ=$P(^TMP("PSBMO",$J,PSBDFN,PSBCORN,"PSB"),U,1),DUZ(2)=$P(^TMP("PSBMO",$J,PSBDFN,PSBCORN,"PSB"),U,2),PSBISITE=$P(^TMP("PSBMO",$J,PSBDFN,PSBCORN,"PSB"),U,3)
D PSJ1^PSBVT(PSBDFN,PSBORDN)
S PSBREC(0)=PSBDFN
S PSBREC(1)=PSBONX
S PSBREC(2)=PSBSCHT
S PSBREC(4)=PSBOIT
S PSBREC(5)=$P(^TMP("PSBMO",$J,PSBDFN,PSBCORN,0),U,5)
S PSBREC(6)=""
S PSBREC(7)="BCMA/CPRS Interface Entry."
S PSBREC(8)=PSBISITE
I PSBONX["U" S PSBREC(9)="UDTAB^",PSBREC(3)="G"
I PSBONX["V" D
.I "PCS"'[PSBIVT S PSBREC(9)="IVTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN),PSBREC(3)="I" Q
.I PSBIVT["S",PSBISYR=0 S PSBREC(9)="IVTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN),PSBREC(3)="I" Q
.I PSBIVT["C",PSBISYR=0 S PSBREC(9)="IVTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN),PSBREC(3)="I" Q
.S PSBREC(9)="PBTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN),PSBREC(3)="G" Q
S PSBIMV="^"_$P($G(^TMP("PSBMO",$J,PSBDFN,PSBCORN,"PSB")),U,4)
S PSBINDX=10
S X="" F S X=$O(PSBDDA(X)) Q:X="" S PSBREC(PSBINDX)=$P(PSBDDA(X),U,1,2)_U_$P(PSBDDA(X),U,4)_U_$P(PSBDDA(X),U,4)_U_PSBDOSEF,PSBINDX=PSBINDX+1
S X="" F S X=$O(PSBADA(X)) Q:X="" S PSBREC(PSBINDX)=PSBADA(X),PSBINDX=PSBINDX+1
S X="" F S X=$O(PSBSOLA(X)) Q:X="" S PSBREC(PSBINDX)=PSBSOLA(X),PSBINDX=PSBINDX+1
D RPC^PSBML(.PSB,"+1^MEDPASS"_$G(PSBIMV),.PSBREC)
S DUZ=PSBDUZ,DUZ(2)=PSBDUZ(2) K PSBDUZ,PSBDUZ(2),^TMP("PSBMO",$J,PSBREC(0),PSBCORN),^TMP("PSB",$J) D CLEAN^PSBVT
Q
PSBAPIPM ;BIRMINGHAM/EFC-BCMA API TO IPM FOR ORDER RENEWAL ;Mar 2004
+1 ;;3.0;BAR CODE MED ADMIN;**6,15**;Mar 2004
+2 ;
+3 ;
EN(PSBDFN,PSBORDX) ;
+1 ;
+2 ; PSBLADT=date/time of the last action
+3 ; PSBADMDT=scheduled time of the last action
+4 ; PSBSTUS=last action (given, held, refused, etc.)
+5 ;
+6 ;
+7 SET (PSBCNT,PSBFLAG)=0
SET Y=""
+8 SET PSBSTR=""
+9 IF '$DATA(^PSB(53.79,"AORDX",PSBDFN,PSBORDX))
QUIT ""
+10 FOR
SET Y=$ORDER(^PSB(53.79,"AORDX",PSBDFN,PSBORDX,Y),-1)
IF Y=""
QUIT
IF PSBFLAG=1
QUIT
Begin DoDot:1
+11 SET PSBLADT=$SELECT(Y:Y,1:"")
+12 SET X=""
FOR
SET X=$ORDER(^PSB(53.79,"AORDX",PSBDFN,PSBORDX,Y,X),-1)
IF X=""
QUIT
Begin DoDot:2
+13 SET PSBSTUS=$PIECE(^PSB(53.79,X,0),U,9)
IF PSBSTUS'="N"
SET PSBFLAG=1
+14 SET PSBADMDT=$PIECE(^PSB(53.79,X,.1),U,3)
+15 IF PSBSTUS="N"
Begin DoDot:3
+16 SET (PSBLADT,PSBSTUS,PSBADMDT)=""
+17 SET Z=""
FOR
SET Z=$ORDER(^PSB(53.79,X,.9,Z),-1)
IF 'Z
QUIT
IF PSBFLAG=1
QUIT
SET PSBDATA=$GET(^(Z,0))
Begin DoDot:4
+18 IF (PSBDATA["Set to 'NOT GIVEN'")!(PSBDATA["Set to 'GIVEN'")!(PSBDATA["Set to 'REFUSED'")!(PSBDATA["Set to 'HELD'")!(PSBDATA["Set to 'MISSING DOSE'")!(PSBDATA["Set to 'REMOVED'")
SET PSBCNT=PSBCNT+1
+19 IF (PSBDATA["STATUS 'HELD'")!(PSBDATA["STATUS 'GIVEN'")!(PSBDATA["STATUS 'REFUSED'")!(PSBDATA["STATUS 'MISSING DOSE'")!(PSBDATA["STATUS 'REMOVED'")
SET PSBCNT=PSBCNT+1
+20 IF PSBCNT#2=0
IF PSBDATA["'REFUSED'"
SET PSBSTUS="R"
SET PSBADMDT=$PIECE(^PSB(53.79,X,.1),U,3)
DO LAST
+21 IF PSBCNT#2=0
IF PSBDATA["'HELD'"
SET PSBSTUS="H"
SET PSBADMDT=$PIECE(^PSB(53.79,X,.1),U,3)
DO LAST
+22 IF PSBCNT#2=0
IF PSBDATA["'MISSING DOSE'"
SET PSBSTUS="M"
SET PSBADMDT=$PIECE(^PSB(53.79,X,.1),U,3)
DO LAST
+23 IF PSBCNT#2=0
IF PSBDATA["'REMOVED'"
SET PSBSTUS="RM"
SET PSBADMDT=$PIECE(^PSB(53.79,X,.1),U,3)
DO LAST
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+24 IF PSBSTUS'=""
SET PSBSTR=PSBADMDT_U_PSBLADT_U_PSBSTUS
+25 QUIT PSBSTR
+26 ;
LAST ;
+1 SET PSBCC=0
+2 SET ZZ=""
FOR
SET ZZ=$ORDER(^PSB(53.79,X,.3,ZZ),-1)
IF 'ZZ
QUIT
IF PSBFLAG=1
QUIT
SET PSBDATA2=$GET(^(ZZ,0))
Begin DoDot:1
+3 SET PSBCC=PSBCC+1
+4 IF PSBCC=2
SET PSBLADT=$PIECE(PSBDATA2,U,3)
SET PSBFLAG=1
End DoDot:1
+5 QUIT
MOB(PSBDFN,PSBCORN) ;
+1 IF '$DATA(^TMP("PSBMO",$JOB,PSBDFN,PSBCORN))
SET ^TMP("PSB",$JOB,0)=-1
QUIT
+2 MERGE ^TMP("PSB",$JOB)=^TMP("PSBMO",$JOB,PSBDFN,PSBCORN)
+3 KILL ^TMP("PSB",$JOB,"PSB")
+4 QUIT
+5 ;
MOBR(PSBDFN,PSBCORN,PSBORDN) ;
+1 IF $GET(PSBORDN)=""
KILL ^TMP("PSB",$JOB)
QUIT
+2 SET PSBDUZ=DUZ
SET PSBDUZ(2)=DUZ(2)
SET DFN=PSBDFN
+3 SET DUZ=$PIECE(^TMP("PSBMO",$JOB,PSBDFN,PSBCORN,"PSB"),U,1)
SET DUZ(2)=$PIECE(^TMP("PSBMO",$JOB,PSBDFN,PSBCORN,"PSB"),U,2)
SET PSBISITE=$PIECE(^TMP("PSBMO",$JOB,PSBDFN,PSBCORN,"PSB"),U,3)
+4 DO PSJ1^PSBVT(PSBDFN,PSBORDN)
+5 SET PSBREC(0)=PSBDFN
+6 SET PSBREC(1)=PSBONX
+7 SET PSBREC(2)=PSBSCHT
+8 SET PSBREC(4)=PSBOIT
+9 SET PSBREC(5)=$PIECE(^TMP("PSBMO",$JOB,PSBDFN,PSBCORN,0),U,5)
+10 SET PSBREC(6)=""
+11 SET PSBREC(7)="BCMA/CPRS Interface Entry."
+12 SET PSBREC(8)=PSBISITE
+13 IF PSBONX["U"
SET PSBREC(9)="UDTAB^"
SET PSBREC(3)="G"
+14 IF PSBONX["V"
Begin DoDot:1
+15 IF "PCS"'[PSBIVT
SET PSBREC(9)="IVTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN)
SET PSBREC(3)="I"
QUIT
+16 IF PSBIVT["S"
IF PSBISYR=0
SET PSBREC(9)="IVTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN)
SET PSBREC(3)="I"
QUIT
+17 IF PSBIVT["C"
IF PSBISYR=0
SET PSBREC(9)="IVTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN)
SET PSBREC(3)="I"
QUIT
+18 SET PSBREC(9)="PBTAB"_U_$$GETWSID^PSBVDLU2(PSBDFN,PSBORDN)
SET PSBREC(3)="G"
QUIT
End DoDot:1
+19 SET PSBIMV="^"_$PIECE($GET(^TMP("PSBMO",$JOB,PSBDFN,PSBCORN,"PSB")),U,4)
+20 SET PSBINDX=10
+21 SET X=""
FOR
SET X=$ORDER(PSBDDA(X))
IF X=""
QUIT
SET PSBREC(PSBINDX)=$PIECE(PSBDDA(X),U,1,2)_U_$PIECE(PSBDDA(X),U,4)_U_$PIECE(PSBDDA(X),U,4)_U_PSBDOSEF
SET PSBINDX=PSBINDX+1
+22 SET X=""
FOR
SET X=$ORDER(PSBADA(X))
IF X=""
QUIT
SET PSBREC(PSBINDX)=PSBADA(X)
SET PSBINDX=PSBINDX+1
+23 SET X=""
FOR
SET X=$ORDER(PSBSOLA(X))
IF X=""
QUIT
SET PSBREC(PSBINDX)=PSBSOLA(X)
SET PSBINDX=PSBINDX+1
+24 DO RPC^PSBML(.PSB,"+1^MEDPASS"_$GET(PSBIMV),.PSBREC)
+25 SET DUZ=PSBDUZ
SET DUZ(2)=PSBDUZ(2)
KILL PSBDUZ,PSBDUZ(2),^TMP("PSBMO",$JOB,PSBREC(0),PSBCORN),^TMP("PSB",$JOB)
DO CLEAN^PSBVT
+26 QUIT