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

PSBML3.m

Go to the documentation of this file.
PSBML3 ;BIRMINGHAM/TEJ-BCMA UTILITY TO EDIT THE PSB MED LOG ;03/06/16 3:06pm
 ;;3.0;BAR CODE MED ADMIN;**3,13,39,41,70,83**;Mar 2004;Build 89
 ;Per VHA Directive 2004-038, this routine should not be modified.
 ;
 ; Reference/IA
 ; $$GET1^DIQ/2056
 ;
 ;*70 - fix Tag CHANGE to compare the DD, Add, & Sol multiples for
 ;      only the first 5 pieces and ignore the HR flag new 6th piece.
 ;        example of pieces 1-5: "DD^363^1^3^TAB"
 ;      Edit Medlog function in BCMA uses this compare to control
 ;      Audit entries for the DD, Add, & Sol multiples & Edit Medlog
 ;      updates.
 ;*83 - check if body site is Inj or Derm & compare to correct field
 ;
APATCH ; Maintain "APATCH" index...
 I $G(PSBTRAN)["MEDPASS" D:$P(PSBREC(9),U)="UDTAB"  Q
 .S PSBX1=9,PSBQUT=0 F  S PSBX1=$O(PSBREC(PSBX1))  Q:PSBQUT  Q:'(+PSBX1)  D:$P(PSBREC(PSBX1),U)="DD"&($P(PSBREC(PSBX1),U,5)="PATCH")  Q:PSBQUT
 ..I $G(PSBOLSTS)="",PSBREC(3)="G" S PSB1="I $D(PSBIEN(1)) S ^PSB(53.79,""APATCH"","_$G(PSBREC(0))_","_$G(PSBNOW)_",+PSBIEN(1))="""""
 ..S PSBQUT=1
 S PSBX1=0 F  S PSBX1=$O(^PSB(53.79,+PSBIEN,.5,PSBX1)) Q:'(+PSBX1)  Q
 I $G(PSBTRAN)["UPDATE",(+PSBX1)'=0 D
 .S PSBX3=0 F  S PSBX3=$O(^PSB(53.79,+PSBIEN,.5,PSBX3)) Q:+PSBX3=0  I $P(^PSB(53.79,+PSBIEN,.5,PSBX3,0),U,4)="PATCH" D
 ..I PSBOLSTS="G",PSBREC(0)="N" S PSB1="K ^PSB(53.79,""APATCH"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$P(^PSB(53.79,+PSBIEN,0),U,6)_","_+PSBIEN_")"
 ..I PSBFDA(53.79,+PSBIEN_",",.09)="G" S PSB1="S ^PSB(53.79,""APATCH"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$G(PSBFDA(53.79,+PSBIEN_",",.06))_","_+PSBIEN_")"_"="""""
 I $G(PSBTRAN)["EDIT",(+PSBX1)'=0 D
 .S PSBX3=0 F  S PSBX3=$O(^PSB(53.79,+PSBIEN,.5,PSBX3)) Q:+PSBX3=0  I $P(^PSB(53.79,+PSBIEN,.5,PSBX3,0),U,4)="PATCH",((PSBREC(0)="G")!(PSBREC(0)="RM")) D
 ..S PSB1="S ^PSB(53.79,""APATCH"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$G(PSBFDA(53.79,+PSBIEN_",",.06))_","_+PSBIEN_")"_"="""""
 ..I $D(PSBREC(4,0)) S PSB2="K ^PSB(53.79,""APATCH"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$G(PSBREC(4,0))_","_+PSBIEN_")"
 Q
 ;
CHANGE(PSBREC,PSBEDIEN) ;Determine an order edit
 S PSBCHNG=0
 K PSBORDMD,PSBDDX
 I PSBREC(0)'=$$GET1^DIQ(53.79,PSBEDIEN,.09,"I") S PSBREC(0,0)=1,PSBCHNG=1
 D:PSBREC(2)'["|D"                                                ;*83
 .I $P(PSBREC(2),"|")'=$$GET1^DIQ(53.79,PSBEDIEN,.16,"I") S PSBREC(2,0)=1,PSBCHNG=1
 D:PSBREC(2)["|D"                                                 ;*83
 .I $P(PSBREC(2),"|")'=$$GET1^DIQ(53.79,PSBEDIEN,.18,"I") S PSBREC(2,0)=1,PSBCHNG=1
 I PSBREC(4)'=$$GET1^DIQ(53.79,PSBEDIEN,.06,"I") S PSBREC(4,0)=$$GET1^DIQ(53.79,PSBEDIEN,.06,"I"),PSBCHNG=1
 I PSBREC(5)'=$$GET1^DIQ(53.79,PSBEDIEN,.21) S PSBREC(5,0)=1,PSBCHNG=1
 I PSBREC(6)'=$$GET1^DIQ(53.79,PSBEDIEN,.22) S PSBREC(6,0)=1,PSBCHNG=1
 K PSBFIND,PSBFOUN,PSBREC2
 F PSBRECNX=8:1 Q:'$D(PSBREC(PSBRECNX))  S PSBDPTR=$P(PSBREC(PSBRECNX),U,2),PSBORDMD(PSBRECNX,PSBDPTR,0)="ADDED"
 F PSBDDX=.5,.6,.7 D:$D(^PSB(53.79,+PSBEDIEN,PSBDDX,"B"))
 .S PSBDPTR="" F  S PSBDPTR=$O(^PSB(53.79,+PSBEDIEN,PSBDDX,"B",PSBDPTR)) Q:+PSBDPTR'>0  D
 ..S PSBXX=0 F  S PSBXX=$O(^PSB(53.79,+PSBEDIEN,PSBDDX,"B",PSBDPTR,PSBXX)) Q:+PSBXX'>0  D  Q:'$$FINDDD^PSBML3(PSBDDX,PSBDPTR)
 ...I '$D(PSBFOUN(PSBDDX,PSBXX)) F PSBRECNX=8:1 Q:'$D(PSBREC(PSBRECNX))  D:$D(PSBORDMD(PSBRECNX))  Q:$D(PSBFOUN(PSBDDX,PSBXX))
 ....S PSBDFDA=$P(PSBREC(PSBRECNX),U) Q:$S(PSBDFDA="DD":.5,PSBDFDA="ADD":.6,PSBDFDA="SOL":.7)'=PSBDDX
 ....S PSBDATAX=PSBDFDA_"^"_$G(^PSB(53.79,+PSBEDIEN,PSBDDX,PSBXX,0))_$S(PSBDDX'=.5:"^",1:"")
 ....S:$P(PSBDATAX,U,3)?1"."1.N $P(PSBDATAX,U,3)=0_+$P(PSBDATAX,U,3)
 ....S:$P(PSBDATAX,U,4)?1"."1.N $P(PSBDATAX,U,4)=0_+$P(PSBDATAX,U,4)
 ....I $P(PSBDATAX,U,1,5)=$P(PSBREC(PSBRECNX),U,1,5) K PSBORDMD(PSBRECNX),PSBREC2(PSBRECNX) S (PSBFIND(PSBRECNX,PSBXX),PSBFOUN(PSBDDX,PSBXX))=1 Q   ;only compare 1-5 pieces for a change *83
 ....S PSBUNTOR=$P(PSBDATAX,U,3),PSBUNTGN=$P(PSBDATAX,U,4),PSBUNTAD=$P(PSBDATAX,U,5)
 ....I PSBREC(PSBRECNX)[(PSBDFDA_"^"_PSBDPTR_"^"_PSBUNTOR_"^") S PSBREC2(PSBRECNX)=PSBREC(PSBRECNX)
 D:$D(PSBREC2)
 .F PSBDDX=.5,.6,.7 D:$D(^PSB(53.79,+PSBEDIEN,PSBDDX,"B"))
 ..S PSBDPTR="" F  S PSBDPTR=$O(^PSB(53.79,+PSBEDIEN,PSBDDX,"B",PSBDPTR)) Q:+PSBDPTR'>0  D
 ...S PSBXX=0 F  S PSBXX=$O(^PSB(53.79,+PSBEDIEN,PSBDDX,"B",PSBDPTR,PSBXX)) Q:+PSBXX'>0  D
 ....S PSBREC2X=0 F  S PSBREC2X=$O(PSBREC2(PSBREC2X)) Q:PSBREC2X=""  D  Q:$G(PSBFOUN(PSBDDX,PSBXX))
 .....S PSBDFDA=$P(PSBREC(PSBREC2X),U) Q:$S(PSBDFDA="DD":.5,PSBDFDA="ADD":.6,PSBDFDA="SOL":.7)'=PSBDDX
 .....S PSBDATAX=PSBDFDA_"^"_$G(^PSB(53.79,+PSBEDIEN,PSBDDX,PSBXX,0))
 .....S:$P(PSBDATAX,U,3)?1"."1.N $P(PSBDATAX,U,3)=0_+$P(PSBDATAX,U,3)
 .....S:$P(PSBDATAX,U,4)?1"."1.N $P(PSBDATAX,U,4)=0_+$P(PSBDATAX,U,4)
 .....; *70 compare only first 5 pieces ignoring the new HR piece
 .....I $P(PSBDATAX,U,1,5)=$P(PSBREC(PSBREC2X),U,1,5) K PSBREC2(PSBREC2X),PSBORDMD(PSBREC2X) S (PSBFIND(PSBREC2X,PSBXX),PSBFOUN(PSBDDX,PSBXX))=1 Q
 .....S PSBUNTOR=$P(PSBDATAX,U,3),PSBUNTGN=$P(PSBDATAX,U,4),PSBUNTAD=$P(PSBDATAX,U,5)
 .....I PSBREC2(PSBREC2X)[(PSBDFDA_"^"_PSBDPTR_"^"_PSBUNTOR_"^") I '$D(PSBFOUN(PSBDDX,PSBXX)) S (PSBCHNG,PSBFIND(PSBREC2X,PSBXX),PSBFOUN(PSBDDX,PSBXX))=1 D  Q
 ......N PSBY,Y F Y=4,5 S PSBY=$P(PSBREC2(PSBREC2X),U,Y) S:PSBY'=$S(Y=4:PSBUNTGN,Y=5:PSBUNTAD) PSBORDMD(PSBREC2X,PSBDPTR,0)=""
 ; Modify FDA per Deleted DDs
 ;
 F PSBX=.5,.6,.7 S PSBXX="" F  Q:'$D(PSBORDMD(PSBX))  S PSBXX=$O(PSBORDMD(PSBX,PSBXX)) Q:$G(PSBXX)=""  D:PSBORDMD(PSBX,PSBXX,0)["DELETE"
 .S PSBDDX=$S(PSBX=.5:53.795,PSBX=.6:53.796,1:53.797)
 .S PSBIENX="^PSB(53.79,"_($G(PSBEDIEN))_($G(PSBX))_",""B"","_PSBXX_")"
 .S PSBIENX=$Q(@PSBIENX),PSBIENX=$QS(PSBIENX,6)_","_(+PSBEDIEN)
 .D:'$D(PSBFOUN(PSBDDX,+PSBIENX)) VAL^PSBML(PSBDDX,PSBIENX,.01,""),VAL^PSBML(PSBDDX,PSBIENX,.02,""),VAL^PSBML(PSBDDX,PSBIENX,.03,""),VAL^PSBML(PSBDDX,PSBIENX,.04,"")
 ;
 S:$D(PSBORDMD) PSBCHNG=1 K PSBREC2
 Q PSBCHNG
 ;
NGRESET(PSBREC,PSBREIEN) ;
 ;
 ; Acknowledged "UNDO" - reinstate previous status and state...
 ;
 I (PSBREC(0)="N")&($$GET1^DIQ(53.79,PSBREIEN,.09,"I")="N") D  I '$D(PSBQUITX)  S PSBREINT=$$GET1^DIQ(53.79,PSBREIEN,.05,"I")
 .S PSBRESET="NOT GIVEN",PSBX="B" K PSBQUITX,PSBREXDT,PSBREINT F  S PSBX=$O(^PSB(53.79,+PSBREIEN,.9,PSBX),-1) Q:PSBX'>0  D  Q:($G(PSBQUITX))!(PSBX'>0)
 ..I (^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["ACTION STATUS Set to") Q
 ..I $P(^PSB(53.79,+PSBREIEN,.9,PSBX,0),U,4)=PSBRESET D  Q:$G(PSBQUITX)  Q:PSBX'>0
 ...S PSBREXDT=$P(^PSB(53.79,+PSBREIEN,.9,PSBX,0),U)
 ...F  S PSBX=$O(^PSB(53.79,+PSBREIEN,.9,PSBX),-1) Q:PSBX'>0  D  Q:$G(PSBQUITX)
 ....I (^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["ACTION STATUS")!(^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["deleted") Q
 ....I $P(^PSB(53.79,+PSBREIEN,.9,PSBX,0),"'",2)'="GIVEN" Q 
 ....F  S PSBX=$O(^PSB(53.79,+PSBREIEN,.9,PSBX),-1) Q:(PSBX'>0)!($G(PSBQUITX))  D  Q:$G(PSBQUIT)
 .....I (^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["ACTION STATUS ")!(^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["deleted") Q
 .....S PSBRESET=$P(^PSB(53.79,+PSBREIEN,.9,PSBX,0),"'",2) I (PSBRESET="GIVEN")!(PSBRESET="REMOVED") Q
 .....S PSBREXDT=$$GET1^DIQ(53.79,PSBREIEN,.04,"I"),PSBX=PSBX-2 I '$D(^PSB(53.79,+PSBREIEN,.9,PSBX,0)) S PSBQUIT=1 Q
 .....I (^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["ACTION DATE/TIME")!(^PSB(53.79,+PSBREIEN,.9,PSBX,0)'["deleted") S PSBQUIT=1 Q
 .....S PSBREXDT=$P(^PSB(53.79,+PSBREIEN,.9,PSBX,0),"'",2),X=$P(PSBREXDT,"@"),%DT="" D ^%DT S PSBREXDT=Y_"."_$TR($P(PSBREXDT,"@",2),":"),PSBQUIT=1
 I $D(PSBREINT),$D(PSBREXDT),($D(PSBRESET)&($G(PSBRESET)'="GIVEN")) D
 .D VAL^PSBML(53.79,PSBREIEN,.06,PSBREXDT)
 .D VAL^PSBML(53.79,PSBREIEN,.09,PSBRESET)
 .D:$D(PSBREINT) VAL^PSBML(53.79,PSBREIEN,.07,"`"_PSBREINT)
 .D:'$G(PSBERR) FILEIT^PSBML
 K PSBXXX,PSBRESET,PSBREXDT,PSBREINT,PSBQUITX
 Q
 ;
FINDDD(PSBDDXX,PSBDDPTR) ;
 ;
 ;  Determine if edit - 'change' is deleted DDrug 
 ;
 S FINDDD=0
 I $D(PSBREC(8)) D
 .F PSBINDX=8:1 Q:'$D(PSBREC(PSBINDX))  S PSBCOMPX=$G(PSBREC(PSBINDX)) D  Q:FINDDD
 ..I ($S(PSBDDXX=.5:"DD",PSBDDXX=.6:"ADD",PSBDDXX=.7:"SOL",1:"")=$P(PSBCOMPX,U)),(PSBDDPTR=$P(PSBCOMPX,U,2)) S FINDDD=1
 I 'FINDDD S PSBORDMD(PSBDDXX,PSBDDPTR,0)="DELETED"
 Q FINDDD
 ;
AMRR  ; Maintain "AMRR" index...
 I $G(PSBTRAN)["UPDATE",(+PSBX1)'=0 D
 .S PSBX3=0 F  S PSBX3=$O(^PSB(53.79,+PSBIEN,.5,PSBX3)) Q:+PSBX3=0  I $P(^PSB(53.79,+PSBIEN,.5,PSBX3,0),U,6)>0 D
 ..I PSBOLSTS="G",PSBREC(0)="N" S PSB1A="K ^PSB(53.79,""AMRR"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$P(^PSB(53.79,+PSBIEN,0),U,6)_","_+PSBIEN_")"
 ..I PSBFDA(53.79,+PSBIEN_",",.09)="G" S PSB1A="S ^PSB(53.79,""AMRR"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$G(PSBFDA(53.79,+PSBIEN_",",.06))_","_+PSBIEN_")"_"="""""
 ;
 I $G(PSBTRAN)["EDIT",(+PSBX1)'=0 D
 .S PSBX3=0 F  S PSBX3=$O(^PSB(53.79,+PSBIEN,.5,PSBX3)) Q:+PSBX3=0  I $P(^PSB(53.79,+PSBIEN,.5,PSBX3,0),U,6)>0,((PSBREC(0)="G")!(PSBREC(0)="RM")) D
 ..S PSB1A="S ^PSB(53.79,""AMRR"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$G(PSBFDA(53.79,+PSBIEN_",",.06))_","_+PSBIEN_")"_"="""""
 ..I $D(PSBREC(4,0)) S PSB2A="K ^PSB(53.79,""AMRR"","_$P(^PSB(53.79,+PSBIEN,0),U)_","_$G(PSBREC(4,0))_","_+PSBIEN_")"
 Q