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

PSXDODH.m

Go to the documentation of this file.
PSXDODH ;BIR/HTW-HL7 Message Conversion ;01/15/02 13:10:52
 ;;2.0;CMOP;**38**;11 Apr 97
 ;  Convert CMOP transmission messages from HL7 V 2.3.1 to V 2.1
START ;  Create 2.1 format 
EN(PATH,FNAME) ; needs directory & file name
 ; force an error in the next line
 ;S X=ERROR ; generate an undefined error 
 I $L(PATH),$L(FNAME) I 1
 E  S PSXERR="0^BAD PATH OR FILENAME" G ERRMSG
 K ^TMP($J,"PSXDOD")
 S GBL="^TMP("_$J_",""PSXDOD"",1)"
 S Y=$$FTG^%ZISH(PATH,FNAME,GBL,3)
 I Y'>0 S PSXERR="9^"_PATH_U_FNAME_U_" DID NOT LOAD" G ERRMSG
 I $D(^TMP($J,"PSXDOD"))'>1 S PSXERR="9^"_PATH_U_FNAME_U_" DID NOT LOAD" G ERRMSG
EN1 ;
 S PSXERR=""
 S G="^TMP($J,""PSXDOD"")" ; for global indirection
 ; Perform Patient Safety check and gather a few variables
 D BLDSEQ^PSXDODH1,TESTBT^PSXDODH1
 ;send acknowledgement message
 K ACK
 S ACK="MSH|^~\&|VistA||CHCS||20010925202704||ORM^O02|573-013240530|P|2.3.1|||NE|NE"
 S BATID=BATIDB,PIECE(BHS,"|",11)=BATID
 D NOW^%DTC S BATDTM=+$$HLDATE^HLFNC(%)
 F YY="BATID^10","BATDTM^7" D PUT(.ACK,"|",YY)
 S ACK(1)=ACK,ACK(2)="MSA|CR|"_BATID
 I PSXERR'="" S ACK(2)=ACK(2)_"|"_PSXERR
 S FNAME2=$P(FNAME,".",1)_".TAC",PATH=$$GET1^DIQ(554,1,21)
 I PSXERR'="" D
 . F XX=1:1:5 S Y=$$GTF^%ZISH("ACK(1)",1,PATH,FNAME2) Q:Y=1  H 4
 . I Y'=1 D FALERT^PSXDODH1(FNAME2,PATH)
 . S PATH=$$GET1^DIQ(554,1,22)
 . F XX=1:1:5 S Y=$$GTF^%ZISH("ACK(1)",1,PATH,FNAME2) Q:Y=1  H 4
 . I Y'=1 D FALERT^PSXDODH1(FNAME2,PATH)
 . ;****TESTING
 I PSXERR'="" G ERRMSG
EN2 ;entry for processing file into Vista Messages
 S (LNCNT,MCNT,LMSGLOC,ORDCNT)=0 ;line count, message line count, last $$MSG location, order count
 D HEADER^PSXDODH1 ; build $$XMIT & NTE|1 and set into Message    
 S XMSUB="DOD CMOP "_FACNUM_"-"_BATNM_" from "_FACNM,XMDUZ=.5
XMZ D XMZ^XMA2
 S M="^XMB(3.9,XMZ,2)" ; variable reference to MailMan message for construction
 S @M@(1,0)=XM
 S @M@(2,0)=NTE1,MCNT=2
 S LNNUM=3 F  S LNNUM=$O(@G@(LNNUM)) Q:LNNUM'>0  S LN=@G@(LNNUM),SEG=$P(LN,"|") S:SEG["NTE" SEG=$P(LN,"|",1,2) D
 . I "NTE|2,NTE|3,NTE|4"[SEG D NTE234
 . I SEG="MSH" D MSH
 . I SEG="PID" D PID
 . I SEG="ORC" D ORC
 . I SEG="RXE" D RXE
 . I SEG="NTE|7" K NTE7 S NTE7=LN
 . I SEG="ZR1" D ZR1,BUILD,SETRX
 . I SEG="BTS" D BTS
 S ^XMB(3.9,XMZ,2,0)="^^"_MCNT_U_MCNT_U_DT
 S XMY("S.PSXX CMOP SERVER")=""
 ;S XMY(DUZ)="" ;****TESTING
 D ENT1^XMD
 D EXIT
 Q
MSH ;assemble $$MSG, MSH
 ;MSH|^~\&|CHCS||VistA||20020219144700||ORM^O01|0124-020501408-1|P|2.3.
 D NTE234CK
 S DODORD=$P(LN,"|",10),DODORD=$P(DODORD,"-",3)
 S ORDCNT=ORDCNT+1
 S MCNT=MCNT+1,@M@(MCNT,0)="$MSG^"_ORDCNT ; Set current order $MSG order value
 I LMSGLOC S $P(@M@(LMSGLOC,0),"^",3)=MCNT-LMSGLOC ; Set last $MSG's location value of line count
 S LMSGLOC=MCNT ; store current $MSGs location
 S MSH="MSH|^~\&|CHCS||VistA||20020219144700||ORM|0124-020501408-1|P|2.1|" ;****Testing
 S $P(MSH,7,"|")=$P(LN,"|",7),$P(MSH,"|",10)=ORDCNT
 S MCNT=MCNT+1,@M@(MCNT,0)=MSH
 Q
PID ;
 ;"PID|||98374511^3^M11||DUCK^CONSTANCE SUSAN||||||1804 MAUMPHREY LANE E.^^HIRANDO^CA^36662||2059880101"
 S PID0=$P(LN,"PID|",2)
 F YY="PTID^3","PNAME^5","PADD^11","PHONE^13" D PIECE(PID0,"|",YY)
 S PT1ST=$P(PNAME,"^",3,99),PTLST=$P(PNAME,"^",1,2) ; VENDOR ADJUSTMENT (REMOVE "^")
 S PT1ST=$TR(PT1ST,"^"," "),PNAME=PTLST_"^"_PT1ST ; VENDOR ADJUSTMENT (REMOVE "^")
 K PT1ST,PTLST ; VENDOR ADJUSTMENT (REMOVE "^")
 S PNAME=$P(PNAME,"^",2,99) ; remove leading "^"
 S PID="" F YY="PTID^3","PNAME^5","PADD^11","PHONE^13" D PUT(.PID,"|",YY)
 S PID="PID|"_PID
 S MCNT=MCNT+1,@M@(MCNT,0)=PID
 Q
 ;
ORC ;Patient Data from ORC and RXE(2.3.1) parse date pieces for RX1,ZX1
 ; element mapping contained in document HL7 2.1_2.3 CONVERSION.xls
 ;S NODE="ORC|NM|0124-NA1281-2||2^1|||^^^20020213^20020315|||25||^HENDERSON^DIANE|||20020213000000||||||||"
 K RX1,ZX1
 S ORC=$P(LN,"ORC|",2) ; adjust line for HL7 component counting
 F YY="RXINDX^2","RXCNT^4","RXDATES^7","PRVPHY^12","ISSDT^15" D PIECE(ORC,"|",YY)
 S RFLDT=$P(RXDATES,"^",4),EXPDT=$P(RXDATES,"^",5)
 S MCNT=MCNT+1,@M@(MCNT,0)="ORC|NW|"
 Q
RXE ;  Start building RX1.  RX1 has data elements from ORC and RXE segments from 3.2.1  
 ;S RXE="RXE|100|A0259^AMOXICILLIN 250MG CAP^L|100||CAP||^TAKE ONE FOUR TIMES A DAY AS DIRECTED THEN TAKE 10 THREE TIMES A DAY AS DIRECTE|||||10||25|NA1281|9||20020213151053"
 S RXE=$P(LN,"RXE|",2)
 F YY="QTY^1","DRUGID^2","SIG^7","NUMRFLS^12","VERPHRM^14","RXNUM^15","RFLRMN^16","LSTRFLDT^18" D PIECE(RXE,"|",YY)
 S RXNUM=$P(RXNUM,"-",2)
 S ISSDT=$$FMDATE^HLFNC(ISSDT)\1,ISSDT=$$HLDATE^HLFNC(ISSDT) ;strip off time
 S LSTRFLDT=$$FMDATE^HLFNC(LSTRFLDT)\1,LSTRFLDT=$$HLDATE^HLFNC(LSTRFLDT)
 S SIG=$E(SIG,2,200)
 Q
ZR1 ;
 ;S NODE="ZR1|NA1281|ONSC|1||1|(2of10)|CMOP TEST PHARMACY|30|RXNA1281|||20030213000000|"
 S ZR1=$P(LN,"ZR1|",2)
 F YY="RXZNUM^1","PATSTAT^2","RNWTYP^3","COPAYID^4","SAFCAP^5","RFLTXT^6","CLNIC^7","DAYSUP^8" D PIECE(ZR1,"|",YY)
 F YY="BARCODE^9","WARNFLG^10","RGSTMAIL^11" D PIECE(ZR1,"|",YY)
 S MAILID="M",RXCNT=$P(RXCNT,"~",1),PRVPHY=$$FMNAME^HLFNC(PRVPHY,"^")
 S LL=$F(PRVPHY," "),$E(PRVPHY,LL-1)="," ;change provider name to FM format "last,first mi jr"
 S RXZNUM=$P(RXZNUM,"-",2),SITEID=DIVNUM_"^"_DIVNM
 Q
BTS ; FINISH
 S MCNT=MCNT+1
 I LMSGLOC S $P(@M@(LMSGLOC,0),"^",3)=MCNT-LMSGLOC
 S END="$$ENDXMIT^^"_DIVNUM_U_BATNM_U_PTCNTB_U_ORDCNTB
 ;S END=$$SETELM^PSXDODH1(END,3,"^",693) ;****TESTING
 ;S END=$$SETELM^PSXDODH1(END,"4,1","^,-",693) ;****TESTING
 S @M@(MCNT,0)=END
 Q
BUILD ; assemble RX1 & ZX1
 ;RX1|NA1367|||||||||||60||P0151^PROPRANOLOL HCL 10MG TAB^L|||||3|20020402|2|||20020502|20020226|0124-NA1367-2||||TAKE ONE TABLET TWICE A DAY
 ;ZX1|NA1367|0124^BALBOA|M|1^1|(2of3)|GORDON ,TEVE||20|20020402||1|1|30||RXNA1367||ONSC|BALBOA
 ; gather elements from subscripted segment array and assemble the segment
 S RXINDX="1"_RXINDX ;****Institution file change for site leading 0s
 S RX1=""
 F YY="RXINDX^1","QTY^12","DRUGID^14","NUMRFLS^19","ISSDT^20","RFLRMN^21","EXPDT^24","LSTRFLDT^25","RXNUM^26","SIG^30" D PUT(.RX1,"|",YY)
 S RX1="RX1|"_RX1
 S ZX1=""
 S RXCNT=$P(RXCNT,"^",2)
 F YY="RXZNUM^1","SITEID^2","MAILID^3","RXCNT^4","RFLTXT^5","PRVPHY^6","RGSTMAIL^7","VERPHRM^8","RFLDT^9" D PUT(.ZX1,"|",YY)
 F YY="COPAYID^10","RNWTYP^11","SAFCAP^12","DAYSUP^13","BARCODE^15","WARNFLG^16","PATSTAT^17","CLNIC^18" D PUT(.ZX1,"|",YY)
 S ZX1="ZX1|"_ZX1
 ; change site number for testing
 ;S RX1=$$SETELM^PSXDODH1(RX1,"2,1","|,-",693) ;****TESTING
 ;S ZX1=$$SETELM^PSXDODH1(ZX1,"3,1","|,^",693) ;****TESTING
 Q
SETRX ;put RX1,ZX1,NTE7 into mail message
 S MCNT=MCNT+1,@M@(MCNT,0)=RX1
 I $L($G(NTE7)) S MCNT=MCNT+1,@M@(MCNT,0)=NTE7 K NTE7
 S MCNT=MCNT+1,@M@(MCNT,0)=ZX1
 Q
NTE234 ; insure 2 3 4 sequence is in place
 I SEG="NTE|2" S MCNT=MCNT+1,@M@(MCNT,0)=LN,NTE2=1
 I SEG="NTE|3" D  S MCNT=MCNT+1,@M@(MCNT,0)=LN,NTE3=1
 . I '$G(NTE2) S MCNT=MCNT+1,@M@(MCNT,0)="NTE|2||",NTE2=1
 I SEG="NTE|4" D  S MCNT=MCNT+1,@M@(MCNT,0)=LN,NTE4=1
 . I '$G(NTE2) S MCNT=MCNT+1,@M@(MCNT,0)="NTE|2||",NTE2=1
 . I '$G(NTE3) S MCNT=MCNT+1,@M@(MCNT,0)="NTE|3||",NTE3=1
 Q
NTE234CK ; encounter MSH , insure NTE 2,3,4 in place
 I '$G(NTE2) S MCNT=MCNT+1,@M@(MCNT,0)="NTE|2||",NTE2=1
 I '$G(NTE3) S MCNT=MCNT+1,@M@(MCNT,0)="NTE|3||",NTE3=1
 I '$G(NTE4) S MCNT=MCNT+1,@M@(MCNT,0)="NTE|4||",NTE4=1
 Q
PIECE(REC,DLM,XX) ;
 ; Set variable V = piece P of REC using delimiter DLM
 N V,P S V=$P(XX,U),P=$P(XX,U,2),@V=$P(REC,DLM,P)
 Q
PUT(REC,DLM,XX) ;
 ; Set Variable V into piece P of REC using delimiter DLM
 N V,P S V=$P(XX,U),P=$P(XX,U,2)
 S $P(REC,DLM,P)=$G(@V)
 Q
GETELM(STR,PIECES,SEPS) ;
 ; uses STRing and
 ; returns value of the element located by path of pieces and separators
 ; ex: 1st address line = $$getelm(ORC,"22,1","|,^")
 ; or                   = $$getelm(XMIT,"4,2,1","|,\F\,\S|")
 N P,S,PI,V,I S V=STR
 F I=1:1 S PI=$P(PIECES,",",I) Q:PI=""  S P=I,P(I)=PI,S(I)=$P(SEPS,",",I)
 F I=1:1:P S V=$P(V,S(I),P(I))
 Q V
ERRMSG ;
MSGSEQER ;send error message to folks & DOD
 ;W !,"error ",PSXERR
 S DIRHOLD=$$GET1^DIQ(554,1,23)
 S Y=$$GTF^%ZISH($NA(^TMP($J,"PSXDOD",1)),3,DIRHOLD,FNAME)
 S XMSUB="DOD CMOP Safety "_FNAME
 S XMY("G.PSXX CMOP MANAGERS")=""
 ;S XMY(DUZ)="" ;***TESTING
 S XMTEXT="PSXTXT("
 S PSXTXT(1,0)="DOD CMOP HL7 Conversion to  VA CMOP HL7 experienced an error"
 S PSXTXT(2,0)=$G(PSXERR)
 S PSXTXT(3,0)="FILE: "_FNAME
 S PSXTXT(4,0)="A copy of the file has been placed in the hold directory "_DIRHOLD
 D ^XMD
 I $E(IOST)="C" W ! F I=1:1:4 W !,PSXTXT(I,0) I I=4 H 3
 K PSXTXT,DIRHOLD
 Q
EXIT ;
 K BATIDB,BATIDM,BHS,BTS,DLM,DODORD,END,FHS,FNAME,G,GBL,I,J,JJ,LL,LINE,LMSGLOC
 K LN,LNCNT,LNNUM,LSEG,M,MCNT,MSH,NTE1,NTE2,NTE3,NTE4,NTE7,ORC,ORDCNT,ORDCNTB
 K P,P1,P2,P3,PATH,PI,PID,PNAME,PSXERR,PSXTXT,PTCNT,PTCNTB,REC,RX1,RXE,RXID1,RXIDC,RXIDE
 K S,S1,S2,S3,SEG,SEGSEQ,SEPS,STR,STR0,V,VALUE,XM,XX,Y,YY,ZR1,ZX1
 K ADDRESS,BATDTM,BATID,BATIDB,BATIDM,BATNM,DIVISION,DIVNM,DIVNUM,EXPDT,FACNM,FNAME2,FNAME3,ISSDT
 K LSTRFLDT,MAILID,NTE1ADD,NTE1DIV,NTE1LOC,PID0,PIECE,PRVPHY,PSXF,RFLDT,RXCNT,RXDATES,RXNUM,RXZNUM
 K SIG,SITEID,START,TRANDTS,XMZ
 K ^TMP($J,"PSXDOD"),PSXTXT
 Q
LOADTMP ; load data into ^TMP
 K ^TMP($J,"PSXDOD")
 F I=1:1 S X=$G(^XMB(3.9,125829,2,I,0)) Q:X=""  S ^TMP($J,"PSXDOD",I)=X
 Q
CLEARFLS(XX,EXT) ;
LOOP K PSXF,PSXL
 S PATH=$$GET1^DIQ(554,1,XX),PSXF(EXT)=""
 S Y=$$LIST^%ZISH(PATH,"PSXF","PSXL")
 W !,"path ",PATH,!,"files ",EXT
 Q:$D(PSXL)'>1
 S FILE="" F I=0:0 S FILE=$O(PSXL(FILE)) Q:FILE=""  W !,FILE S I=I+1
 Q:I'>0
 K DIR S DIR(0)="Y",DIR("A")="DELETE FILES ?? ",DIR("B")="N" D ^DIR K DIR Q:Y'>0
 W $$DEL^%ZISH(PATH,"PSXL")
 G LOOP
 Q