source: FOIAVistA/tag/r/SCHEDULING-SD-SC/SDRPA07.m@ 1334

Last change on this file since 1334 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 8.0 KB
Line 
1SDRPA07 ;BP-OIFO/ESW - APPOINTMENT BATCH TRANSMISSION BUILDER; ; 9/14/04 9:20am ; Compiled April 24, 2006 17:00:51
2 ;;5.3;Scheduling;**290,333,349,376,446**;AUG 13 1993;Build 77
3 ;
4 ;
5SNDS19(ZTSK,SDBCID,SDMCID) ;Main entry point for the sending of SIU-S19 batch messages to
6 ; the National Patient Care Database
7 ;
8 ;Input : ZTSK
9 ;Output : SDBCID - Batch Control ID
10 ; SDMCID - Message Control ID
11 ;
12 ;
13 ;Declare variables
14 N X,X1,X2,%H
15 N BATCHC,MSGN,CURLINE
16 N LINEN,MSHLINE,XMITERR,HL7XMIT,ERROR,ORIGENT,ORIGMNT
17 N HLEID,HL,HLECH,HLFS,HLQ,HLMID,HLMTIEN,HLDT,HLDT1,MSGID,HLRESLT,HLP
18 ;Set message count limit for batch message
19 ;Initialize global locations
20 S XMITERR="^TMP(""SD-PAIT-BLD"","_$J_",""ERRORS"")"
21 S HL7XMIT="^TMP(""HLS"","_$J_")"
22 K @XMITERR,@HL7XMIT
23 ;Initiate
24 D INIT^HLFNC2("SD-PAIT-EVENT",.HL)
25 ;Unable to initiate HL7 variable - send error bulletin - done
26 ;I ($O(HL(""))="") D ERRBUL($P(HL,U,2)) Q ; create ERRBUL later
27 ;Create batch message
28 D CREATE^HLTF(.HLMID,.HLMTIEN,.HLDT,.HLDT1)
29 ;HLMID - value of batch ID
30 ;HLMTIEN - IEN of Message Text file entry
31 ;HLDT - current date/time in FM internal format
32 ;HLDT1 - current date/time in HL7 format
33 N SDA,SDDT S SDA=HLMID,SDDT=HLDT ; to be used to file later
34 ;Unable to create batch message - send error bulletin - done
35 ;I ('HLMTIEN) D ERRBUL("Unable to create batch HL7 message") Q
36 ;Initialize message count
37 S BATCHC=0
38 ;Initialize message number
39 S MSGN=0
40 ;Initialize line count
41 S LINEN=1
42 S CURLINE=LINEN
43 ;Loop through list of appointments requiring transmission
44 N RUNID S RUNID=$O(^SDWL(409.6,"AD",ZTSK,""))
45 N DFN,SD25,SD6,SD8,SD7,SDPATCL S DFN="" F S DFN=$O(^TMP("SDDPT",$J,DFN)) Q:DFN="" D
46 .N SDP,ICN,SSN,SNM,FNM,MNM,DOB,SDSC,SDSCP,SDENRO,SDAPPT S SDP=^TMP("SDDPT",$J,DFN)
47 .S ICN=$P(SDP,U),SSN=$P(SDP,U,2),SNM=$P(SDP,U,3),FNM=$P(SDP,U,4)
48 .S MNM=$P(SDP,U,5),DOB=$P(SDP,U,6),SDSC=$P(SDP,U,7),SDSCP=$P(SDP,U,8),SDENRO=$P(SDP,U,9)
49 .N SDADT S SDADT="" F S SDADT=$O(^TMP("SDDPT",$J,DFN,SDADT)) Q:SDADT="" D
50 ..N SDPT,SDCDATE,SDADID,SDSDDT,SDSTAT,SDNAVA,SDCHKOUT,SDCDT,SDARF,SDARDT,SDNEW,SDCL,SDCLNUM,SDSTOP,SDCSTOP,SDFAC,SDDAM,SDCLNM,SDSTOPD,SDCSTOPD
51 ..N SDSTOPDD,SD8RD
52 ..S SDPT=^TMP("SDDPT",$J,DFN,SDADT),SDADID=$P(SDPT,U),SDDAM=$P(SDPT,U,2),SDSDDT=$P(SDPT,U,3),SDNAVA=$P(SDPT,U,5)
53 ..S SDCHKOUT=$P(SDPT,U,6),SDCDT=$P(SDPT,U,7),SDARDT=$P(SDPT,U,9),SDNEW=$P(SDPT,U,10),SDCL=$P(SDPT,U,12),SDCLNM=$P(SDPT,U,13)
54 ..S SDSTOP=$P(SDPT,U,14),SDCSTOP=$P(SDPT,U,15),SDFAC=$P(SDPT,U,16),SDPATCL=$P(SDPT,U,4)
55 ..S SDAPPT=^TMP("SDDPT",$J,DFN,SDADT,"SCH"),SD25=$P(SDAPPT,"^",2),SD6=$P(SDAPPT,"^",3),SD8=$P(SDAPPT,"^",4),SD8RD=$P(SDAPPT,"^",7)
56 ..S SDSTOPDD=^TMP("SDDPT",$J,DFN,SDADT,"STDC"),SDSTOPD=$P(SDSTOPDD,"^"),SDCSTOPD=$P(SDSTOPDD,"^",2)
57 ..;calculate consult date if applicable; 446
58 ..N SEQ S SEQ=0,SDCDATE="" F S SEQ=$O(^SC(SDCL,"S",SDADT,1,SEQ)) Q:+SEQ'=SEQ I $P(^SC(SDCL,"S",SDADT,1,SEQ,0),"^")=DFN D Q
59 ...S SDCSLT=$$GET1^DIQ(44.003,SEQ_","_SDADT_","_SDCL_",",688,"I") ; consult
60 ...Q:SDCSLT=""
61 ...I $D(^GMR(123,SDCSLT)) S SDCDATE=$$DTCONV^SDRPA08($$GET1^DIQ(123,SDCSLT_",",3,"I")) ;date converted to HL7
62 ..;Calculate message control ID
63 ..S MSGN=MSGN+1
64 ..S MSGID=HLMID_"-"_MSGN
65 ..;Build MSG segment
66 ..I (MSGID'="") D
67 ...;remember orig message and event type
68 ...S ORIGMNT="SIU"
69 ...S ORIGENT="S12"
70 ...S HL("MNT")="SIU",HL("ETN")=$P(SDAPPT,"^")
71 ...;build MSH segment
72 ...K RESULT D MSH^HLFNC2(.HL,MSGID,.RESULT)
73 ...;reset message & event type to its orig values
74 ...S HL("MNT")=ORIGMNT
75 ...S HL("ETN")=ORIGENT
76 ...;copy MSH segment into HL7 message
77 ...S @HL7XMIT@(CURLINE)=RESULT
78 ...N SDFACL S SDFACL=$P($$SITE^VASITE(),"^",3)
79 ...S $P(@HL7XMIT@(CURLINE),U,4)=SDFACL ;sending facility station #
80 ...S $P(@HL7XMIT@(CURLINE),U,5)="SD-AAC-PAIT" ;Receiving Application
81 ...S $P(@HL7XMIT@(CURLINE),U,6)=200 ; Receiving Facility
82 ...I ($D(RESULT(1))) D
83 ....S @HL7XMIT@(CURLINE,1)=RESULT(1)
84 ....S CURLINE=CURLINE+1
85 ...E S CURLINE=CURLINE+1
86 ..;get list of segments
87 ..N SDSCH S SDSCH="SCH"_HLFS_1_"^^^^^"
88 ..S SD7=SDNAVA
89 ..;S ^TMP("HLS",$J,CURLINE)
90 ..S @HL7XMIT@(CURLINE)=SDSCH_SD6_"^"_SD7_"^"_SD8_"^^^"
91 ..N SDDAT S SDDAT="~~~"_SDDAM_"~~~"_"Date Appt Created|~~~"_SDSDDT_"~~~"_"Desired Date|~~~"_SDADID_"~~~"_"Appt Date"
92 ..S SDDAT=SDDAT_"|~~~"_SDCHKOUT_"~~~"_"Checkout Date"
93 ..S SDDAT=SDDAT_"|~~~"_SDCDT_"~~~"_"Cancellation Date"
94 ..S SDDAT=SDDAT_"|~~~"_SDARDT_"~~~"_"Auto-rebook Date"
95 ..S SDDAT=SDDAT_"|~~~"_SD8RD_"~~~"_"Resched Date"
96 ..S SDDAT=SDDAT_"|~~~"_SDCDATE_"~~~"_"Consult Date"
97 ..;S $P(SDSCH,U,12)=SDDAT,$P(SDSCH,U,26)=SDSTAT
98 ..S @HL7XMIT@(CURLINE,1)=SDDAT_"^^^^^^^^^^^^^^"_SD25
99 ..S CURLINE=CURLINE+1
100 ..S @HL7XMIT@(CURLINE)=$$EN^VAFHLPID(DFN,"1,3,5,7,11,19",1,1)
101 ..N SDCDFN S SDCDFN=$P(@HL7XMIT@(CURLINE),"^",4),SDCDFN=SDCDFN_"|"_DFN_"~~~USVHA&&L~PI" I $P(SDCDFN,"~")["V" S $P(SDCDFN,"~",2)=""
102 ..S $P(@HL7XMIT@(CURLINE),"^",4)=SDCDFN
103 ..N SDZIP S SDZIP=$P(@HL7XMIT@(CURLINE),U,12),SDZIP=$P(SDZIP,"~",5) S $P(@HL7XMIT@(CURLINE),U,12)="~~~~"_SDZIP
104 ..S CURLINE=CURLINE+1
105 ..;get Admission Type
106 ..N SDCR1,SDAT,SDCR S SDCR1=$E(SDDAM,5,8)_$E(SDDAM,1,4) D DT^DILF(,SDCR1,.SDCR) S SDAT=$$POV^SDRPA20(DFN,SDADT,SDCL,SDCR)
107 ..S @HL7XMIT@(CURLINE)="PV1^1^"_SDPATCL_"^^"_SDAT_"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"_SDFAC
108 ..S CURLINE=CURLINE+1
109 ..S SDNEW=$S(SDNEW=1:"NSF",SDNEW=2:"OPN",SDNEW=3:"SHB")
110 ..S @HL7XMIT@(CURLINE)="PV2^^^^^^^^^^^^^^^^^^^^^^^^"_SDNEW
111 ..S CURLINE=CURLINE+1
112 ..I $D(^TMP("SDDPT",$J,DFN,SDADT,"ROL")) D
113 ...N SDCNT,SDAIP S SDAIP="AIP^" S SDCNT="" F S SDCNT=$O(^TMP("SDDPT",$J,DFN,SDADT,"ROL",SDCNT)) Q:SDCNT="" D
114 ....N SDPOVID,SDPROVNM,SDROLS
115 ....S SDROLS=^TMP("SDDPT",$J,DFN,SDADT,"ROL",SDCNT)
116 ....S SDPOVID=$P(SDROLS,U,3),SDPROVNM=$P(SDROLS,U,4),SDPROVNM=$TR(SDPROVNM,",","~")
117 ....S SDPROVNM=$TR(SDPROVNM," ","~")
118 ....I $L(SDPROVNM,"~")=2 S SDPROVNM=SDPROVNM_"~~"
119 ....E I $L(SDPROVNM,"~")=3 S SDPROVNM=SDPROVNM_"~"
120 ....S @HL7XMIT@(CURLINE)=SDAIP_SDCNT_"^^"_SDPOVID_"~"_SDPROVNM_"^"_"Provider"
121 ....S CURLINE=CURLINE+1
122 ..S @HL7XMIT@(CURLINE)="AIL^1^^"_SDCL_"~~~~~~~~"_SDCLNM_"^"_SDSTOP_"~"_SDSTOPD_"~DSS Clinic ID^"_SDCSTOP_"~"_SDCSTOPD_"~DSS Credit Stop"
123 ..S CURLINE=CURLINE+1
124 ..N SDCNT S SDCNT="" F S SDCNT=$O(^TMP("SDDPT",$J,DFN,SDADT,"ZCL",SDCNT)) Q:SDCNT="" D
125 ...S @HL7XMIT@(CURLINE)=^TMP("SDDPT",$J,DFN,SDADT,"ZCL",SDCNT,0)
126 ...S CURLINE=CURLINE+1
127 ..;create ZEN only if enrollment was retrieved
128 ..I SDENRO>0 S @HL7XMIT@(CURLINE)="ZEN^1^^^^^^^^"_SDENRO,CURLINE=CURLINE+1
129 ..S @HL7XMIT@(CURLINE)="ZSP^1^"_SDSC_"^"_SDSCP
130 ..S CURLINE=CURLINE+1
131 ..;ZEL
132 ..N SDZEL D EN1^VAFHLZEL(DFN,"1,37,38",1,.SDZEL) D
133 ...;need to modify 37 WITH THE CREATION DATE
134 ...N SDDAMV S SDDAMV=$$HL7TFM^XLFDT(SDDAM)
135 ...N SDVC S SDVC=$$CVEDT^DGCV(DFN,SDDAMV),SDVC=$P(SDVC,"^",3) D
136 ....S $P(SDZEL(1),"^",38)=$S(SDVC=1:1,SDVC=0:0,1:"U")
137 ....I $P(SDZEL(1),"^",39)'?8N S $P(SDZEL(1),"^",39)=""
138 ...S @HL7XMIT@(CURLINE)=SDZEL(1)
139 ..S CURLINE=CURLINE+1
140 ..;ZMH
141 ..N SAR D ENTER^VAFHLZMH(DFN,"SAR","1,5,10","3,4",HL("FS"),HL("ECH"),"")
142 ..S $P(SAR(1,0),"^",4)="" ;
143 ..;service separation date
144 ..;combat indication and location;gulf war indication
145 ..S $P(SAR(1,0),"^",5)="~"_$P($P(SAR(1,0),"^",5),"~",2)
146 ..N SS F SS=2,3 D
147 ...S $P(SAR(SS,0),"^",5)=""
148 ..I $E($P(SAR(2,0),"^",4))'="Y" S $P(SAR(2,0),"^",4)="N~"
149 ..I $E($P(SAR(3,0),"^",4))'="Y" S $P(SAR(3,0),"^",4)="N"
150 ..N SDD F SDD=1,2,3 S @HL7XMIT@(CURLINE)=SAR(SDD,0) S CURLINE=CURLINE+1
151 ..;file MSGID into 409.69 separately as batch # and ID #
152 ..N DIE,DA D
153 ...S DIE="^SDWL(409.6,"_RUNID_",1,",DA(1)=RUNID
154 ...S DA=$O(^SDWL(409.6,"AC",DFN,SDADT,RUNID,"")) D
155 ....I $P(^SDWL(409.6,RUNID,1,DA,0),"^",3)'="" S DA=$O(^SDWL(409.6,"AC",DFN,SDADT,RUNID,DA))
156 ...S DR="2///"_+MSGID_";3///"_$P(MSGID,"-",2) D ^DIE
157 D GENERATE^HLMA("SD-PAIT-EVENT","GB",1,.HLRESLT,HLMTIEN,.HLP) K @HL7XMIT
158 N DA,DIE,DR S DA=RUNID,DIE=409.6,DR="1.1///"_+$G(MSGID) D ^DIE
159 S SDMCID=+$G(SDMCID)
160 ;file message control ID # and batch control ID number
161 N DIC,DA,X,Y D
162 .S DIC="^SDWL(409.6,"_RUNID_",2,",DA(1)=RUNID,DIC("P")=409.7,DIC(0)="X"
163 .S SDBCID=+$G(HLRESLT)
164 .K DO S X=+$G(SDBCID) D FILE^DICN
165 .S DA=+Y,DIE=DIC,DR=".02///"_+$G(SDDT)_";.03///"_+$G(SDA) D ^DIE
166 Q
Note: See TracBrowser for help on using the repository browser.