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

BQICAHLO.m

Go to the documentation of this file.
BQICAHLO ;VNGT/HS/ALA-HL7 for CANES Export ; 08 Nov 2010  2:09 PM
 ;;2.5;ICARE MANAGEMENT SYSTEM;**1**;May 24, 2016;Build 17
 ;
EN ;EP
 NEW APPARMS,PARMS,IN,RECORD,ERR,ERROR,WHO,HLMSTATE,MSIEN,BDIEN,CNT,HIN,HLFS,HLECH
 NEW MSH,SEG,VISIT,GRP
 K ^BQIHL7($J)
 ; Start the batch segment
 S APPARMS("COUNTRY")="USA"
 S APPARMS("FIELD SEPARATOR")="|"
 S APPARMS("ENCODING CHARACTERS")="^~\&"
 S APPARMS("VERSION")="2.5"
 I '$$NEWBATCH^HLOAPI(.APPARMS,.HLMSTATE,.ERROR) Q
 ;
 I $O(^BQIDATA($J,0))'="" D
 . S IN=0
 . F  S IN=$O(^BQIDATA($J,IN)) Q:IN=""  D
 .. D BEG
 .. S RECORD=^BQIDATA($J,IN)
 .. S VISIT=$P(RECORD,DELIM,17)
 .. D SEG
 ;
 I $O(^BQIDATA($J,0))="" D BEG
 ;
 I '$D(ERR) D
 . ; Define sending and receiving parameters
 . S APPARMS("SENDING APPLICATION")="RPMS-CANES"
 . S APPARMS("ACCEPT ACK TYPE")="AL"  ;Commit ACK type
 . S APPARMS("APP ACK RESPONSE")="AACK^BQICAHLO"  ;Callback when 'application ACK' is received
 . S APPARMS("ACCEPT ACK RESPONSE")="CACK^BQICAHLO"  ;Callback when 'commit ACK' is received
 . S APPARMS("APP ACK TYPE")="AL"  ;Application ACK type
 . S APPARMS("QUEUE")="CANES ADT"   ;Incoming QUEUE
 . S WHO("RECEIVING APPLICATION")="CDC"
 . S WHO("FACILITY LINK NAME")="CANES"
 . I '$$SENDONE^HLOAPI1(.HLMSTATE,.APPARMS,.WHO,.ERROR) D
 .. S ERR=$G(ERROR)
 ;
 ; Set up HL7 messages in global for flat file export
 S MSIEN=$G(HLMSTATE("IEN"))
 I MSIEN="" Q
 S CNT=0
 S BDIEN=$P($G(^HLB(MSIEN,0)),U,2) I BDIEN="" Q
 S HIN=0
 F  S HIN=$O(^HLB(MSIEN,3,HIN)) Q:'HIN  D
 . S MSH=""
 . S GRP=$P(^HLB(MSIEN,3,HIN,0),U,1)
 . S N=0
 . F  S N=$O(^HLB(MSIEN,3,HIN,N)) Q:'N  S MSH=MSH_$G(^HLB(MSIEN,3,HIN,N))
 . S CNT=CNT+1,^BQIHL7($J,CNT)=MSH
 . S N=0
 . F  S N=$O(^HLA(BDIEN,2,GRP,1,N)) Q:'N  D
 .. I ^HLA(BDIEN,2,GRP,1,N,0)="" Q
 .. S CNT=CNT+1,^BQIHL7($J,CNT)=^HLA(BDIEN,2,GRP,1,N,0)
 Q
 ;
BEG ; Begin message
 S PARMS("EVENT")="A08"
 S PARMS("MESSAGE TYPE")="ADT"
 I '$$ADDMSG^HLOAPI(.HLMSTATE,.PARMS,.ERROR) D  Q
 . ;
 S HLFS=HLMSTATE("HDR","FIELD SEPARATOR")
 S HLECH=HLMSTATE("HDR","ENCODING CHARACTERS")
 ;
 D SET^HLOAPI(.SEG,"EVN",0)
 D SET^HLOAPI(.SEG,"A08",1)
 D SET^HLOAPI(.SEG,$$HLDATE^HLFNC($$NOW^XLFDT(),"TS"),2)
 I '$$ADDSEG^HLOAPI(.HLMSTATE,.SEG) Q
 Q
 ;
SEG ; For each record, create the segments
 ;PID
 D SET^HLOAPI(.SEG,"PID",0)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,1),2)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,2),3)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,3),6)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,4),7)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,7),11,1)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,8),11,3)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,9),11,4)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,10),11,5)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,11),11,9)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,12),11,8)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,13),10)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,14),22)
 S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG)
 ;PV1
 D SET^HLOAPI(.SEG,"PV1",0)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,15),3)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,16),44)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,17),19)
 S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG)
 ;DG1
 D SET^HLOAPI(.SEG,"DG1",0)
 D SET^HLOAPI(.SEG,1,1)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,18),3,1)
 NEW CODE,SYS,CSY
 I $$VERSION^XPDUTL("AICD")<4.0 D
 . S SYS=1
 I $$VERSION^XPDUTL("AICD")>3.51 D
 . S CODE=$P(RECORD,DELIM,18),SYS=$P($$CODECS^ICDEX(CODE,80),"^",1)
 S CSY=$S(SYS=30:"I10",1:"I9")
 D SET^HLOAPI(.SEG,CSY,3,3)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,19),3,5)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,20),3,6)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,21),3,4)
 S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG)
 ;OBX
 NEW INC,VALUE
 S INC=0
 I $P(RECORD,DELIM,23)'="" D
 . S INC=INC+1
 . D SET^HLOAPI(.SEG,"OBX",0)
 . D SET^HLOAPI(.SEG,INC,1)
 . D SET^HLOAPI(.SEG,"ST",2)
 . D SET^HLOAPI(.SEG,"TMP",3)
 . D SET^HLOAPI(.SEG,$P(RECORD,DELIM,23),5)
 . D SET^HLOAPI(.SEG,"R",11)
 . S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG,.ERR)
 I $P(RECORD,DELIM,24)'="" D
 . S VALUE=$P(RECORD,DELIM,24)
 . F BJ=1:1:$L(VALUE,";") D
 .. S TYP=$P(VALUE,";",BJ)
 .. S INC=INC+1
 .. S MEAS=$P(TYP,"=",1),RESULT=$P(TYP,"=",2)
 .. D SET^HLOAPI(.SEG,"OBX",0)
 .. D SET^HLOAPI(.SEG,INC,1)
 .. D SET^HLOAPI(.SEG,"ST",2)
 .. D SET^HLOAPI(.SEG,MEAS,3)
 .. D SET^HLOAPI(.SEG,RESULT,5)
 .. D SET^HLOAPI(.SEG,"R",11)
 .. S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG,.ERR)
 I $P(RECORD,DELIM,25)'="" D
 . S INC=INC+1
 . D SET^HLOAPI(.SEG,"OBX",0)
 . D SET^HLOAPI(.SEG,INC,1)
 . D SET^HLOAPI(.SEG,"CE",2)
 . S VALUE=$P(RECORD,DELIM,25,26)
 . NEW LAB,RES
 . S RES=$P(VALUE,"^",3),RESULT=$P(RES,"=",2)
 . S LAB=$P(VALUE,"^",1,2)_"^"_$P(RES,"=",1)_"^"_$P(VALUE,"^",4,5)
 . S LAB=$$TKO^BQIUL1(LAB,DELIM)
 . ;S LAB=$P(VALUE,"=",1),RESULT=$P(VALUE,"=",2)
 . S RESULT=$$TKO^BQIUL1(RESULT,DELIM)
 . D SET^HLOAPI(.SEG,$P(LAB,"^",1),3,1)
 . D SET^HLOAPI(.SEG,$P(LAB,"^",2),3,2)
 . D SET^HLOAPI(.SEG,$P(LAB,"^",3),3,3)
 . D SET^HLOAPI(.SEG,$P(LAB,"^",5),3,5)
 . D SET^HLOAPI(.SEG,RESULT,5)
 . D SET^HLOAPI(.SEG,"R",11)
 . I $P(RECORD,DELIM,31)'="" D
 .. S VALUE=$P(RECORD,DELIM,31)
 .. D SET^HLOAPI(.SEG,VALUE,6,1)
 .. D SET^HLOAPI(.SEG,VALUE,6,2)
 .. D SET^HLOAPI(.SEG,"L",6,3)
 . I $P(RECORD,DELIM,32)'="" D
 .. S VALUE=$P(RECORD,DELIM,32)
 .. NEW L,H
 .. S L=$P(VALUE,"^",1),H=$P(VALUE,"^",2)
 .. I L'="",H'="" D SET^HLOAPI(.SEG,L_"-"_H,7) Q
 .. I L'="",H="" D
 ... I L'?.N D SET^HLOAPI(.SEG,L,7) Q
 ... D SET^HLOAPI(.SEG,">"_L,7)
 .. I L="",H'="" D SET^HLOAPI(.SEG,"<"_H,7)
 . I $P(RECORD,DELIM,33)'="" D
 .. S VALUE=$P(RECORD,DELIM,33)
 .. I VALUE'["*" D SET^HLOAPI(.SEG,VALUE,8) Q
 .. D SET^HLOAPI(.SEG,$S(VALUE["H":"HH",1:"LL"),8)
 . S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG,.ERR)
 ; NTE
 I $P(RECORD,DELIM,30)'="" D
 . NEW FILE,RIEN,VALUE,COMM,I
 . S VALUE=$P(RECORD,DELIM,30)
 . S FILE=$P(VALUE,":",1),RIEN=$P(VALUE,":",2)
 . I FILE=9000010.25 D
 .. F I=1:1:3 S COMM=$P($G(^AUPNVMIC(RIEN,13)),U,I) I COMM'="" D
 ... D SET^HLOAPI(.SEG,"NTE",0)
 ... D SET^HLOAPI(.SEG,I,1)
 ... D SET^HLOAPI(.SEG,COMM,3)
 ... S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG,.ERR)
 . I FILE=9000010.09 D
 .. S I=0
 .. F  S I=$O(^AUPNVLAB(RIEN,21,I)) Q:'I  D
 ... S COMM=^AUPNVLAB(RIEN,21,I,0)
 ... D SET^HLOAPI(.SEG,"NTE",0)
 ... D SET^HLOAPI(.SEG,I,1)
 ... D SET^HLOAPI(.SEG,COMM,3)
 ... S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG,.ERR)
 . S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG)
 ;ZID
 D SET^HLOAPI(.SEG,"ZID",0)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,5),1,1)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,6),1,2)
 S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG)
 ;ZLI
 NEW VER,PTCH,VERSION
 S VER=$$VERSION^XPDUTL("BQI")
 S PTCH=$$LAST^XPDUTL("ICARE MANAGEMENT SYSTEM",VER)
 S VERSION=VER_$S($P(PTCH,U,1)'=-1:"P"_$P(PTCH,U,1),1:"")
 D SET^HLOAPI(.SEG,"ZLI",0)
 D SET^HLOAPI(.SEG,$P(RECORD,DELIM,22),3)
 D SET^HLOAPI(.SEG,VERSION,10)
 S X=$$ADDSEG^HLOAPI(.HLMSTATE,.SEG)
 Q
 ;
AACK ; Application Acknowledgement
 Q
 ;
CACK ; Commit Acknowledgement
 Q