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

PXRMPLAB.m

Go to the documentation of this file.
PXRMPLAB ;SLC/AGP,RFR - Reminder Order Protocol Incoming from Lab ;Jan 18, 2023@12:55
 ;;2.0;CLINICAL REMINDERS;**45,71,84**;Feb 04, 2005;Build 2
 Q
 ;
 ;SAC EXEMPTION 20030908-01 : Use proper variable scoping instead of
 ;                            namespace variable scoping
 ;
 ;Reference to ^OR(100, in ICR #3800
 ;Reference to GETRECIPS^WVRPCPT1 in ICR #6200   
 ;Reference to $$SAVESRND^WVRPCPT1 in ICR #6336   
 ;
EN(MSG) ;
 N PXRMMSG,$ETRAP,$ESTACK
 S $ETRAP="G UNEXPERR^PXRMPLAB"
 S PXRMMSG=$S($L($G(MSG)):MSG,1:"MSG") Q:'$O(@PXRMMSG@(0))
 N APPL,BEGDATE,CNTRL,DATE,ERROR,ITEMIEN,LOC,MATCH,MSH,NODE,OBR,ORDIEN,ORC,PAT,PID,PROV
 N TERMARR,PKGIFN,OBX,DATA,EXIT,PXRMPROV,MUC,ITEM,ITEMTYPE,STATUS,PXRMVASITE
 S MSH=0 F  S MSH=$O(@PXRMMSG@(MSH)) Q:MSH'>0  Q:$E(@PXRMMSG@(MSH),1,3)="MSH"
 I 'MSH D ERROR("Missing or invalid MSH segment",.ERROR) G ORX
 S APPL=$P(@PXRMMSG@(MSH),"|",3) I '$$VALIDAPL(APPL) G ORX
 S PXRMVASITE=$P(@PXRMMSG@(MSH),"|",4)
 D PID(.PXRMMSG,MSH,.PID,.PAT) I PAT'>0 D ERROR("Missing patient in HL7 message",.ERROR) G ORX
 S ORC=PID
 ;
ORC ;process the ORC segments
 S MATCH=0
 F  S ORC=$O(@PXRMMSG@(+ORC)) Q:ORC'>0  I $E(@PXRMMSG@(ORC),1,3)="ORC" D  Q
 . S ORC=ORC_U_@PXRMMSG@(ORC),CNTRL=$TR($P(ORC,"|",2),"@","P")
 . I '$L(CNTRL) D ERROR("Invalid control code in HL7 message") Q
 . I '$$VALIDCTL(APPL,CNTRL) Q
 . S ORDIEN=$P($P(ORC,"|",3),U),PKGIFN=$P($P(ORC,"|",4),U)
 . I ORDIEN,$D(^OR(100,+ORDIEN,0)),+$P(^(0),U,2)'=PAT D ERROR("Patient doesn't match between the Order and HL7 message",.ERROR) Q
 . S MATCH=1
 . S DATE=$P($G(^OR(100,+ORDIEN,0)),U,7),LOC=+$P($G(^OR(100,+ORDIEN,0)),U,10)
 . S PROV=$P($P(ORC,"|",13),U)
 I MATCH=0 G ORX
 S OBR=ORC
 ;
OBR ;process the OBR segments
 F  S OBR=$O(@PXRMMSG@(+OBR)) Q:OBR'>0  I $E(@PXRMMSG@(OBR),1,3)="OBR" D  Q
 .S BEGDATE=$P(@PXRMMSG@(OBR),"|",8)
 .I BEGDATE'="" S BEGDATE=$$HL7TFM^XLFDT(BEGDATE,"L")
 S ITEMTYPE=$$GETTYPE(APPL)
 I $G(ITEMTYPE)="" G ORX
 ;
OBX ;process the OBX segments
 S OBX=+OBR,STATUS=0
 F  S OBX=$O(@PXRMMSG@(OBX)) Q:'+OBX!($G(EXIT))  D
 .I $E(@PXRMMSG@(OBX),1,3)'="OBX" S EXIT=1,OBX=OBX-1 Q
 .S NODE=$P(@PXRMMSG@(OBX),"|",4) I NODE="" Q
 .S ITEMIEN=+$P(NODE,U,4),ITEM=$P(NODE,U,5)
 .I ITEMIEN'>0!(ITEM="") Q
 .I $$EVAL(PAT,ITEMIEN,ITEM,ITEMTYPE,$P($G(BEGDATE),"."),PROV,$G(DATE),$G(LOC),.PXRMPROV,.ERROR,.MUC,PXRMVASITE)>0 D
 ..S DATA("ID")=PAT_U_"P"
 ..S DATA("LAB")=BEGDATE_"|"_$P(@PXRMMSG@(OBX),"|",4,8)
 ..S STATUS=$$SAVESRND^WVRPCPT1(.DATA)
 ..I +STATUS=-1 D ERROR("Error saving status conflict notification data: "_$P(STATUS,U,2),.ERROR) Q
 ..I STATUS=1 D TALERT^PXRMNTFY(PAT,.PXRMPROV,1,.MUC)
 .I $D(ERROR) S EXIT=1
ORX ;
 I $D(ERROR) D SENDERR(.ERROR)
 Q
 ;
UNEXPERR ;unexpected error handler
 N ERROR
 D ERROR("An unexpected error was encountered: "_$$EC^%ZOSV,.ERROR)
 D SENDERR(.ERROR)
 D @^%ZOSF("ERRTN") ;file error
 S $ECODE=""
 Q ""
ERROR(TEXT,ERROR) ;
 N CNT,DATA,INDEX
 S CNT=$O(ERROR("?"),-1)+1
 S ERROR(CNT,0)=TEXT,CNT=CNT+1
 S ERROR(CNT,0)="",CNT=CNT+1
 S ERROR(CNT,0)="The contents of the HL7 message that triggered this error:"
 D ACOPY^PXRMUTIL($S(PXRMMSG[U:$P(PXRMMSG,",")_")",1:"MSG"),"DATA()")
 S INDEX=0 F  S INDEX=$O(DATA(INDEX)) Q:INDEX'>0  S CNT=CNT+1,ERROR(CNT,0)=DATA(INDEX)
 Q
 ;
EVAL(PAT,ITEMIEN,ITEM,ITEMTYPE,BEGDATE,PROV,DATE,LOC,PXRMPROV,ERROR,MUC,PXRMVASITE) ;evaluation of a reminder
 N DEFARR,FIEV,NAME,NODE,PXRMSDT,RESULT,RIEN,RNAME,STATUS,TNAME,TERMARR
 N CONT,PCP
 S RESULT=0
 ;check terms to see if test should trigger an evaluation
 F TNAME="VA-WH POSITIVE LAB PREGNANCY TEST","VA-WH NEGATIVE LAB PREGNANCY TEST"  D  Q:$G(CONT)
 .D TERM^PXRMLDR(TNAME,.TERMARR) I $D(TERMARR("DNE")) D ERROR("Reminder Term "_TNAME_" not found",.ERROR) G EVALX
 .I $D(TERMARR("E",ITEMTYPE,ITEMIEN)) S CONT=1
 G:'$G(CONT) EVALX
 ;set variables for reminder evaluation
 K ^TMP("PXRHM",$J)
 S PXRMSDT=$S(BEGDATE>0:BEGDATE,1:DT),NAME="VA-WH CHANGE IN PREGNANCY STATUS"
 S RIEN=$O(^PXD(811.9,"B",NAME,"")) I RIEN'>0 D ERROR("Reminder Definition "_NAME_" not found",.ERROR) G EVALX
 S NODE=$G(^PXD(811.9,RIEN,0))
 S RNAME=$S($P(NODE,U,3)'="":$P(NODE,U,3),1:$P(NODE,U))
 ;may be able to switch to call MAIN
 D DEF^PXRMLDR(RIEN,.DEFARR)
 D EVAL^PXRM(PAT,.DEFARR,1,1,.FIEV,PXRMSDT)
 S STATUS=$P($G(^TMP("PXRHM",$J,RIEN,RNAME)),U)
 K ^TMP("PXRHM",$J)
 I (STATUS="CNBD")!(STATUS="ERROR") D ERROR("Error evaluating Reminder Definition "_NAME,.ERROR) G EVALX
 S RESULT=$$STATMTCH^PXRMORCH(STATUS,"D")
 ;FIEV(4)=1 => MEDICALLY UNABLE TO CONCEIVE
 S MUC=$S($G(FIEV(4)):1,1:0)
 I RESULT=1 D
 .D GETRECIPS^WVRPCPT1(.PXRMPROV,PAT,"LAB","P",0,PXRMVASITE)
 .I +$G(PXRMPROV(0))=-1 D
 ..S RESULT=0
 ..D ERROR("Error retrieving Women's Health managers: "_$P(PXRMPROV(0),U,2),.ERROR) G EVALX
 S PXRMPROV(PROV)=""
EVALX ;
 Q RESULT
 ;
GETTYPE(APPL) ;
 I APPL="LABORATORY" Q "LAB(60,"
 Q ""
 ;
SENDERR(ERROR) ;
 K ^TMP("PXRMXMZ",$J)
 M ^TMP("PXRMXMZ",$J)=ERROR
 D SEND^PXRMMSG("PXRMXMZ","Clinical Reminder Laboratory HL7 listener.")
 K ^TMP("PXRMXMZ",$J)
 Q
 ;
VALIDCTL(APPL,CNTRL) ;
 N RESULT
 S RESULT=0
 I APPL="LABORATORY" D  Q RESULT
 .I CNTRL="CM" S RESULT=1 Q
 .I CNTRL="RE" S RESULT=1 Q
 Q RESULT
 ;
VALIDAPL(APPL) ;
 I APPL="LABORATORY" Q 1
 Q 0
 ;
PID(PXRMMSG,MSH,PID,PAT) ; -- Returns patient from PID segment in current msg
 N DFN,I,SEG S I=MSH,PID=""
 F  S I=$O(@PXRMMSG@(I)) Q:I'>0  S SEG=$E(@PXRMMSG@(I),1,3) Q:SEG="ORC"  I SEG="PID" D  Q
 . S DFN=+$P(@PXRMMSG@(I),"|",4),PID=I
 . I $D(^DPT(DFN,0)) S PAT=DFN Q
 . S:$L($P(@PXRMMSG@(I),"|",5)) PAT=+$P(@PXRMMSG@(I),"|",5) ; alt ID for Lab
 Q