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

PSJPDCL.m

Go to the documentation of this file.
PSJPDCL ;BIR/MHA - PADE HL7 ADT MESSAGE CLIENT TO VAFC ADT SERVER ;07/08/15
 ;;5.0;INPATIENT MEDICATIONS;**317,337,347,379,389**;16 DEC 97;Build 4
 ;Reference to ^SC supported by DBIA 10040
 ;Reference to ^DIC(42 supported by DBIA 10039
 ;Reference to ^ORD(101 supported by DBIA 872
 ;Reference to ^DG(405.4 supported by DBIA 1380
 ;Reference to ^GMRADPT supported by DBIA 10099
 ;Reference to ^GMRVUTL supported by DBIA 1120
 ;Reference to ^GMRAOR2 supported by DBIA 2422
 ;
 Q
 ;
EN ; Get ADT Message and send to PADE.
 Q:$O(^PS(58.7,"B",""))=""
 Q:'$G(HLEID)
 N PSJAP
 S PSJAP=0
 N I,J S I=0
 F  S I=$O(^PS(58.7,I)) Q:'I  S J=$$PDACT^PSJPDCLA(I)
 Q:'PSJAP
 I $G(HL("ETN"))="" D INIT^HLFNC2(HLEID,.HL) Q:$D(HL)=1
 N FS,ECH S FS=HL("FS"),ECH=$E(HL("ECH"),1)
 N SNM,SID,NHL S SNM="PSJ ADT-"_HL("ETN")_" SERVER"
 S SID=$O(^ORD(101,"B",SNM,0))
 Q:'SID
 D INIT^HLFNC2(SID,.NHL) Q:$D(NHL)=1
 N NFS,NECH S NFS=NHL("FS"),NECH=$E(NHL("ECH"),1)
 N NSEG,PSJQ,PSJLOC,PSJWARD,PSJRBD,SEQ,PSJX,VAIP,X,FTS
 S VAIP("D")="L" D IN5^VADPT S PSJRBD=$P(VAIP(6),"^",2),FTS=$S($P(VAIP(8),"^")]"":$P(VAIP(8),"^")_NECH_$P(VAIP(8),"^",2),1:"")
 S SEQ=0,PSJQ=0,PSJX=1 S:HL("ETN")="A11" FTS=""
 F I=1:1 X HLNEXT Q:HLQUIT'>0!('PSJX)  D
 . Q:$E(HLNODE,1,3)="MSH"
 . Q:$E(HLNODE,1,3)="OBX"
 . Q:$E(HLNODE,1,3)="ROL"
 . Q:$E(HLNODE,1)="Z"
 . S SEQ=SEQ+1
 . S NSEG(SEQ)=$$TR(HLNODE)
 . S J=0 F  S J=$O(HLNODE(J)) Q:'J  S NSEG(SEQ,J)=$$TR(HLNODE(J))
 . I $E(HLNODE,1,3)="PV1" D
 .. S PSJLOC=$P(HLNODE,FS,4)
 .. S PSJWARD=$P(PSJLOC,ECH) Q:PSJWARD=""
 .. S PSJQ=$$CHKPD(PSJWARD,PSJRBD)
 .. I 'PSJQ S PSJX=0 Q
 .. D AGY
 Q:'PSJQ
 N XX,HL,HLFS,HLECH M HL=NHL
 S HLFS=NHL("FS")
 S HLECH=NHL("ECH")
 N ZTIO,ZTRTN,ZTSAVE,ZTDESC,ZTDTH
 S ZTIO=""
 S ZTRTN="SEND^PSJPDCL"
 F XX="PSJQ(","NSEG(","HLFS","HLECH","HL(","SNM","SID","FTS" S ZTSAVE(XX)=""
 S ZTDESC="PADE HL7 ADT Message Router"
 S ZTDTH=$H
 D ^%ZTLOAD
 Q
 ;
SEND ;
 N XX,CT,PSJND,PSJVNM,PSJDNS,PSJVP,VR,HLA,CNM,PSJSND
 M HLA("HLS")=NSEG
 Q:$G(SNM)=""
 I $G(HL("ETN"))="" D INIT^HLFNC2(SNM,.HL) Q:$D(HL)=1
 S CNM="PSJ ADT-"_HL("ETN")_" CLIENT"
 S XX=0,CT=0 F  S XX=$O(PSJQ(XX)) Q:'XX  D   ;sends HL7 message for each PADE SERVER
 .S PSJND=$G(^PS(58.7,XX,0))
 .Q:PSJND=""
 .S PSJVNM=$P(PSJND,"^"),PSJDNS=$P(PSJND,"^",2),PSJVP=$P(PSJND,"^",3)
 .Q:PSJVNM=""!(PSJDNS="")!('PSJVP)
 .N HLP,PSJSND,ZZ1,ZZ2 S (HLP,ZZ1,ZZ2)=""
 .I $G(HL("ETN"))="" D INIT^HLFNC2(SNM,.HL) Q:$D(HL)=1
 .K HLA,HLL M HLA("HLS")=NSEG
 .S HLP("SUBSCRIBER")="^^^^~"_PSJDNS_":"_PSJVP_"~DNS"
 .S HLL("LINKS",1)=CNM_"^"_"PSJ PADE",ZZ1=$P(PSJQ(XX),"^",2)
 .S CT=$O(HLA("HLS",9999),-1)+1 S:CT>1 HLA("HLS",CT)="ZZZ"_HL("FS")_ZZ1_HL("FS")_HL("FS")_FTS
 .D PV19^PSJPDAPP
 .D GENERATE^HLMA(SNM,"LM",1,.PSJSND,"",.HLP)
 .S:$G(PSJSND(1)) PSJSND=PSJSND(1)
 .D LOG^PSJPADE
 Q
 ;
TR(SEG) ; Translate the VAFC message delimiters to HL7 delimiters for PADE
 N CSEG
 S CSEG=$TR(SEG,HL("FS")_HL("ECH"),NHL("FS")_NHL("ECH"))
 S CSEG=$TR(CSEG,"""","")
 Q CSEG
 ;
CHKPD(PSJWD,PSJRB) ;
 N PSJWDI S PSJWDI=$O(^DIC(42,"B",PSJWD,"")) K PSJQ
 Q:'PSJWDI 0
 N PSJDIV,PSJDIVI S PSJDIV=+$P($G(^DIC(42,PSJWDI,0)),"^",11)
 Q:'PSJDIV 0
 N PSJPD,PSJSAR,PSJX S (PSJQ,PSJPD)=0
 F  S PSJPD=$O(^PS(58.7,"AD",PSJDIV,PSJPD)) Q:'PSJPD  D
 . Q:'$D(PSJAP(PSJPD)) 
 . S PSJDIVI=$O(^PS(58.7,PSJPD,"DIV","B",PSJDIV,0))
 . Q:'PSJDIVI
 . N DN S DN=$G(^PS(58.7,PSJPD,"DIV",PSJDIVI,0))
 . S PSJACT=$P(DN,"^",2)
 . I PSJACT,PSJACT<DT Q
 . I $G(PSJPDO)=1 N I S I=0 D  Q:I 
 .. I ($P($G(^PS(58.7,PSJPD,"DIV",PSJDIVI,2)),"^"))'="Y" S I=1 Q  ;DON'T SEND ORDER MESSAGES
 .. I $G(RXO)["V",$P(DN,"^",5)'="Y" S I=1 Q  ;DON'T SEND IP IV
 .. I "UV"[$E(RXO,$L(RXO)),($P($G(^(3)),"^")="Y"),'($S(RXO["V":$$CSIV^PSJPDCLA,1:$$CSUD^PSJPDCLA)) S I=1 Q  ;CS ONLY
 . S PSJX=0
 . I $G(PSJRB)]"" D
 .. N PSJRBI S PSJRBI=$$ROOMBED(PSJRB,PSJWDI) I 'PSJRBI Q
 .. S PSJSAR=$O(^PS(58.7,PSJPD,"DIV",PSJDIVI,"BG","C",PSJRBI,0))
 .. I PSJSAR D
 ... S PSJSAR=$G(^PS(58.7,PSJPD,"DIV",PSJDIVI,"BG",PSJSAR,2))
 ... I PSJSAR S PSJSAR=$P($G(^PS(58.71,PSJSAR,0)),"^") S:PSJSAR]"" PSJQ(PSJPD)="1^"_PSJSAR,(PSJX,PSJQ)=1,PSJXCL(PSJPD)=1
 . Q:PSJX 
 . S PSJSAR=$O(^PS(58.7,PSJPD,"DIV",PSJDIVI,"WD","B",PSJWDI,0))
 . I PSJSAR D
 .. S PSJSAR=$P($G(^PS(58.7,PSJPD,"DIV",PSJDIVI,"WD",PSJSAR,0)),"^",2)
 .. S:PSJSAR PSJSAR=$P($G(^PS(58.71,PSJSAR,0)),"^")
 .. S PSJQ(PSJPD)=1_$S(PSJSAR]"":"^"_PSJSAR,1:""),(PSJX,PSJQ)=1,PSJXCL(PSJPD)=1
 . Q:PSJX
 . I $O(^PS(57.5,"AB",PSJWDI,0)) D
 .. S PSJSAR=$O(^PS(57.5,"AB",PSJWDI,0)) Q:'PSJSAR
 .. S PSJSAR=$O(^PS(58.7,PSJPD,"DIV",PSJDIVI,"WG","B",PSJSAR,0))
 .. I PSJSAR S PSJSAR=$P($G(^PS(58.7,PSJPD,"DIV",PSJDIVI,"WG",PSJSAR,0)),"^",2) D
 ... S:PSJSAR PSJSAR=$P($G(^PS(58.71,PSJSAR,0)),"^")
 ... S PSJQ(PSJPD)="1"_$S(PSJSAR]"":"^"_PSJSAR,1:""),(PSJQ,PSJX)=1,PSJXCL(PSJPD)=1
 . K:'PSJX PSJAP(PSJPD)
 Q PSJQ
 ;
REACT ;
 N REAC S REAC="",IDX=0
 F  S IDX=$O(ADTL("S",IDX)) Q:IDX=""  D
 . I IDX>1 S REAC=REAC_NECH_$G(ADTL("S",IDX))
 . E  S REAC=$G(ADTL("S",IDX))
 S:REAC]"" $P(SEG,NFS,6)=REAC
 Q
 ;
AGY ;
 N SEG,GMRA,GMRAL
 S GMRA="0^0^111" D ^GMRADPT
 I GMRAL="" G OBX
 ;No known
 I GMRAL=0 D
 .S $P(SEG,NFS,1)="AL1"
 .S $P(SEG,NFS,2)=1
 .S $P(SEG,NFS,3)="OA"
 .S $P(SEG,NFS,4)="0;GMRD(120.82,"_NECH_"NO KNOWN ALLERGIES"
 .S $P(SEG,NFS,6)=""
 .S $P(SEG,NFS,7)=$$FMTHL7^XLFDT($$GET1^DIQ(120.86,DFN,3,"I"))
 .S SEQ=SEQ+1
 .S NSEG(SEQ)=SEG
 ;
 ;Yes, allergies
 I GMRAL=1 N KK,ACT,AEXT,ND D
 .S KK=0,ACT=0
 .F  S KK=$O(GMRAL(KK)) Q:'KK  D
 ..S ND=GMRAL(KK)
 ..S AEXT=$P(ND,U,2)
 ..S ACT=ACT+1
 ..S $P(SEG,NFS,1)="AL1"
 ..S $P(SEG,NFS,2)=ACT
 ..S $P(SEG,NFS,3)=$S($P(ND,U,3)="D":"DA",$P(ND,U,3)="F":"FA",1:"OA")
 ..S $P(SEG,NFS,4)=$P(ND,U,9)_NECH_AEXT
 ..N ADTL D EN1^GMRAOR2(KK,"ADTL") D:$O(ADTL("O",""))
 ... N IDX,SEV
 ... S IDX=$O(ADTL("O","")),SEV=$P($G(ADTL("O",IDX)),"^",2)
 ... S SEV=$S(SEV="MILD":"MI",SEV="MODERATE":"MO",SEV="SEVERE":"SV",1:"U")
 ... S $P(SEG,NFS,5)=SEV
 ..D:$O(ADTL("S","")) REACT
 ..S $P(SEG,NFS,7)=$$FMTHL7^XLFDT($$GET1^DIQ(120.8,KK,4,"I"))
 ..S SEQ=SEQ+1
 ..S NSEG(SEQ)=SEG,SEG=""
OBX ;HT,WT
 N GMRVSTR
 S GMRVSTR="HT" D EN6^GMRVUTL
 I X]"" S $P(SEG,NFS,1)="OBX",$P(SEG,NFS,2)=1,$P(SEG,NFS,3)="CE",$P(SEG,NFS,4)="1010.3"_NECH_"HEIGHT" D
 .S $P(SEG,NFS,6)=$J($P(X,U,8)*2.54,0,2),$P(SEG,NFS,7)="cm"
 .S $P(SEG,NFS,15)=$$HLDATE^HLFNC($P(X,U))
 .S SEQ=SEQ+1
 .S NSEG(SEQ)=SEG,SEG=""
 S GMRVSTR="WT" D EN6^GMRVUTL
 I X]"" S $P(SEG,NFS,1)="OBX",$P(SEG,NFS,2)=2,$P(SEG,NFS,3)="CE",$P(SEG,NFS,4)="1010.1"_NECH_"WEIGHT" D
 .S $P(SEG,NFS,6)=$J($P(X,U,8)/2.2046226,0,2),$P(SEG,NFS,7)="kg"
 .S $P(SEG,NFS,15)=$$HLDATE^HLFNC($P(X,"^"))
 .S SEQ=SEQ+1
 .S NSEG(SEQ)=SEG,SEG=""
 Q
 ;
A08 ;
 K ^TMP("A08")
 M ^TMP("A08","HLS")=^TMP("HLS",$J)
 M ^TMP("A08","HL")=HL
 Q:$O(^PS(58.7,"B",""))=""
 Q:$D(HL)=1
 Q:'$D(^TMP("HLS",$J))
 N XX,HLN,PSJND,PSJCLN,PSJCLNI,PSJDIV,PSJX S (PSJX,XX)=0
 F  S XX=$O(^TMP("HLS",$J,XX)) Q:'XX!(PSJX)  D
 . S HLN=^TMP("HLS",$J,XX)
 . I $E(HLN,1,3)="PV1" D
 .. S PSJCLN=$P(HLN,FS,4)
 .. S PSJCLNI=$O(^SC("B",PSJCLN,0))
 .. I 'PSJCLNI S PSJX=1 Q
 .. S PSJDIV=$P($G(^SC(PSJCLNI,0)),"^",15)
 .. I 'PSJDIV S PSJX=1 Q
 .. N PSJPD,PSJSAR,PSJQ S (PSJQ,PSJPD)=0
 .. F  S PSJPD=$O(^PS(58.7,"AD",PSJDIV,PSJPD)) Q:'PSJPD  D
 ... I '$D(^PS(58.7,PSJPD,0)) Q
 ... N PSJVNM,PSJDNS,PSJVP,PSJACT S PSJND=$G(^PS(58.7,PSJPD,0))
 ... S PSJVNM=$P(PSJND,"^"),PSJDNS=$P(PSJND,"^",2),PSJVP=$P(PSJND,"^",3)
 ... I PSJVNM=""!(PSJDNS="")!('PSJVP) Q
 ... S PSJACT=$P(PSJND,"^",4)
 ... I PSJACT&(PSJACT<DT) Q
 ... S PSJDIVI=$O(^PS(58.7,PSJPD,"DIV","B",PSJDIV,0))
 ... S PSJACT=$G(^PS(58.7,PSJPD,"DIV",PSJDIVI,0))
 ... S PSJACT=$P(PSJACT,"^",2)
 ... I PSJACT,PSJACT<DT Q
 ... S PSJQ=1,PSJQ(PSJPD)=1
 Q:'PSJQ 
 N SNM,SID S SNM="PSJ ADT-A08 SERVER"
 S SID=$O(^ORD(101,"B",SNM,0))
 Q:'SID
 D INIT^HLFNC2(SID,.NHL) Q:$D(NHL)=1
 N NFS,NECH S NFS=NHL("FS"),NECH=$E(NHL("ECH"),1)
 Q
 ;
ROOMBED(RMBDNAM,WARDIEN) ; Return the Room-Bed IEN - 379
 N ROOMBED,RMBD
 S (RMBD,ROOMBED)=0
 F  S RMBD=$O(^DG(405.4,"B",RMBDNAM,RMBD)) Q:'RMBD  D  I ROOMBED Q
 . I $D(^DG(405.4,RMBD,"W","B",WARDIEN)) S ROOMBED=RMBD
 Q ROOMBED
 ;