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

SDHL7BLD.m

Go to the documentation of this file.
SDHL7BLD ;SLC/AGP - RTC Order HL7 sender;11:53 AM  19 Jun 2017
 ;;5.3;Scheduling;**671**;Aug 13, 1993;Build 25
 ;
 ;INPUTS("REQ FILE IEN")=89 <=
 ;INPUTS("APPT TYPE")="followup"
 ;INPUTS("CLINIC")="240^20 MINUTE" <=
 ;INPUTS("COMMENT")="This is the new comment field"
 ;INPUTS("DISPOSITION BY")="10000000195^PULEO,ANTHONY" <= this is set if the order is disposition or discontinue
 ;INPUTS("INTERVAL")="Q7D"
 ;INPUTS("DISCONTINUE")=1 <= this is set if the order is discontinue
 ;INPUTS("NLT")=1
 ;INPUTS("NUMBER APPT")=4 <=
 ;INPUTS("ORDER IEN")=14524362 <=
 ;INPUTS("PATIENT")="346^RECORD, THREE" <=
 ;INPUTS("PREREQ",2)="XRAY"
 ;INPUTS("PREREQ",3)="VITALS"
 ;INPUTS("RTC DATE")=20170524 <=
 ;INPUTS("PARTIAL")=1
 ;
 Q
 ;
EN(INPUTS) ; -- main entry point for sending a
 N INC,MSG,LS
 I $G(INPUTS("ORDER IEN")) S LS=$$LOCK1^ORX2($G(INPUTS("ORDER IEN"))) Q:'LS
 S INC=0
 S INC=INC+1,MSG(INC)=$$MSH(.INPUTS)
 S INC=INC+1,MSG(INC)=$$PID(.INPUTS)
 S INC=INC+1,MSG(INC)=$$PV1(.INPUTS)
 S INC=INC+1,MSG(INC)=$$SCH(.INPUTS)
 S INC=INC+1,MSG(INC)=$$AIL(.INPUTS)
 I $D(INPUTS("PREREQ")) S INC=INC+1 D AIG(.INPUTS,.MSG,INC)
 I $G(INPUTS("COMMENT"))'="" S INC=INC+1,MSG(INC)=$$NTE(.INPUTS)
ENX ;
 I $G(SDZTEST) M SDZTEST=MSG Q  ;testing only
 D MSG^XQOR("SD EVSEND OR",.MSG)
 D UNLK1^ORX2($G(INPUTS("ORDER IEN")))
 Q
 ;
MSH(INPUTS) ;
 N TYPE
 S TYPE=$S($G(INPUTS("DISCONTINUE"))=1:"S15",1:"S12")
 Q "MSH|^~\&|SCHEDULING|"_$G(DUZ(2))_"|ORDER ENTRY|"_DUZ(2)_"|"_$$FMTHL7^XLFDT($$NOW^XLFDT)_"||SRM|"_INPUTS("ORDER IEN")_"^"_TYPE
 ;
PID(INPUTS) ;
 Q "PID|||"_$P(INPUTS("PATIENT"),U)_"||"_$P(INPUTS("PATIENT"),U,2)
 ;
SCH(INPUTS) ;
 N STR,TYPE
 S TYPE=$S($G(INPUTS("DISCONTINUE"))=1:"S15",1:"S12")_U_$S($D(INPUTS("PARTIAL")):"PARTIAL",1:"")
 S STR="SCH|"_INPUTS("REQ FILE IEN")_"|"_INPUTS("ORDER IEN")_"||||"_TYPE_"||"_$$FMTHL7^XLFDT(INPUTS("RTC DATE"))_"|"_$S($G(INPUTS("NLT"))=1:"T",1:"")_"|"
 S STR=STR_$G(INPUTS("INTERVAL"))_"|"_INPUTS("NUMBER APPT")_"^|||||"_INPUTS("DISPOSITION BY")_"|"
 S STR=STR_"|||||"_INPUTS("REQ FILE IEN")_"|"_INPUTS("ORDER IEN")
 Q STR
 ;
AIL(INPUTS,X,SEG,ERRARR) ;
 Q "AIL|||"_INPUTS("CLINIC")
 ;
AIG(INPUTS,MSG,X) ;
 N CNT,INC,FIRST,NUM
 S CNT=0,INC=0,FIRST=1,NUM=0
 F  S INC=$O(INPUTS("PREREQ",INC)) Q:INC'>0  D
 .S CNT=CNT+1
 .I FIRST=1 S MSG(X)="AIG|"_CNT_"|"_U_INPUTS("PREREQ",INC)_U_U_U_U_"|||||||||||",FIRST=0 Q
 .S NUM=NUM+1,MSG(X,NUM)="AIG|"_CNT_"|"_U_INPUTS("PREREQ",INC)_U_U_U_U_"|||||||||||"
 Q
 ;
NTE(INPUTS) ;
 Q "NTE|6|P|"_$$ESC(INPUTS("COMMENT"))
 ;
PV1(INPUTS) ; -- Gets Patient location info.
 ;
 N PATRB,PATTYPE,STR,WARD
 S WARD=+$G(^DPT(+INPUTS("PATIENT"),.1))
 S PATTYPE=$S(WARD>0:"I",1:"O")
 S PATRB=$S(PATTYPE="I":$P($G(^DPT(+INPUTS("PATIENT"),.101)),U),1:"")
 S STR="PV1||"_PATTYPE_"|"_$S(WARD>0:WARD,1:+$G(INPUTS("CLINIC")))_$S($L(PATRB):U_PATRB,1:"")_"||||||||||||||||"
 Q STR
 ;
ERROR ; -- Sends a DE reply to current msg
 ; Uses ORVP, ORNMSP, ORDUZ, ORIFN, ORERR, and PKGIFN
 N ORV S ORV("XQY0")="" D ERROR(ORERR,.SDMSG,.ORV)
 Q:ORTYPE="ORR"  Q:'$L($G(ORNMSP))
 N OREMSG,ORVP,ORTS S:'$G(ORDUZ) ORDUZ=DUZ D:'$G(ORVP) PID
 S OREMSG(1)=$$MSH^ORMBLD("ORR",ORNMSP),OREMSG(2)=$$PID^ORMBLD($G(ORVP))
 S OREMSG(3)="ORC|DE|"_$S($G(ORIFN):ORIFN_"^OR",1:"")_"|"_$S($L($G(PKGIFN)):PKGIFN_U_ORNMSP,1:"")_"|||||||"_ORDUZ_"||||||"_ORERR
 D MSG^XQOR("OR EVSEND "_ORNMSP,.OREMSG)
 Q
 ;
TEST(INPUTS) ; -- Build/display HL7 msgs w/o sending
 K SDZTEST S SDZTEST=1 D EN(.INPUTS) ; leaves msg in SDZTEST() on exit
 Q
 ;
ESC(STR) ;
 ;ICR 4922
 Q $$ESC^ORHLESC(STR)