source: WorldVistAEHR/trunk/r/REGISTRATION-DGQE-DG-DPT-GRPX-VAD-VAF-VAS-VAT-VAU--VA-VIC--DGBT--DGJ--DGYA--VALM/DGPFHLQ.m@ 700

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

initial load of WorldVistAEHR

File size: 6.0 KB
RevLine 
[613]1DGPFHLQ ;ALB/RPM - PRF HL7 QRY/ORF PROCESSING ; 1/23/03
2 ;;5.3;Registration;**425,650**;Aug 13, 1993;Build 3
3 ;
4BLDQRY(DGDFN,DGICN,DGROOT,DGHL) ;Build QRY~R02 Message/Segments
5 ;
6 ; Input:
7 ; DGDFN - (required) Pointer to patient in PATIENT (#2) file
8 ; DGICN - (required) Patient's Integrated Control Number
9 ; DGROOT - (required) Closed root array or global name for segment
10 ; storage.
11 ; DGHL - (required) VistA HL7 environment array
12 ;
13 ; Output:
14 ; Function Value - 1 on success, 0 on failure
15 ; DGROOT - array of HL7 segments on success
16 ;
17 N DGCNT ;segment counter
18 N DGDEM ;pt. demographics array
19 N DGQRD ;formatted QRD segment
20 N DGQRF ;formatted QRF segment
21 N DGRSLT ;function value
22 N DGSTR ;field string
23 ;
24 S DGRSLT=0
25 S DGCNT=0
26 ;
27 I +$G(DGDFN),+$G(DGICN),$G(DGROOT)]"" D
28 . ;
29 . ;get patient demographics
30 . Q:'$$GETPAT^DGPFUT2(DGDFN,.DGDEM)
31 . ;
32 . ;build QRD
33 . S DGSTR="1,2,3,4,7,8,9,10"
34 . S DGQRD=$$QRD^DGPFHLQ1(DGDFN,DGICN,DGSTR,.DGHL)
35 . Q:(DGQRD="")
36 . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=DGQRD
37 . ;
38 . ;build QRF
39 . S DGSTR="1,4,5"
40 . S DGQRF=$$QRF^DGPFHLQ2($G(DGDEM("SSN")),$G(DGDEM("DOB")),DGSTR,.DGHL)
41 . Q:(DGQRF="")
42 . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=DGQRF
43 . ;
44 . S DGRSLT=1
45 Q DGRSLT
46 ;
47BLDORF(DGROOT,DGHL,DGDFN,DGQRY,DGSEGERR,DGQRYERR) ;Build ORF~R04 Message/Segments
48 ;
49 ; Input:
50 ; DGROOT - (required) Segment array
51 ; DGHL - (required) HL7 environment array
52 ; DGDFN - (required) Pointer to patient in PATIENT (#2) file
53 ; DGQRY - (required) Array of parsed QRY data
54 ; DGSEGERR - (optional) Array of errors encountered during QRY parsing
55 ; DGQRYERR - (optional) Error encountered during ICN to DFN conversion
56 ;
57 ; Output:
58 ; Function Value - 1 on success, 0 on failure
59 ;
60 N DGACK ;acknowledgment code (i.e. AA, AE)
61 N DGAIENS ;array of assignment IENS
62 N DGCNT ;segment counter
63 N DGI ;generic index
64 N DGOBROOT ;temporary storage of OBR/OBX segments
65 N DGRSLT ;function value
66 N DGSEGSTR ;formatted segment string
67 N DGSTR ;comma-delimited list of fields to include
68 ;
69 S DGRSLT=0
70 S DGOBROOT=$NA(^TMP("DGPF OB",$J))
71 K @DGOBROOT
72 ;
73 I $G(DGROOT)]"",$D(DGQRY) D
74 . S DGCNT=0
75 . S DGACK=$S($D(DGSEGERR):"AE",$D(DGQRYERR):"AE",1:"AA")
76 . ;
77 . ;build OBR/OBX segments for any Category I record flag assignments
78 . I DGACK="AA",$$GETALL^DGPFAA($G(DGDFN),.DGAIENS,"",1) D
79 . . ;
80 . . ;build and temporarily store OBR/OBX segments
81 . . Q:$$BLDALLOB(DGOBROOT,.DGAIENS,.DGHL)
82 . . ;
83 . . ;if we get here then the data retrieval failed
84 . . S DGQRYERR=261130 ;unable to retrieve existing assignments
85 . . S DGACK="AE"
86 . . K @DGOBROOT
87 . ;
88 . ;build MSA segment
89 . S DGSTR=$S($D(DGQRYERR):"1,2,6",1:"1,2")
90 . S DGSEGSTR=$$MSA^DGPFHLU3(DGACK,DGHL("MID"),.DGQRYERR,DGSTR,.DGHL)
91 . Q:(DGSEGSTR="")
92 . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=DGSEGSTR
93 . ;
94 . ;build ERR segments for any segment parsing errors
95 . I $D(DGSEGERR),'$$BLDERR^DGPFHLU4(DGROOT,.DGSEGERR,.DGHL,.DGCNT) Q
96 . ;
97 . ;build QRD segment
98 . S DGSTR="1,2,3,4,7,8,9,10"
99 . S DGSEGSTR=$$QRD^DGPFHLQ1($G(DGQRY("QID")),$G(DGQRY("ICN")),DGSTR,.DGHL)
100 . Q:(DGSEGSTR="")
101 . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=DGSEGSTR
102 . ;
103 . ;move any OBR/OBX segments into the message
104 . S DGI=0
105 . F S DGI=$O(@DGOBROOT@(DGI)) Q:'DGI D
106 . . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=@DGOBROOT@(DGI)
107 . ;
108 . ;success
109 . S DGRSLT=1
110 ;
111 ;cleanup
112 K @DGOBROOT
113 ;
114 Q DGRSLT
115 ;
116BLDALLOB(DGROOT,DGAIENS,DGHL) ;build all OBRs and OBXs for a patient
117 ;
118 ; Input:
119 ; DGROOT - (required) Closed root array or global name for segment
120 ; storage.
121 ; DGAIENS - (required) Array of pointers to PRF ASSIGNMENT (#26.13) file
122 ; DGHL - (required) VistA HL7 environment array
123 ;
124 ; Output:
125 ; Function Value - 1 on success, 0 on failure
126 ; DGROOT - array of HL7 segments on success
127 ;
128 N DGAIEN ;single assignment IEN
129 N DGCNT ;segment counter
130 N DGHIEN ;single assignment history IEN
131 N DGHIENS ;array of assignment history IENs
132 N DGOBRSET ;OBR segment Set ID
133 N DGOBXOK ;OBX segment creation flag
134 N DGOBXSET ;OBX segment Set ID
135 N DGPFA ;assignment data array
136 N DGPFAH ;assignment history data array
137 N DGRSLT ;function value
138 N DGSEGSTR ;formatted segment string
139 N DGSTR ;comma-delimited list of fields to include
140 N DGTROOT ;closed root name of text array value
141 ;
142 S DGCNT=0
143 S DGRSLT=0
144 I $G(DGROOT)]"",$D(DGAIENS) D
145 . S DGAIEN=0
146 . S DGOBRSET=0
147 . F S DGAIEN=$O(DGAIENS(DGAIEN)) Q:'DGAIEN D
148 . . N DGHIENS ;array of assignment history IENS
149 . . N DGPFA ;assignment data array
150 . . ;
151 . . ;get assignment details
152 . . Q:'$$GETASGN^DGPFAA(DGAIEN,.DGPFA)
153 . . ;
154 . . ;get last assignment history for narrative observation date
155 . . Q:'$$GETHIST^DGPFAAH($$GETLAST^DGPFAAH(DGAIEN),.DGPFAH)
156 . . ;
157 . . ;build OBR segment for this assignment
158 . . S DGSTR="1,4,7,20,21"
159 . . S DGOBRSET=DGOBRSET+1
160 . . S DGSEGSTR=$$OBR^DGPFHLU1(DGOBRSET,.DGPFA,.DGPFAH,DGSTR,.DGHL)
161 . . Q:(DGSEGSTR="")
162 . . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=DGSEGSTR
163 . . ;
164 . . ;build narrative OBX segment for this assignment
165 . . S DGOBXSET=0
166 . . S DGTROOT="DGPFA(""NARR"")"
167 . . Q:'$$BLDOBXTX^DGPFHLU2(DGROOT,DGTROOT,"N",.DGPFAH,.DGHL,.DGCNT,.DGOBXSET)
168 . . ;
169 . . ;get a list of all assignment histories
170 . . Q:'$$GETALL^DGPFAAH(DGAIEN,.DGHIENS)
171 . . ;
172 . . ;loop through each assignment history entry
173 . . S DGHIEN=0
174 . . F S DGHIEN=$O(DGHIENS(DGHIEN)) Q:'DGHIEN D Q:'DGOBXOK
175 . . . N DGPFAH
176 . . . S DGOBXOK=0
177 . . . ;
178 . . . ;get single assignment history record
179 . . . Q:'$$GETHIST^DGPFAAH(DGHIEN,.DGPFAH)
180 . . . ;
181 . . . ;build status OBX segment for this history record
182 . . . S DGSTR="1,2,3,5,11,14"
183 . . . S DGOBXSET=DGOBXSET+1
184 . . . S DGSEGSTR=$$OBX^DGPFHLU2(DGOBXSET,"S","",$P($G(DGPFAH("ACTION")),U,2),.DGPFAH,DGSTR,.DGHL)
185 . . . Q:(DGSEGSTR="")
186 . . . S DGCNT=DGCNT+1,@DGROOT@(DGCNT)=DGSEGSTR
187 . . . ;
188 . . . ;build review comment OBX segments for this history record
189 . . . S DGTROOT="DGPFAH(""COMMENT"")"
190 . . . Q:'$$BLDOBXTX^DGPFHLU2(DGROOT,DGTROOT,"C",.DGPFAH,.DGHL,.DGCNT,.DGOBXSET)
191 . . . S DGOBXOK=1
192 . . Q:'DGOBXOK
193 . . S DGRSLT=1
194 Q DGRSLT
Note: See TracBrowser for help on using the repository browser.