MHV7B1R ;WAS/GPM - HL7 message builder RTB^K13 Medications Profile ; 10/13/05 7:52pm [12/24/07 5:39pm]
;;1.0;My HealtheVet;**40**;Aug 23, 2005;Build 26
;;Per VA Directive 6402, this routine should not be modified
;
Q
;
RDF(MSGROOT,CNT,LEN,HL) ; Build RDF segment for Rx Profile data
;
; Input:
; MSGROOT - Root of array holding the message
; CNT - Current message line counter
; LEN - Current message length
; HL - HL7 package array variable
;
; Output:
; - Populated message array
; - Updated LEN and CNT
;
N RDF
S RDF(0)="RDF"
S RDF(1)=52
S RDF(2,1,1)="Prescription Number",RDF(2,1,2)="ST",RDF(2,1,3)=30
S RDF(2,2,1)="IEN",RDF(2,2,2)="NM",RDF(2,2,3)=30
S RDF(2,3,1)="Drug Name",RDF(2,3,2)="ST",RDF(2,3,3)=50
S RDF(2,4,1)="Issue Date/Time",RDF(2,4,2)="TS",RDF(2,4,3)=26
S RDF(2,5,1)="Last Fill Date",RDF(2,5,2)="TS",RDF(2,5,3)=26
S RDF(2,6,1)="Release Date/Time",RDF(2,6,2)="TS",RDF(2,6,3)=26
S RDF(2,7,1)="Expiration",RDF(2,7,2)="TS",RDF(2,7,3)=26
S RDF(2,8,1)="Status",RDF(2,8,2)="ST",RDF(2,8,3)=25
S RDF(2,9,1)="Quantity",RDF(2,9,2)="NM",RDF(2,9,3)=11
S RDF(2,10,1)="Days Supply",RDF(2,10,2)="NM",RDF(2,10,3)=5
S RDF(2,11,1)="Refills Remaining",RDF(2,11,2)="NM",RDF(2,11,3)=5
S RDF(2,12,1)="Provider",RDF(2,12,2)="XCN",RDF(2,12,3)=150
S RDF(2,13,1)="Placer Order Number",RDF(2,13,2)="ST",RDF(2,13,3)=30
S RDF(2,14,1)="Mail/Window",RDF(2,14,2)="ST",RDF(2,14,3)=10
S RDF(2,15,1)="Division",RDF(2,15,2)="NM",RDF(2,15,3)=50
S RDF(2,16,1)="Division Name",RDF(2,16,2)="ST",RDF(2,16,3)=50
S RDF(2,17,1)="MHV Request Status",RDF(2,17,2)="NM",RDF(2,17,3)=5
S RDF(2,18,1)="MHV Request Status Date",RDF(2,18,2)="TS",RDF(2,18,3)=26
S RDF(2,19,1)="Remarks",RDF(2,19,2)="ST",RDF(2,19,3)=1024
S RDF(2,20,1)="Source",RDF(2,20,2)="ST",RDF(2,20,3)=2
S RDF(2,21,1)="NDC",RDF(2,21,2)="ST",RDF(2,21,3)=15
S RDF(2,22,1)="Dispensed Date",RDF(2,22,2)="TS",RDF(2,22,3)=26
S RDF(2,23,1)="Trade Name",RDF(2,23,2)="ST",RDF(2,23,3)=30
S RDF(2,24,1)="Reason",RDF(2,24,2)="ST",RDF(2,24,3)=100
S RDF(2,25,1)="Reason Comment",RDF(2,25,2)="st",RDF(2,25,3)=1024
S RDF(2,26,1)="Cancel Date",RDF(2,26,2)="TS",RDF(2,26,3)=26
S RDF(2,27,1)="Facility Site Number",RDF(2,27,2)="ST",RDF(2,27,3)=50
S RDF(2,28,1)="Facility Name",RDF(2,28,2)="ST",RDF(2,28,3)=50
S RDF(2,29,1)="Facility Address Line 1",RDF(2,29,2)="ST",RDF(2,29,3)=100
S RDF(2,30,1)="Facility City",RDF(2,30,2)="ST",RDF(2,30,3)=60
S RDF(2,31,1)="Facility State",RDF(2,31,2)="ST",RDF(2,31,3)=10
S RDF(2,32,1)="Facility Zip",RDF(2,32,2)="ST",RDF(2,32,3)=10
S RDF(2,33,1)="Facility Phone Number",RDF(2,33,2)="NM",RDF(2,33,3)=10
S RDF(2,34,1)="Next Possible Fill Date",RDF(2,34,2)="TS",RDF(2,34,3)=26
S RDF(2,35,1)="Drug Schedule",RDF(2,35,2)="ST",RDF(2,35,3)=50
S RDF(2,36,1)="VAMC Tracking Number",RDF(2,36,2)="ST",RDF(2,36,3)=25
S RDF(2,37,1)="CMOP Tracking Number",RDF(2,37,2)="ST",RDF(2,37,3)=25
S RDF(2,38,1)="CMOP Date Shipped",RDF(2,38,2)="TS",RDF(2,38,3)=26
S RDF(2,39,1)="CMOP Carrier",RDF(2,39,2)="ST",RDF(2,39,3)=50
S RDF(2,40,1)="Carrier Tracking Number",RDF(2,40,2)="ST",RDF(2,40,3)=25
S RDF(2,41,1)="Number of RX in Package",RDF(2,41,2)="NM",RDF(2,41,3)=5
S RDF(2,42,1)="CMOP System",RDF(2,42,2)="ST",RDF(2,42,3)=50
S RDF(2,43,1)="CMOP Status",RDF(2,43,2)="ST",RDF(2,43,3)=50
S RDF(2,44,1)="CMOP RX Indicator",RDF(2,44,2)="ST",RDF(2,44,3)=5
S RDF(2,45,1)="CMOP NDC Received",RDF(2,45,2)="ST",RDF(2,45,3)=15
S RDF(2,46,1)="CMOP NDC Sent",RDF(2,46,2)="ST",RDF(2,46,3)=15
S RDF(2,47,1)="Orderable Item",RDF(2,47,2)="ST",RDF(2,47,3)=30
S RDF(2,48,1)="Administered At Clinic",RDF(2,48,2)="NM",RDF(2,48,3)=10
S RDF(2,49,1)="Clinic/Hospital Location",RDF(2,49,2)="TX",RDF(2,49,3)=100
S RDF(2,50,1)="SIG",RDF(2,50,2)="TX",RDF(2,50,3)=1024
S RDF(2,51,1)="UNIQUE INDEX",RDF(2,51,2)="TX",RDF(2,51,3)=10
S RDF(2,52,1)="DISCLAIMER",RDF(2,52,2)="TX",RDF(2,52,3)=1024
;
S CNT=CNT+1
S @MSGROOT@(CNT)=$$BLDSEG^MHV7U(.RDF,.HL)
S LEN=LEN+$L(@MSGROOT@(CNT))
Q
;
RDT(MSGROOT,DATAROOT,CNT,LEN,HL) ; Build RDT segments for Rx Profile data
;
; Walks data in DATAROOT to populate MSGROOT with RDT segments
; sequentially numbered starting at CNT
;
; Integration Agreements:
; 10103 : FMTHL7^XLFDT
; 3065 : HLNAME^XLFNAME
;
; Input:
; MSGROOT - Root of array holding the message
; DATAROOT - Root of array to hold extract data
; CNT - Current message line counter
; LEN - Current message length
; HL - HL7 package array variable
;
; Output:
; - Populated message array
; - Updated LEN and CNT
;
N I,CMP,DIV,RX,CMOP,RXP,RXN,RXN1,RXN2,RXN3,RXN4,RXD,RDT,SIG,SEG,PIEN,NAME,WPLEN,PHRM,RTXT,STXT,TXT,DTXT,REM,DISC
D LOG^MHVUL2("MHV7B1R","BEGIN RDT","S","TRACE")
F I=1:1 Q:'$D(@DATAROOT@(I)) D
. K RDT
. S (RTXT,STXT,TXT)=""
. S CMOP=$G(@DATAROOT@(I,"CMOP"))
. S RX=$G(@DATAROOT@(I))
. S RXN=$G(@DATAROOT@(I,"RXN"))
. S RXN1=$G(@DATAROOT@(I,"RXN1"))
. S RXN2=$G(@DATAROOT@(I,"RXN2"))
. S RXN3=$G(@DATAROOT@(I,"RXN3"))
. S RXN4=$G(@DATAROOT@(I,"RXN4"))
. S PHRM=$G(@DATAROOT@(I,"PHRM"))
. S RXP=$G(@DATAROOT@(I,"P"))
. S PIEN=+RXP
. S RXD=$G(@DATAROOT@(I,"DIV"))
. ;K SIG I $D(@DATAROOT@(I,"SIG")) M SIG=@DATAROOT@(I,"SIG")
. S RDT(0)="RDT"
. S RDT(1)=$P(RX,"^") ;Rx Number
. S RDT(2)=$P(RXN,"^") ;Rx IEN
. S RDT(3)=$$ESCAPE^MHV7U($P(RXN,"^",2),.HL) ;Drug Name
. S RDT(4)=$$FMTHL7^XLFDT($P(RXN,"^",3)) ;Issue Date/Time
. S RDT(5)=$$FMTHL7^XLFDT($P(RXN,"^",4)) ;Last Fill Date
. S RDT(6)=$$FMTHL7^XLFDT($P(RXN,"^",5)) ;Release Date/Time
. S RDT(7)=$$FMTHL7^XLFDT($P(RXN,"^",6)) ;Expiration
. S RDT(8)=$$ESCAPE^MHV7U($P(RXN1,"^",1),.HL) ;Status
. S RDT(9)=$P(RXN1,"^",2) ;Quantity
. S RDT(10)=$P(RXN1,"^",3) ;Days Supply
. S RDT(11)=$P(RXN1,"^",4) ;Number of Refills
. I PIEN D
.. D FMTNAME2^MHV7BU(PIEN,200,.NAME,.HL,"XCN") ;Provider IEN
.. M RDT(12,1)=NAME
.. S RDT(12,1,1)=PIEN
. S RDT(13)=$$ESCAPE^MHV7U($P(RXN1,"^",5),.HL) ;Placer Order Number
. S RDT(14)=$P(RXN1,"^",6) ;Mail/Window
. S RDT(15)=$P(RXD,"^") ;Division
. S RDT(16)=$$ESCAPE^MHV7U($P(RXD,"^",2),.HL) ;Division Name
. S RDT(17)=$P(RX,"^",3) ;MHV status
. S RDT(18)=$$FMTHL7^XLFDT($P(RX,"^",4)) ;MHV status date
. S RTXT=$$RMK("RMK")
. S TXT=$$ESCAPE($E(RTXT,1,1024),.HL) ;Remarks
. S RDT(19)=$$SPACES(TXT)
. S RDT(20)=$P(RXN2,"^",1) ;Source
. S RDT(21)=$P(RXN2,"^",2) ;NDC
. S RDT(22)=$$FMTHL7^XLFDT($P(RXN2,"^",3)) ;Dispense Date
. S RDT(23)=$P(RXN,"^",8) ;Trade Name
. S RDT(24)=$P(RXN2,"^",4) ;Reason for Auto DC'ed: Rx Discontinued by EHRM Data Migration. - Activity log.
. S RDT(25)=$P(RXN2,"^",5) ;Auto DC'ed: Rx Discontinued by EHRM Data Migration.
. S RDT(26)=$$FMTHL7^XLFDT($P(RXN2,"^",6)) ;Cancel Date
. S RDT(27)=$P(PHRM,"^",8) ;Site Number
. S RDT(28)=$P(PHRM,"^",2) ;Facility Name
. S RDT(29)=$P(PHRM,"^",3) ;Facility Address Line1
. S RDT(30)=$P(PHRM,"^",5) ;Facility City
. S RDT(31)=$P(PHRM,"^",7) ;Facility State
. S RDT(32)=$P(PHRM,"^",6) ;Facility Zip
. S RDT(33)=$P(PHRM,"^",4) ;Facility Phone
. S RDT(34)=$$FMTHL7^XLFDT($P(RXN3,"^",2)) ;Refilliable Date
. S RDT(35)=$P(RXN3,"^",3) ;Drug Schedule
. S RDT(36)=$P(RXN3,"^",4) ;Other Tracking Number pulled from activity log
. S RDT(37)=$P(CMOP,"^",11) ;CMOP Tracking Number
. S RDT(38)=$$FMTHL7^XLFDT($P(CMOP,"^",9)) ;CMOP Date Shipped
. S RDT(39)=$P(CMOP,"^",10) ;CMOP Carrier
. S RDT(40)="" ;Carrier Tracking Number <FUTURE USE>
. S RDT(41)="" ;Number of RX in Package <FUTURE USE>
. S RDT(42)="" ;CMOP System <FUTURE USE>
. S RDT(43)=$P(CMOP,"^",3) ;CMOP Status
. S RDT(44)=$P(CMOP,"^",2) ;CMOP Rx Indicator
. S RDT(45)=$P(CMOP,"^",4) ;CMOP NDC Received
. S RDT(46)=$P(CMOP,"^",12) ;CMOP NDC Sent
. S RDT(47)=$P(RXN3,"^",5) ;Orderable Item
. S RDT(48)=$P(RXN3,"^",6) ;Administered at Clinic
. s RDT(49)=$P(RXN3,"^",1) ;Clinic
. S STXT=$$RMK("SIG")
. S TXT=$$ESCAPE($E(RTXT,1,1024),.HL)
. S RDT(50)=$$SPACES(STXT) ;Sig
. S RDT(51)=$P(RXN1,"^",7) ;UNIQUE INDEX FOR RF AND PF
. S RDT(52)=""
. I RDT(20)="NV" D
. .S DISC=$$RMK("DSC") ;DISCLAIMER FOR NONVA
. .S REM=$$RMK("RMK")
. .S DTXT=$P(DISC,REM,1)
. .S TXT=$$ESCAPE($E(DTXT,1,1024),.HL)
. .S RDT(52)=$$SPACES(TXT)
. S CNT=CNT+1
. S @MSGROOT@(CNT)=$$BLDSEG^MHV7U(.RDT,.HL)
. S LEN=LEN+$L(@MSGROOT@(CNT))
. Q
D LOG^MHVUL2("MHV7B1R","END RDT","S","TRACE")
Q
;
RMK(TYP) ; build Remark field
N X,Y
S X="",Y=0
F S Y=$O(@DATAROOT@(I,TYP,Y)) Q:'Y D
.Q:$G(@DATAROOT@(I,TYP,Y,0))=""
.S:X]"" X=X_" "
.S X=X_@DATAROOT@(I,TYP,Y,0)
Q X
;
SPACES(WPN) ; Remove extra spaces from line of text
N OUT,IX,SP
S OUT=WPN
S SP=" "
F IX=$L(OUT):-1:1 I ($E(OUT,IX,IX+1)=(SP_SP)) S $E(OUT,IX)=""
Q OUT
;
ESCAPE(VAL,HL) ;Escape any special characters
;
; Input:
; VAL - value to escape
; HL - HL7 environment array
;
; Output:
; VAL - passed by reference
;
N FS ;field separator
N CS ;component separator
N RS ;repetition separator
N ES ;escape character
N SS ;sub-component separator
N L,STR,I
;
S FS=HL("FS")
S CS=$E(HL("ECH"))
S RS=$E(HL("ECH"),2)
S ES=$E(HL("ECH"),3)
S SS=$E(HL("ECH"),4)
;
I VAL[ES D
. S L=$L(VAL,ES),STR=""
. F I=1:1:L S $P(STR," ",I)=$P(VAL,ES,I)
. S VAL=STR
I VAL[FS D
. S L=$L(VAL,FS),STR=""
. F I=1:1:L S $P(STR," ",I)=$P(VAL,FS,I)
. S VAL=STR
I VAL[RS D
. S L=$L(VAL,RS),STR=""
. F I=1:1:L S $P(STR," ",I)=$P(VAL,RS,I)
. S VAL=STR
I VAL[CS D
. S L=$L(VAL,CS),STR=""
. F I=1:1:L S $P(STR," ",I)=$P(VAL,CS,I)
. S VAL=STR
I VAL[SS D
. S L=$L(VAL,SS),STR=""
. F I=1:1:L S $P(STR," ",I)=$P(VAL,SS,I)
. S VAL=STR
Q VAL
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMHV7B1R 10265 printed Dec 13, 2024@02:15:46 Page 2
MHV7B1R ;WAS/GPM - HL7 message builder RTB^K13 Medications Profile ; 10/13/05 7:52pm [12/24/07 5:39pm]
+1 ;;1.0;My HealtheVet;**40**;Aug 23, 2005;Build 26
+2 ;;Per VA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
RDF(MSGROOT,CNT,LEN,HL) ; Build RDF segment for Rx Profile data
+1 ;
+2 ; Input:
+3 ; MSGROOT - Root of array holding the message
+4 ; CNT - Current message line counter
+5 ; LEN - Current message length
+6 ; HL - HL7 package array variable
+7 ;
+8 ; Output:
+9 ; - Populated message array
+10 ; - Updated LEN and CNT
+11 ;
+12 NEW RDF
+13 SET RDF(0)="RDF"
+14 SET RDF(1)=52
+15 SET RDF(2,1,1)="Prescription Number"
SET RDF(2,1,2)="ST"
SET RDF(2,1,3)=30
+16 SET RDF(2,2,1)="IEN"
SET RDF(2,2,2)="NM"
SET RDF(2,2,3)=30
+17 SET RDF(2,3,1)="Drug Name"
SET RDF(2,3,2)="ST"
SET RDF(2,3,3)=50
+18 SET RDF(2,4,1)="Issue Date/Time"
SET RDF(2,4,2)="TS"
SET RDF(2,4,3)=26
+19 SET RDF(2,5,1)="Last Fill Date"
SET RDF(2,5,2)="TS"
SET RDF(2,5,3)=26
+20 SET RDF(2,6,1)="Release Date/Time"
SET RDF(2,6,2)="TS"
SET RDF(2,6,3)=26
+21 SET RDF(2,7,1)="Expiration"
SET RDF(2,7,2)="TS"
SET RDF(2,7,3)=26
+22 SET RDF(2,8,1)="Status"
SET RDF(2,8,2)="ST"
SET RDF(2,8,3)=25
+23 SET RDF(2,9,1)="Quantity"
SET RDF(2,9,2)="NM"
SET RDF(2,9,3)=11
+24 SET RDF(2,10,1)="Days Supply"
SET RDF(2,10,2)="NM"
SET RDF(2,10,3)=5
+25 SET RDF(2,11,1)="Refills Remaining"
SET RDF(2,11,2)="NM"
SET RDF(2,11,3)=5
+26 SET RDF(2,12,1)="Provider"
SET RDF(2,12,2)="XCN"
SET RDF(2,12,3)=150
+27 SET RDF(2,13,1)="Placer Order Number"
SET RDF(2,13,2)="ST"
SET RDF(2,13,3)=30
+28 SET RDF(2,14,1)="Mail/Window"
SET RDF(2,14,2)="ST"
SET RDF(2,14,3)=10
+29 SET RDF(2,15,1)="Division"
SET RDF(2,15,2)="NM"
SET RDF(2,15,3)=50
+30 SET RDF(2,16,1)="Division Name"
SET RDF(2,16,2)="ST"
SET RDF(2,16,3)=50
+31 SET RDF(2,17,1)="MHV Request Status"
SET RDF(2,17,2)="NM"
SET RDF(2,17,3)=5
+32 SET RDF(2,18,1)="MHV Request Status Date"
SET RDF(2,18,2)="TS"
SET RDF(2,18,3)=26
+33 SET RDF(2,19,1)="Remarks"
SET RDF(2,19,2)="ST"
SET RDF(2,19,3)=1024
+34 SET RDF(2,20,1)="Source"
SET RDF(2,20,2)="ST"
SET RDF(2,20,3)=2
+35 SET RDF(2,21,1)="NDC"
SET RDF(2,21,2)="ST"
SET RDF(2,21,3)=15
+36 SET RDF(2,22,1)="Dispensed Date"
SET RDF(2,22,2)="TS"
SET RDF(2,22,3)=26
+37 SET RDF(2,23,1)="Trade Name"
SET RDF(2,23,2)="ST"
SET RDF(2,23,3)=30
+38 SET RDF(2,24,1)="Reason"
SET RDF(2,24,2)="ST"
SET RDF(2,24,3)=100
+39 SET RDF(2,25,1)="Reason Comment"
SET RDF(2,25,2)="st"
SET RDF(2,25,3)=1024
+40 SET RDF(2,26,1)="Cancel Date"
SET RDF(2,26,2)="TS"
SET RDF(2,26,3)=26
+41 SET RDF(2,27,1)="Facility Site Number"
SET RDF(2,27,2)="ST"
SET RDF(2,27,3)=50
+42 SET RDF(2,28,1)="Facility Name"
SET RDF(2,28,2)="ST"
SET RDF(2,28,3)=50
+43 SET RDF(2,29,1)="Facility Address Line 1"
SET RDF(2,29,2)="ST"
SET RDF(2,29,3)=100
+44 SET RDF(2,30,1)="Facility City"
SET RDF(2,30,2)="ST"
SET RDF(2,30,3)=60
+45 SET RDF(2,31,1)="Facility State"
SET RDF(2,31,2)="ST"
SET RDF(2,31,3)=10
+46 SET RDF(2,32,1)="Facility Zip"
SET RDF(2,32,2)="ST"
SET RDF(2,32,3)=10
+47 SET RDF(2,33,1)="Facility Phone Number"
SET RDF(2,33,2)="NM"
SET RDF(2,33,3)=10
+48 SET RDF(2,34,1)="Next Possible Fill Date"
SET RDF(2,34,2)="TS"
SET RDF(2,34,3)=26
+49 SET RDF(2,35,1)="Drug Schedule"
SET RDF(2,35,2)="ST"
SET RDF(2,35,3)=50
+50 SET RDF(2,36,1)="VAMC Tracking Number"
SET RDF(2,36,2)="ST"
SET RDF(2,36,3)=25
+51 SET RDF(2,37,1)="CMOP Tracking Number"
SET RDF(2,37,2)="ST"
SET RDF(2,37,3)=25
+52 SET RDF(2,38,1)="CMOP Date Shipped"
SET RDF(2,38,2)="TS"
SET RDF(2,38,3)=26
+53 SET RDF(2,39,1)="CMOP Carrier"
SET RDF(2,39,2)="ST"
SET RDF(2,39,3)=50
+54 SET RDF(2,40,1)="Carrier Tracking Number"
SET RDF(2,40,2)="ST"
SET RDF(2,40,3)=25
+55 SET RDF(2,41,1)="Number of RX in Package"
SET RDF(2,41,2)="NM"
SET RDF(2,41,3)=5
+56 SET RDF(2,42,1)="CMOP System"
SET RDF(2,42,2)="ST"
SET RDF(2,42,3)=50
+57 SET RDF(2,43,1)="CMOP Status"
SET RDF(2,43,2)="ST"
SET RDF(2,43,3)=50
+58 SET RDF(2,44,1)="CMOP RX Indicator"
SET RDF(2,44,2)="ST"
SET RDF(2,44,3)=5
+59 SET RDF(2,45,1)="CMOP NDC Received"
SET RDF(2,45,2)="ST"
SET RDF(2,45,3)=15
+60 SET RDF(2,46,1)="CMOP NDC Sent"
SET RDF(2,46,2)="ST"
SET RDF(2,46,3)=15
+61 SET RDF(2,47,1)="Orderable Item"
SET RDF(2,47,2)="ST"
SET RDF(2,47,3)=30
+62 SET RDF(2,48,1)="Administered At Clinic"
SET RDF(2,48,2)="NM"
SET RDF(2,48,3)=10
+63 SET RDF(2,49,1)="Clinic/Hospital Location"
SET RDF(2,49,2)="TX"
SET RDF(2,49,3)=100
+64 SET RDF(2,50,1)="SIG"
SET RDF(2,50,2)="TX"
SET RDF(2,50,3)=1024
+65 SET RDF(2,51,1)="UNIQUE INDEX"
SET RDF(2,51,2)="TX"
SET RDF(2,51,3)=10
+66 SET RDF(2,52,1)="DISCLAIMER"
SET RDF(2,52,2)="TX"
SET RDF(2,52,3)=1024
+67 ;
+68 SET CNT=CNT+1
+69 SET @MSGROOT@(CNT)=$$BLDSEG^MHV7U(.RDF,.HL)
+70 SET LEN=LEN+$LENGTH(@MSGROOT@(CNT))
+71 QUIT
+72 ;
RDT(MSGROOT,DATAROOT,CNT,LEN,HL) ; Build RDT segments for Rx Profile data
+1 ;
+2 ; Walks data in DATAROOT to populate MSGROOT with RDT segments
+3 ; sequentially numbered starting at CNT
+4 ;
+5 ; Integration Agreements:
+6 ; 10103 : FMTHL7^XLFDT
+7 ; 3065 : HLNAME^XLFNAME
+8 ;
+9 ; Input:
+10 ; MSGROOT - Root of array holding the message
+11 ; DATAROOT - Root of array to hold extract data
+12 ; CNT - Current message line counter
+13 ; LEN - Current message length
+14 ; HL - HL7 package array variable
+15 ;
+16 ; Output:
+17 ; - Populated message array
+18 ; - Updated LEN and CNT
+19 ;
+20 NEW I,CMP,DIV,RX,CMOP,RXP,RXN,RXN1,RXN2,RXN3,RXN4,RXD,RDT,SIG,SEG,PIEN,NAME,WPLEN,PHRM,RTXT,STXT,TXT,DTXT,REM,DISC
+21 DO LOG^MHVUL2("MHV7B1R","BEGIN RDT","S","TRACE")
+22 FOR I=1:1
if '$DATA(@DATAROOT@(I))
QUIT
Begin DoDot:1
+23 KILL RDT
+24 SET (RTXT,STXT,TXT)=""
+25 SET CMOP=$GET(@DATAROOT@(I,"CMOP"))
+26 SET RX=$GET(@DATAROOT@(I))
+27 SET RXN=$GET(@DATAROOT@(I,"RXN"))
+28 SET RXN1=$GET(@DATAROOT@(I,"RXN1"))
+29 SET RXN2=$GET(@DATAROOT@(I,"RXN2"))
+30 SET RXN3=$GET(@DATAROOT@(I,"RXN3"))
+31 SET RXN4=$GET(@DATAROOT@(I,"RXN4"))
+32 SET PHRM=$GET(@DATAROOT@(I,"PHRM"))
+33 SET RXP=$GET(@DATAROOT@(I,"P"))
+34 SET PIEN=+RXP
+35 SET RXD=$GET(@DATAROOT@(I,"DIV"))
+36 ;K SIG I $D(@DATAROOT@(I,"SIG")) M SIG=@DATAROOT@(I,"SIG")
+37 SET RDT(0)="RDT"
+38 ;Rx Number
SET RDT(1)=$PIECE(RX,"^")
+39 ;Rx IEN
SET RDT(2)=$PIECE(RXN,"^")
+40 ;Drug Name
SET RDT(3)=$$ESCAPE^MHV7U($PIECE(RXN,"^",2),.HL)
+41 ;Issue Date/Time
SET RDT(4)=$$FMTHL7^XLFDT($PIECE(RXN,"^",3))
+42 ;Last Fill Date
SET RDT(5)=$$FMTHL7^XLFDT($PIECE(RXN,"^",4))
+43 ;Release Date/Time
SET RDT(6)=$$FMTHL7^XLFDT($PIECE(RXN,"^",5))
+44 ;Expiration
SET RDT(7)=$$FMTHL7^XLFDT($PIECE(RXN,"^",6))
+45 ;Status
SET RDT(8)=$$ESCAPE^MHV7U($PIECE(RXN1,"^",1),.HL)
+46 ;Quantity
SET RDT(9)=$PIECE(RXN1,"^",2)
+47 ;Days Supply
SET RDT(10)=$PIECE(RXN1,"^",3)
+48 ;Number of Refills
SET RDT(11)=$PIECE(RXN1,"^",4)
+49 IF PIEN
Begin DoDot:2
+50 ;Provider IEN
DO FMTNAME2^MHV7BU(PIEN,200,.NAME,.HL,"XCN")
+51 MERGE RDT(12,1)=NAME
+52 SET RDT(12,1,1)=PIEN
End DoDot:2
+53 ;Placer Order Number
SET RDT(13)=$$ESCAPE^MHV7U($PIECE(RXN1,"^",5),.HL)
+54 ;Mail/Window
SET RDT(14)=$PIECE(RXN1,"^",6)
+55 ;Division
SET RDT(15)=$PIECE(RXD,"^")
+56 ;Division Name
SET RDT(16)=$$ESCAPE^MHV7U($PIECE(RXD,"^",2),.HL)
+57 ;MHV status
SET RDT(17)=$PIECE(RX,"^",3)
+58 ;MHV status date
SET RDT(18)=$$FMTHL7^XLFDT($PIECE(RX,"^",4))
+59 SET RTXT=$$RMK("RMK")
+60 ;Remarks
SET TXT=$$ESCAPE($EXTRACT(RTXT,1,1024),.HL)
+61 SET RDT(19)=$$SPACES(TXT)
+62 ;Source
SET RDT(20)=$PIECE(RXN2,"^",1)
+63 ;NDC
SET RDT(21)=$PIECE(RXN2,"^",2)
+64 ;Dispense Date
SET RDT(22)=$$FMTHL7^XLFDT($PIECE(RXN2,"^",3))
+65 ;Trade Name
SET RDT(23)=$PIECE(RXN,"^",8)
+66 ;Reason for Auto DC'ed: Rx Discontinued by EHRM Data Migration. - Activity log.
SET RDT(24)=$PIECE(RXN2,"^",4)
+67 ;Auto DC'ed: Rx Discontinued by EHRM Data Migration.
SET RDT(25)=$PIECE(RXN2,"^",5)
+68 ;Cancel Date
SET RDT(26)=$$FMTHL7^XLFDT($PIECE(RXN2,"^",6))
+69 ;Site Number
SET RDT(27)=$PIECE(PHRM,"^",8)
+70 ;Facility Name
SET RDT(28)=$PIECE(PHRM,"^",2)
+71 ;Facility Address Line1
SET RDT(29)=$PIECE(PHRM,"^",3)
+72 ;Facility City
SET RDT(30)=$PIECE(PHRM,"^",5)
+73 ;Facility State
SET RDT(31)=$PIECE(PHRM,"^",7)
+74 ;Facility Zip
SET RDT(32)=$PIECE(PHRM,"^",6)
+75 ;Facility Phone
SET RDT(33)=$PIECE(PHRM,"^",4)
+76 ;Refilliable Date
SET RDT(34)=$$FMTHL7^XLFDT($PIECE(RXN3,"^",2))
+77 ;Drug Schedule
SET RDT(35)=$PIECE(RXN3,"^",3)
+78 ;Other Tracking Number pulled from activity log
SET RDT(36)=$PIECE(RXN3,"^",4)
+79 ;CMOP Tracking Number
SET RDT(37)=$PIECE(CMOP,"^",11)
+80 ;CMOP Date Shipped
SET RDT(38)=$$FMTHL7^XLFDT($PIECE(CMOP,"^",9))
+81 ;CMOP Carrier
SET RDT(39)=$PIECE(CMOP,"^",10)
+82 ;Carrier Tracking Number <FUTURE USE>
SET RDT(40)=""
+83 ;Number of RX in Package <FUTURE USE>
SET RDT(41)=""
+84 ;CMOP System <FUTURE USE>
SET RDT(42)=""
+85 ;CMOP Status
SET RDT(43)=$PIECE(CMOP,"^",3)
+86 ;CMOP Rx Indicator
SET RDT(44)=$PIECE(CMOP,"^",2)
+87 ;CMOP NDC Received
SET RDT(45)=$PIECE(CMOP,"^",4)
+88 ;CMOP NDC Sent
SET RDT(46)=$PIECE(CMOP,"^",12)
+89 ;Orderable Item
SET RDT(47)=$PIECE(RXN3,"^",5)
+90 ;Administered at Clinic
SET RDT(48)=$PIECE(RXN3,"^",6)
+91 ;Clinic
SET RDT(49)=$PIECE(RXN3,"^",1)
+92 SET STXT=$$RMK("SIG")
+93 SET TXT=$$ESCAPE($EXTRACT(RTXT,1,1024),.HL)
+94 ;Sig
SET RDT(50)=$$SPACES(STXT)
+95 ;UNIQUE INDEX FOR RF AND PF
SET RDT(51)=$PIECE(RXN1,"^",7)
+96 SET RDT(52)=""
+97 IF RDT(20)="NV"
Begin DoDot:2
+98 ;DISCLAIMER FOR NONVA
SET DISC=$$RMK("DSC")
+99 SET REM=$$RMK("RMK")
+100 SET DTXT=$PIECE(DISC,REM,1)
+101 SET TXT=$$ESCAPE($EXTRACT(DTXT,1,1024),.HL)
+102 SET RDT(52)=$$SPACES(TXT)
End DoDot:2
+103 SET CNT=CNT+1
+104 SET @MSGROOT@(CNT)=$$BLDSEG^MHV7U(.RDT,.HL)
+105 SET LEN=LEN+$LENGTH(@MSGROOT@(CNT))
+106 QUIT
End DoDot:1
+107 DO LOG^MHVUL2("MHV7B1R","END RDT","S","TRACE")
+108 QUIT
+109 ;
RMK(TYP) ; build Remark field
+1 NEW X,Y
+2 SET X=""
SET Y=0
+3 FOR
SET Y=$ORDER(@DATAROOT@(I,TYP,Y))
if 'Y
QUIT
Begin DoDot:1
+4 if $GET(@DATAROOT@(I,TYP,Y,0))=""
QUIT
+5 if X]""
SET X=X_" "
+6 SET X=X_@DATAROOT@(I,TYP,Y,0)
End DoDot:1
+7 QUIT X
+8 ;
SPACES(WPN) ; Remove extra spaces from line of text
+1 NEW OUT,IX,SP
+2 SET OUT=WPN
+3 SET SP=" "
+4 FOR IX=$LENGTH(OUT):-1:1
IF ($EXTRACT(OUT,IX,IX+1)=(SP_SP))
SET $EXTRACT(OUT,IX)=""
+5 QUIT OUT
+6 ;
ESCAPE(VAL,HL) ;Escape any special characters
+1 ;
+2 ; Input:
+3 ; VAL - value to escape
+4 ; HL - HL7 environment array
+5 ;
+6 ; Output:
+7 ; VAL - passed by reference
+8 ;
+9 ;field separator
NEW FS
+10 ;component separator
NEW CS
+11 ;repetition separator
NEW RS
+12 ;escape character
NEW ES
+13 ;sub-component separator
NEW SS
+14 NEW L,STR,I
+15 ;
+16 SET FS=HL("FS")
+17 SET CS=$EXTRACT(HL("ECH"))
+18 SET RS=$EXTRACT(HL("ECH"),2)
+19 SET ES=$EXTRACT(HL("ECH"),3)
+20 SET SS=$EXTRACT(HL("ECH"),4)
+21 ;
+22 IF VAL[ES
Begin DoDot:1
+23 SET L=$LENGTH(VAL,ES)
SET STR=""
+24 FOR I=1:1:L
SET $PIECE(STR," ",I)=$PIECE(VAL,ES,I)
+25 SET VAL=STR
End DoDot:1
+26 IF VAL[FS
Begin DoDot:1
+27 SET L=$LENGTH(VAL,FS)
SET STR=""
+28 FOR I=1:1:L
SET $PIECE(STR," ",I)=$PIECE(VAL,FS,I)
+29 SET VAL=STR
End DoDot:1
+30 IF VAL[RS
Begin DoDot:1
+31 SET L=$LENGTH(VAL,RS)
SET STR=""
+32 FOR I=1:1:L
SET $PIECE(STR," ",I)=$PIECE(VAL,RS,I)
+33 SET VAL=STR
End DoDot:1
+34 IF VAL[CS
Begin DoDot:1
+35 SET L=$LENGTH(VAL,CS)
SET STR=""
+36 FOR I=1:1:L
SET $PIECE(STR," ",I)=$PIECE(VAL,CS,I)
+37 SET VAL=STR
End DoDot:1
+38 IF VAL[SS
Begin DoDot:1
+39 SET L=$LENGTH(VAL,SS)
SET STR=""
+40 FOR I=1:1:L
SET $PIECE(STR," ",I)=$PIECE(VAL,SS,I)
+41 SET VAL=STR
End DoDot:1
+42 QUIT VAL