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

PSOERUT3.m

Go to the documentation of this file.
PSOERUT3 ;ALB/MFR - eRx Listman Allergy Utilities; 06/25/2022 5:14pm
 ;;7.0;OUTPATIENT PHARMACY;**700,746**;DEC 1997;Build 106
 ;
ALLERGY(MODE,NPSPC,ERXIEN,DFN) ; Sets Allergy and Adverse Reaction information
 ; Input: MODE   - Display Mode: "RS": Roll & Scroll | "LM": ListMan
 ;        NMSPC  - ListMan Temp Global Namespace (e.g., "PSOERXP1")
 ;        ERXIEN - Pointer to ERX HOLDING QUEUE file (#52.49)
 ;        DFN    - Pointer to PATIENT File(#2)
 ;
 N IEN,X,XE,XV,LDAT,GMRAL,PSONOAL,LN,TYPE,VANOASS,VANKA,VERALLST,NOVALLST,REMALLST,VERARLST,NOVARLST,EALLDATA,ALLLN
 N VALIST,ERXLIST,VA1ALL,VAALLS,ERX1ALL,ERXALLS,I,HDRLN,EALLLST,ENKA
 Q:'$D(^PS(52.49,+$G(ERXIEN),0))
 S (VERALLST,NOVALLST,VERARLST,NOVARLST,REMALLST)="",(VANOASS,VANKA)=0
 I $G(DFN) D
 . ; Allergies & Adverse Reactions
 . S GMRA="0^0^111" D ^GMRADPT
 . I GMRAL="" S VANOASS=1 Q      ; No Allergy Assessment
 . I GMRAL=0 S VANKA=1 Q         ; No Known Allergies
 . I GMRAL D                     ; Allergies Found
 . . N ALL,Z,ALLLIST,VERIF,ALORAR,AGENT,FILE
 . . S ALL=0 F  S ALL=$O(GMRAL(ALL)) Q:'ALL  D
 . . . S Z=GMRAL(ALL),ALLLIST($S($P(Z,"^",4):"V",1:"NV"),$S('$P(Z,"^",5):"AL",1:"AR"),$P(Z,"^",2))=""
 . . S (VERIF,ALORAR,AGENT)=""
 . . F  S VERIF=$O(ALLLIST(VERIF)) Q:VERIF=""  D
 . . . F  S ALORAR=$O(ALLLIST(VERIF,ALORAR)) Q:ALORAR=""  D
 . . . . F  S AGENT=$O(ALLLIST(VERIF,ALORAR,AGENT)) Q:AGENT=""  D
 . . . . . I VERIF="V",ALORAR="AL" S VERALLST=VERALLST_","_AGENT
 . . . . . I VERIF="NV",ALORAR="AL" S NOVALLST=NOVALLST_","_AGENT
 . . . . . I VERIF="V",ALORAR="AR" S VERARLST=VERARLST_","_AGENT
 . . . . . I VERIF="NV",ALORAR="AR" S NOVARLST=NOVARLST_","_AGENT
 . . . . . S VALIST($$UP^XLFSTR(AGENT))=""
 . ; Remote Allergies
 . I $T(HAVEHDR^ORRDI1)'="" D
 . . I '$$HAVEHDR^ORRDI1 Q
 . . I $D(^XTMP("ORRDI","OUTAGE INFO","DOWN")) Q
 . . I $T(GET^ORRDI1)]"" D GET^ORRDI1(DFN,"ART") D
 . . . I $P($G(^XTMP("ORRDI","ART",DFN,0)),"^",3)=0 Q
 . . . S ALL=0 F  S ALL=$O(^XTMP("ORRDI","ART",DFN,ALL)) Q:'ALL  D
 . . . . S Z=$G(^XTMP("ORRDI","ART",DFN,ALL,"GMRALLERGY",0))
 . . . . S AGENT=$P(Z,"^",2) Q:AGENT=""
 . . . . S FILE=$P($P(Z,"^",3),"99VA",2)
 . . . . I FILE'=50.6,FILE'=120.82,FILE'=50.605,FILE'=50.416 Q
 . . . . S REMALLST=REMALLST_","_AGENT
 . . . . S VALIST($$UP^XLFSTR(AGENT))=""
 ;
 ;Removing the last comma
 S VERALLST=$$SORT^PSOERUT(VERALLST)
 S NOVALLST=$$SORT^PSOERUT(NOVALLST)
 S VERARLST=$$SORT^PSOERUT(VERARLST)
 S NOVARLST=$$SORT^PSOERUT(NOVARLST)
 S REMALLST=$$SORT^PSOERUT(REMALLST)
 ;
 ;eRx Allergies
 S ENKA=$$GET1^DIQ(52.49,ERXIEN,302,"I")
 ; Retrieving the list of eRx Patient Allergies (Sorted Alphabetically)
 D ALRGDATA^PSOERXU9(.EALLDATA,ERXIEN,1)
 S EALLLST=",",SEQ=0 F  S SEQ=$O(EALLDATA(SEQ)) Q:'SEQ  D
 . I $P(EALLDATA(SEQ),"^",7)="" Q
 . S EALLLST=EALLLST_$E($P(EALLDATA(SEQ),"^",7),1,38)_","
 . S ERXLIST($P(EALLDATA(SEQ),"^",7))=""
 S $E(EALLLST)=""
 ;
 K ERXLINES,VALINES
 I ENKA="Y" D
 . S ERXLINES(1,0)="NO KNOWN ALLERGIES"
 I EALLLST'="" D
 . S X=$$C2S^PSOERUT(EALLLST) K ^UTILITY($J,"W") S DIWL=1,DIWR=39,DIWF="|" D ^DIWP
 . F I=1:1 Q:'$D(^UTILITY($J,"W",1,I))  S ERXLINES(I,0)=$$S2C^PSOERUT(^UTILITY($J,"W",1,I,0))
 I ENKA'="Y",EALLLST="" D
 . S ERXLINES(1,0)="NO ALLERGY INFORMATION RECEIVED"
 ;
 ; - VistA Allergies
 I $G(DFN) D
 . S LN=0 K HDRLN
 . I VANOASS S LN=LN+1,VALINES(1,0)=" NO ALLERGY ASSESSMENT"
 . I VANKA S LN=LN+1,VALINES(1,0)=" NO KNOWN ALLERGIES"
 . I VERALLST'="" D
 . . K ^UTILITY($J,"W")
 . . S LN=LN+1,VALINES(LN,0)=" Verified:",HDRLN(LN)=1
 . . S X=$$C2S^PSOERUT(VERALLST) K ^UTILITY($J,"W") S DIWL=1,DIWR=38,DIWF="|" D ^DIWP
 . . F I=1:1 Q:'$D(^UTILITY($J,"W",1,I))  S LN=LN+1,VALINES(LN,0)="  "_$$S2C^PSOERUT(^UTILITY($J,"W",1,I,0))
 . I NOVALLST'="" D
 . . K ^UTILITY($J,"W")
 . . S LN=LN+1,VALINES(LN,0)=" Non-Verified:",HDRLN(LN)=1
 . . S X=$$C2S^PSOERUT(NOVALLST) K ^UTILITY($J,"W") S DIWL=1,DIWR=38,DIWF="|" D ^DIWP
 . . F I=1:1 Q:'$D(^UTILITY($J,"W",1,I))  S LN=LN+1,VALINES(LN,0)="  "_$$S2C^PSOERUT(^UTILITY($J,"W",1,I,0))
 . I REMALLST'="" D
 . . K ^UTILITY($J,"W")
 . . S LN=LN+1,VALINES(LN,0)="Remote Allergies:",HDRLN(LN)=0
 . . S X=$$C2S^PSOERUT(REMALLST) K ^UTILITY($J,"W") S DIWL=1,DIWR=38,DIWF="|" D ^DIWP
 . . F I=1:1 Q:'$D(^UTILITY($J,"W",1,I))  S LN=LN+1,VALINES(LN,0)="  "_$$S2C^PSOERUT(^UTILITY($J,"W",1,I,0))
 . I (VERARLST'="")!(NOVARLST'="") D
 . . S LN=LN+1,VALINES(LN,0)="Adverse Reactions:",HDRLN(LN)=0
 . . I VERARLST'="" D
 . . . S LN=LN+1,VALINES(LN,0)=" Verified:",HDRLN(LN)=1
 . . . S X=$$C2S^PSOERUT(VERARLST) K ^UTILITY($J,"W") S DIWL=1,DIWR=38,DIWF="|" D ^DIWP
 . . . F I=1:1 Q:'$D(^UTILITY($J,"W",1,I))  S LN=LN+1,VALINES(LN,0)="  "_$$S2C^PSOERUT(^UTILITY($J,"W",1,I,0))
 . . I NOVARLST'="" D
 . . . S LN=LN+1,VALINES(LN,0)=" Non-Verified:",HDRLN(LN)=1
 . . . S X=$$C2S^PSOERUT(NOVARLST) K ^UTILITY($J,"W") S DIWL=1,DIWR=38,DIWF="|" D ^DIWP
 . . . F I=1:1 Q:'$D(^UTILITY($J,"W",1,I))  S LN=LN+1,VALINES(LN,0)="  "_$$S2C^PSOERUT(^UTILITY($J,"W",1,I,0))
 ;
 ; - Setting eRx Allergies & Local VistA Allergies (Sets reverse video for non-matching
 ;   Allergies between eRx and VistA)
 S XE="Allergy:",XV="|Allergy:"
 D ADDLINE^PSOERUT0(MODE,NMSPC,XE,XV)
 F ALLLN=1:1 Q:('$D(ERXLINES(ALLLN))&'$D(VALINES(ALLLN)))  D
 . S ERXALLS=$G(ERXLINES(ALLLN,0)),VAALLS=$G(VALINES(ALLLN,0))
 . I $D(VALIST)!$D(ERXLIST) D
 . . F I=1:1:$L(ERXALLS,",") D
 . . . S ERX1ALL=$P(ERXALLS,",",I)
 . . . I ERX1ALL'="",'$D(VALIST(ERX1ALL)) D
 . . . . S REVLN(LINE,$F(ERXALLS,ERX1ALL)-$L(ERX1ALL)+1)=$L(ERX1ALL)
 . . . E  S HIGHLN(LINE,$F(ERXALLS,ERX1ALL)-$L(ERX1ALL)+1)=$L(ERX1ALL)
 . . I '$D(HDRLN(ALLLN)) D
 . . . F I=1:1:$L(VAALLS,",") D
 . . . . S VA1ALL=$P(VAALLS,",",I) S:$E(VA1ALL,1,2)="  " $E(VA1ALL,1,2)=""
 . . . . I VA1ALL'="",'$D(ERXLIST(VA1ALL)) D
 . . . . . S REVLN(LINE,40+$F(VAALLS,VA1ALL)-$L(VA1ALL))=$L(VA1ALL)
 . . . . E  S HIGHLN(LINE,40+$F(VAALLS,VA1ALL)-$L(VA1ALL))=$L(VA1ALL)
 . . E  S:$G(HDRLN(ALLLN)) UNDERLN(LINE,42)=$L(VAALLS)-1
 . E  D
 . . I '$G(DFN)!(ENKA="Y"&VANKA) D
 . . . S HIGHLN(LINE,2)=$L(ERXALLS),HIGHLN(LINE,42)=$L(VAALLS)
 . . E  S REVLN(LINE,2)=$L(ERXALLS) S REVLN(LINE,42)=$L(VAALLS)
 . S XE=" "_$G(ERXLINES(ALLLN,0))
 . S XV="|"_$G(VALINES(ALLLN,0))
 . D ADDLINE^PSOERUT0(MODE,NMSPC,XE,XV)
 D BLANKLN^PSOERUT0(MODE),VIDEO^PSOERUT0()
 Q
 ;
ADDALLS ; Add Alergies to the Screen (Reverses or Highlights Video for each Allergy)
 N ALLLN
 F ALLLN=1:1 Q:('$D(ERXLINES(ALLLN))&'$D(VALINES(ALLLN)))  D
 . S ERXALLS=$G(ERXLINES(ALLLN,0)),VAALLS=$E($G(VALINES(ALLLN,0)),2,99)
 . I $D(VALIST)!$D(ERXLIST) D
 . . F I=1:1:$L(ERXALLS,",") D
 . . . S ERX1ALL=$P(ERXALLS,",",I)
 . . . I ERX1ALL'="",'$D(VALIST(ERX1ALL)) D
 . . . . S REVLN(LINE,$F(ERXALLS,ERX1ALL)-$L(ERX1ALL)+1)=$L(ERX1ALL)
 . . . E  S HIGHLN(LINE,$F(ERXALLS,ERX1ALL)-$L(ERX1ALL)+1)=$L(ERX1ALL)
 . . I VAALLS'["erified:" D
 . . . F I=1:1:$L(VAALLS,",") D
 . . . . S VA1ALL=$P(VAALLS,",",I)
 . . . . I VA1ALL'="",'$D(ERXLIST(VA1ALL)) D
 . . . . . S REVLN(LINE,$F(VAALLS,VA1ALL)+42-$L(VA1ALL))=$L(VA1ALL)
 . . . . E  S HIGHLN(LINE,$F(VAALLS,VA1ALL)+42-$L(VA1ALL))=$L(VA1ALL)
 . E  D
 . . I '$G(DFN)!(ENKA="Y"&VANKA) D
 . . . S HIGHLN(LINE,2)=$L(ERXALLS),HIGHLN(LINE,42)=$L(VAALLS)+1
 . . E  S REVLN(LINE,2)=$L(ERXALLS) S REVLN(LINE,42)=$L(VAALLS)+1
 . S XE=" "_$G(ERXLINES(ALLLN,0))
 . S XV="| "_$G(VALINES(ALLLN,0))
 . D ADDLINE^PSOERUT0(MODE,NMSPC,XE,XV)
 Q
 ;
SETDIAGS(MODE,NPSPC,ERXIEN) ; Sets Diagnosis information
 ; Input: MODE   - Display Mode: "RS": Roll & Scroll | "LM": ListMan
 ;        NMSPC  - ListMan Temp Global Namespace (e.g., "PSOERXP1")
 ;        ERXIEN - Pointer to ERX HOLDING QUEUE file (#52.49)
 N DIAGS,DIAG,DIAGZ,XE
 D GETDIAGS(ERXIEN,.DIAGS)
 S DIAG=0 F  S DIAG=$O(DIAGS(DIAG)) Q:'DIAG  D
 . S DIAGZ=DIAGS(DIAG)
 . S XE=$S($P(DIAGZ,"^")="P":"Primary",1:"Secondary")_" Dx:" D ADDLINE^PSOERUT0(MODE,NMSPC,XE,"|")
 . S XE=$P(DIAGZ,"^",2)_" "_$P(DIAGZ,"^",3)
 . F  Q:$E(XE,1,38)=""  D
 . . S HIGUNDLN(LINE,2)=$L($E(XE,1,38))
 . . D ADDLINE^PSOERUT0(MODE,NMSPC," "_$E(XE,1,38),"|")
 . . S XE=$E(XE,39,9999)
 . S XE=$P(DIAGZ,"^",4)
 . F  Q:$E(XE,1,38)=""  D
 . . D ADDLINE^PSOERUT0(MODE,NMSPC," "_$$COMPARE^PSOERUT0(MODE,$E(XE,1,38),$E(XE,1,38),2),"|")
 . . S XE=$E(XE,39,9999)
 I $O(DIAGS(0)) D BLANKLN^PSOERUT0(MODE)
 Q
 ;
GETDIAGS(ERXIEN,ICDARR) ; Returns the diagnosis codes for the eRx order
 ; Input: (r) ERXIEN - Pointer to the ERX HOLDING QUEUE file (52.49)
 ;Output:     ICDARR array - P1: "P"rimary or "S"econdary diagnosis | P2: Diagnosis qualifier" "Diagnosis code
 ;                           P3: ICD Description | P4: Primary or Secondary Diagnosis description
 ;
 N MIEN,COUNT,DIAGIEN,DIENS,DIAGDAT,PDIAGQ,PDIAGV,PDESC,DRES,DRESL,DRESDAT
 N SDIAGQ,SDIAGV,SDESC,SDRES,SDRESL,SDRESDAT
 S (MIEN,COUNT)=0 F  S MIEN=$O(^PS(52.49,ERXIEN,311,MIEN)) Q:'MIEN  D
 . S DIAGIEN=0 F  S DIAGIEN=$O(^PS(52.49,ERXIEN,311,MIEN,3,DIAGIEN)) Q:'DIAGIEN  D
 . . S DIENS=DIAGIEN_","_MIEN_","_ERXIEN_"," N DIAGDAT
 . . D GETS^DIQ(52.493113,DIENS,"**","IE","DIAGDAT")
 . . S PDIAGQ=$G(DIAGDAT(52.493113,DIENS,1.2,"E"))
 . . S PDIAGV=$G(DIAGDAT(52.493113,DIENS,1.1,"E"))
 . . S PDESC=$G(DIAGDAT(52.493113,DIENS,2,"E"))
 . . I PDIAGQ["ICD" D
 . . . D ICDDESC^ICDXCODE(PDIAGQ,PDIAGV,,.DRES)
 . . . I '$O(DRES(0)) D  Q
 . . . . S COUNT=COUNT+1,ICDARR(COUNT)="P^"_PDIAGQ_" "_PDIAGV_"^^"_PDESC
 . . . S DRESL=0 F  S DRESL=$O(DRES(DRESL)) Q:'DRESL  D
 . . . . S DRESDAT=$G(DRES(DRESL)) Q:DRESDAT=""
 . . . . S COUNT=COUNT+1,ICDARR(COUNT)="P^"_PDIAGQ_" "_PDIAGV_"^"_$$UP^XLFSTR(DRESDAT)_"^"_PDESC
 . . S SDIAGQ=$G(DIAGDAT(52.493113,DIENS,3.2,"E"))
 . . S SDIAGV=$G(DIAGDAT(52.493113,DIENS,3.1,"E"))
 . . S SDESC=$G(DIAGDAT(52.493113,DIENS,4,"E"))
 . . I SDIAGQ["ICD" D
 . . . D ICDDESC^ICDXCODE(SDIAGQ,SDIAGV,,.SDRES)
 . . . I '$O(SDRES(0)) D  Q
 . . . . S COUNT=COUNT+1,ICDARR(COUNT)="S^"_SDIAGQ_" "_SDIAGV_"^^"_SDESC
 . . . S SDRESL=0 F  S SDRESL=$O(SDRES(SDRESL)) Q:'SDRESL  D
 . . . . S SDRESDAT=$G(SDRES(SDRESL)) Q:SDRESDAT=""
 . . . . S COUNT=COUNT+1
 . . . . S ICDARR(COUNT)="S^"_SDIAGQ_" "_SDIAGV_"^"_$$UP^XLFSTR(SDRESDAT)_"^"_SDESC
 Q
  ;
SUGSIG(RXIEN,ERXIEN) ; Returns the Suggested SIG retrieved from the VA Rx
 ; Input:ERXIEN - Pointer to ERX HOLDING QUEUE file (#52.49)
 ;       RXIEN  - Prescription IEN - Pointer to PRESCRIPTION file (#52)
 ;Output:SUGSIG - Suggested SIG
 ;
 K SUGSIG,VADOSE,SIG,I,VAPATIEN,PSODRUG,VAPATINS
 I '$D(^PSRX(+$G(RXIEN),0))!'$D(^PS(52.49,+$G(ERXIEN),0)) Q ""
 S PSODRUG("IEN")=+$$GET1^DIQ(52,RXIEN,6,"I"),PSODRUG("OI")=+$$GET1^DIQ(50,PSODRUG("IEN"),2.1,"I")
 S SUGSIG=""
 D VARXDOSE^PSOERUT4(RXIEN,.VADOSE)
 K SIG D EN^PSOFSIG(.VADOSE)
 F I=1:1 Q:'$D(SIG(I))  S SUGSIG=SUGSIG_SIG(I)
 ; - Appending Patient Instrutions
 S VADRGIEN=+$$GET1^DIQ(52,RXIEN,6,"I")
 S VAOIIEN=+$$GET1^DIQ(50,VADRGIEN,2.1,"I")
 S VAPATIEN=+$$GET1^DIQ(52.49,ERXIEN,.05,"I")
 S VAPATINS=$$VAPATINS(VAOIIEN,VAPATIEN)
 I VAPATINS'="" S SUGSIG=SUGSIG_" "_VAPATINS
 Q SUGSIG
 ;
VAPATINS(OI,DFN) ; Returns the Pharmacy Orderable Patient Instructions, if any
 ; Input: OI  - Pointer to the PHARMACY ORDERABLE ITEM file (#50.7)
 ;     (o)DFN - Pointer to the PATIEN file (#2)
 ;Output: VAPTINS - Expanded (if needed) OI Patient Instructions
 ;
 N VAPATINS,FLD,X,PSODIR,INS1
 S FLD=7
 I $G(DFN),$$GET1^DIQ(55,DFN,106,"I") S FLD=7.1
 S VAPATINS=$$GET1^DIQ(50.7,+$G(OI),FLD)
 ;
 I $G(VAPATINS)'="" D
 . S (X,PSODIR("INS"))=VAPATINS D SIG^PSOHELP S $E(INS1)="",VAPATINS=INS1
 Q VAPATINS