1 | #!/bin/bash
|
---|
2 |
|
---|
3 | #there are many reads and comments in this document for debugging
|
---|
4 | #This scipt requires a provider organization file for each provider to be in the directory, and AllM1EncounterCodes.txt,
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 | #cat PAT_100146_QRDA_V1_0_0.xml|grep SSN
|
---|
9 | #Find out which files to edit and assign them to the variable "MyFile". As you can see, here I loop through particular files in the same directory with this script
|
---|
10 |
|
---|
11 | for MyFile in $(ls /home/nancy/CCR-Template/M1-*0.xml)
|
---|
12 | do
|
---|
13 |
|
---|
14 | #cp $MyFile $MyFile"BU"
|
---|
15 | #Replace where is just says SSN for the patient with the SSN ID HL7 number
|
---|
16 | #since this is a medicare patient, no privacy violation as that will also appear in the Payer's section
|
---|
17 |
|
---|
18 | echo "xml files are in the directory"
|
---|
19 | read
|
---|
20 |
|
---|
21 | #replace the @@@UUID-DOC@@@,@@@UUID-SET@@@ and @@@UUID-PAYER@@@ with UUIDs
|
---|
22 | #should probably do that in the problem section as well with WV HL7 ID as root and UUID as an extension for now
|
---|
23 |
|
---|
24 | VerNum=$(grep versionNumber "$MyFile"|awk -F\" '{print $2}')
|
---|
25 | echo "$VerNum"
|
---|
26 |
|
---|
27 | if [ "1" = "$VerNum" ]
|
---|
28 | then
|
---|
29 | #uuid is a Linux command that generates a new uuid
|
---|
30 | u=$(uuid)
|
---|
31 | sed -i s/'@@@UUID-DOC@@@'/$u/ $MyFile
|
---|
32 |
|
---|
33 | sed -i s/'@@@UUID-SET@@@'/$u/ $MyFile
|
---|
34 | sed -i s/'@@@UUID-PAYER@@@'/$u/ $MyFile
|
---|
35 |
|
---|
36 | else
|
---|
37 | echo "UUIDs should remain unchanged because this is not the first version of this document"
|
---|
38 |
|
---|
39 | fi
|
---|
40 | echo "replace UUID site markers"
|
---|
41 | u=""
|
---|
42 | VerNum=""
|
---|
43 | read
|
---|
44 |
|
---|
45 |
|
---|
46 | #make sure <state></state> is no longer than two
|
---|
47 |
|
---|
48 | echo "Fix the state line length"
|
---|
49 |
|
---|
50 | sed -i 's/Alabama/AL/gI' $MyFile
|
---|
51 | sed -i 's/Alaska/AK/gI' $MyFile
|
---|
52 | sed -i 's/Arizona/AZ/gI' $MyFile
|
---|
53 | sed -i 's/Arkansas/AR/gI' $MyFile
|
---|
54 | sed -i 's/California/CA/gI' $MyFile
|
---|
55 | sed -i 's/Colorado/CO/gI' $MyFile
|
---|
56 | sed -i 's/Connecticut/CT/gI' $MyFile
|
---|
57 | sed -i 's/Delaware/DE/gI' $MyFile
|
---|
58 | sed -i 's/District of Columbia/DC/gI' $MyFile
|
---|
59 | sed -i 's/Florida/FL/gI' $MyFile
|
---|
60 | sed -i 's/Georgia/GA/gI' $MyFile
|
---|
61 | sed -i 's/Hawaii/HI/gI' $MyFile
|
---|
62 | sed -i 's/Idaho/ID/gI' $MyFile
|
---|
63 | sed -i 's/Illinois/IL/gI' $MyFile
|
---|
64 | sed -i 's/Indiana/IN/gI' $MyFile
|
---|
65 | sed -i 's/Iowa/IA/gI' $MyFile
|
---|
66 | sed -i 's/Kansas/KS/gI' $MyFile
|
---|
67 | sed -i 's/Kentucky/KY/gI' $MyFile
|
---|
68 | sed -i 's/Louisiana/LA/gI' $MyFile
|
---|
69 | sed -i 's/Maine/ME/gI' $MyFile
|
---|
70 | sed -i 's/Maryland/MD/gI' $MyFile
|
---|
71 | sed -i 's/Massachusetts/MA/gI' $MyFile
|
---|
72 | sed -i 's/Michigan/MI/gI' $MyFile
|
---|
73 | sed -i 's/Minnesota/MN/gI' $MyFile
|
---|
74 | sed -i 's/Mississippi/MS/gI' $MyFile
|
---|
75 | sed -i 's/Missouri/MO/gI' $MyFile
|
---|
76 | sed -i 's/Montana/MT/gI' $MyFile
|
---|
77 | sed -i 's/Nebraska/NE/gI' $MyFile
|
---|
78 | sed -i 's/Nevada/NV/gI' $MyFile
|
---|
79 | sed -i 's/New Hampshire/NH/gI' $MyFile
|
---|
80 | sed -i 's/New Jersey/NJ/gI' $MyFile
|
---|
81 | sed -i 's/New Mexico/NM/gI' $MyFile
|
---|
82 | sed -i 's/New York/NY/gI' $MyFile
|
---|
83 | sed -i 's/North Carolina/NC/gI' $MyFile
|
---|
84 | sed -i 's/North Dakota/ND/gI' $MyFile
|
---|
85 | sed -i 's/Ohio/OH/gI' $MyFile
|
---|
86 | sed -i 's/Oklahoma/OK/gI' $MyFile
|
---|
87 | sed -i 's/Oregon/OR/gI' $MyFile
|
---|
88 | sed -i 's/Pennsylvania/PA/gI' $MyFile
|
---|
89 | sed -i 's/Rhode Island/RI/gI' $MyFile
|
---|
90 | sed -i 's/South Carolina/SC/gI' $MyFile
|
---|
91 | sed -i 's/South Dakota/SD/gI' $MyFile
|
---|
92 | sed -i 's/Tennessee/TN/gI' $MyFile
|
---|
93 | sed -i 's/Texas/TX/gI' $MyFile
|
---|
94 | sed -i 's/Utah/UT/gI' $MyFile
|
---|
95 | sed -i 's/Vermont/VT/gI' $MyFile
|
---|
96 | sed -i 's/Virginia/VA/gI' $MyFile
|
---|
97 | sed -i 's/Washington/WA/gI' $MyFile
|
---|
98 | sed -i 's/West Virginia/WV/'gI $MyFile
|
---|
99 | sed -i 's/Wisconsin/WI/gI' $MyFile
|
---|
100 | sed -i 's/Wyoming/WY/gI' $MyFile
|
---|
101 | sed -i 's/American Samoa/AS/gI' $MyFile
|
---|
102 | sed -i 's/Guam/GU/gI' $MyFile
|
---|
103 | sed -i 's/Northern Mariana Islands/MP/gI' $MyFile
|
---|
104 | sed -i 's/Puerto Rico/PR/gI' $MyFile
|
---|
105 | sed -i 's/Virgin Islands/VI/gI' $MyFile
|
---|
106 | sed -i 's/West VA/WV/gI' $MyFile
|
---|
107 | sed -i 's/N Carolina/NC/gI' $MyFile
|
---|
108 | sed -i 's/N Dakota/ND/gI' $MyFile
|
---|
109 | sed -i 's/S Carolina/SC/gI' $MyFile
|
---|
110 | sed -i 's/S Dakota/SD/gI' $MyFile
|
---|
111 | sed -i 's/Puerto Rico/PR/gI' $MyFile
|
---|
112 | sed -i 's/Virgin Islands/VI/gI' $MyFile
|
---|
113 | sed -i 's/"W. VA"/WV/gI' $MyFile
|
---|
114 | sed -i 's/"N. Carolina"/NC/gI' $MyFile
|
---|
115 | sed -i 's/"N. Dakota"/ND/gI' $MyFile
|
---|
116 | sed -i 's/"S. Carolina"/SC/gI' $MyFile
|
---|
117 | sed -i 's/"S. Dakota"/SD/gI' $MyFile
|
---|
118 | sed -i 's/"R.I."/RI/gI' $MyFile
|
---|
119 |
|
---|
120 |
|
---|
121 | #Fix the state entries
|
---|
122 |
|
---|
123 | (grep -n '<state>' $MyFile |awk -F\: '{print $1}') >> statetags.txt
|
---|
124 |
|
---|
125 | for i in $(cat statetags.txt);
|
---|
126 | do
|
---|
127 | StateLineLength=$(sed -n "$i"p "$MyFile" | sed 's/^[ \t]*//' |awk '{print length}')
|
---|
128 |
|
---|
129 | echo "StateLineLength is $StateLineLength"
|
---|
130 | if [ ! "17" = "$StateLineLength" ]
|
---|
131 | then
|
---|
132 |
|
---|
133 | cat -n $MyFile | grep '<state>';echo "$MyFile"
|
---|
134 | echo "Urgent there is a problem with the <state> tag in $MyFile"
|
---|
135 | read
|
---|
136 |
|
---|
137 | fi
|
---|
138 | done
|
---|
139 |
|
---|
140 | StateLineLength=""
|
---|
141 | rm -rf statetags.txt #UNCOMMENT THIS!!!
|
---|
142 |
|
---|
143 | echo "$MyFile"
|
---|
144 | a1=$(grep -n \"SSN\" $MyFile | awk -F\" '{print $2}'); echo "$a1"
|
---|
145 | echo "$a1 is the line with SSN on it"
|
---|
146 | sed -i s/@@SSN@@/"$a1"/ $MyFile
|
---|
147 | sed -i 's/SSN/2.16.840.1.113883.4.1/' $MyFile
|
---|
148 | a1=""
|
---|
149 |
|
---|
150 |
|
---|
151 | echo "SSN code added"
|
---|
152 | echo "About to start fixing the problem section"
|
---|
153 | read
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 | #PROBLEM SECTION 1 FIX - TEMPLATE
|
---|
160 | #Add the added template line after 2.16.840.1.113883.10.20.1.50
|
---|
161 | sed -in /"2.16.840.1.113883.10.20.1.50"/s/$/"\\n<templateId root=\"2.16.840.1.113883.3.249.11.100.12\"\\/>"/ "$MyFile"
|
---|
162 | cat -n "$MyFile" | grep "3.249.11.100.12"
|
---|
163 |
|
---|
164 | read
|
---|
165 | #PROBLEM FIX 2 - TABLE
|
---|
166 | #Remove the table in the beginning of the section
|
---|
167 | ProblemSectionKey=$(grep -n "11450-4" "$MyFile" | awk -F: '{print $1}')
|
---|
168 | grep -n "2.16.840.1.113883.10.20.1.27" "$MyFile" | awk -F: '{print $1}' >> Problem27TemplateLines.txt
|
---|
169 | read
|
---|
170 | startline="$ProblemSectionKey"
|
---|
171 | endline="$(head -1 Problem27TemplateLines.txt)"
|
---|
172 | echo "$startline is startline"
|
---|
173 | echo "$endline is endline"
|
---|
174 | cat -n "$MyFile" | grep '<table>'
|
---|
175 | #Remove the table at the beginning of the problem section but leaves <text/>
|
---|
176 | sed -in "$startline,$endline{ s/<text>/<text\/>\n<text>/ }" "$MyFile"
|
---|
177 | sed -in "$startline,$endline{ /<text>/,/<\/text>/d }" "$MyFile"
|
---|
178 |
|
---|
179 | # this in an example of one that works
|
---|
180 | #sed -in "$startline,$endline{ /<table>/,/<\/table>/d }" M1-PAT_100839_QRDA_V1_0_0.xml
|
---|
181 | cat -n "$MyFile" | grep '<table>'
|
---|
182 | echo "Done removing the table"
|
---|
183 | startline=""
|
---|
184 | endline=""
|
---|
185 | rm -rf Problem27TemplateLines.txt
|
---|
186 | rm -rf MyValueLinesInProblems.txt
|
---|
187 | #PROBLEM SECTION FIX 3 - TEXT TAGS
|
---|
188 | #Remove <text> </text> section near effectiveTime
|
---|
189 | read
|
---|
190 |
|
---|
191 | index="0"
|
---|
192 | grep -n "2.16.840.1.113883.3.249.11.100.8" $MyFile | awk -F: '{print $1}' >> MyTextLinesKeysProblems.txt
|
---|
193 | for i in $(cat MyTextLinesKeysProblems.txt);
|
---|
194 | do
|
---|
195 | startline="$(($i+$index))"
|
---|
196 | endline="$(($i+$index+10))"
|
---|
197 | sed -in "$startline,$endline{ /<text>/,/<\/text>/d }" "$MyFile"
|
---|
198 | index="$((index-3))"
|
---|
199 | done
|
---|
200 | index=""
|
---|
201 | starline=""
|
---|
202 | endline=""
|
---|
203 | rm -rf MyTextLinesKeysProblems.txt
|
---|
204 | echo "done removing <text>"
|
---|
205 | read
|
---|
206 |
|
---|
207 | #PROBLEM SECTION 4 FIX - REMOVE BAD VALUE LINE
|
---|
208 | #remove the value tags after the 2.16.840.1.113883.10.20.1.50 enty
|
---|
209 | index="0"
|
---|
210 | echo "value Lines in Problems about to be written to screen and then the file"
|
---|
211 | #grep -n "2.16.840.1.113883.10.20.1.50" $MyFile | awk -F: '{print $1}'
|
---|
212 | grep -n "2.16.840.1.113883.10.20.1.50" $MyFile | awk -F: '{print $1}' >> MyValueLinesInProblems.txt
|
---|
213 | for i in $(cat MyValueLinesInProblems.txt);
|
---|
214 | do
|
---|
215 | startline="$((i+index))"
|
---|
216 | endline="$(($i+index+8))"
|
---|
217 | #sed -in "$startline,$endline{ /<value>/,/<\/value>/d }" "$MyFile"
|
---|
218 | sed -in "$startline,$endline{ /<value>/,/<\/value>/d }" "$MyFile"
|
---|
219 | echo "a value line was deleted from the $startline area"
|
---|
220 | index="$((index-3))"
|
---|
221 | done
|
---|
222 | index=""
|
---|
223 | starline=""
|
---|
224 | endline=""
|
---|
225 | cat MyValueLinesInProblems.txt
|
---|
226 | rm -rf MyValueLinesInProblems.txt
|
---|
227 | echo "done removing bad value lines"
|
---|
228 | read
|
---|
229 |
|
---|
230 | #PROBLEM SECTION 5 FIX - ADD GOOD VALUE LINE
|
---|
231 |
|
---|
232 | #Put in a good value line if there are bad ones
|
---|
233 |
|
---|
234 | cat -n "$MyFile" | grep "55561003"; echo "greped 55561003"
|
---|
235 | cat -n "$MyFile" | grep "2.16.840.1.113883.3.249.11.100.12";echo "grepped 2.16.840.1.113883.3.249.11.100.12"
|
---|
236 | cat -n "$MyFile" | grep "2.16.840.1.113883.10.20.1.50"; echo "grepped 2.16.840.1.113883.10.20.1.50"
|
---|
237 | echo " about to add xsi value lines with sed"
|
---|
238 | read
|
---|
239 |
|
---|
240 | #sed -in '/"2.16.840.1.113883.10.20.1.50"/{n;n;n;s/$/\n<value xsi:type="CE" code="55561003" codeSystem="2.16.840.1. 113883.6.96" displayName="Active" codeSystemName="SNM" \/>/}' "$MyFile"
|
---|
241 | sed -in '/"2.16.840.1.113883.10.20.1.50"/{N;N;N;s/$/\n<value xsi:type="CE" code="55561003" codeSystem="2.16.840.1.113883.6.96" displayName="Active" codeSystemName="SNM" \/>/}' "$MyFile"
|
---|
242 | #echo "value Lines in Problems about to be written to screen and then the file"
|
---|
243 | #grep -n "2.16.840.1.113883.10.20.1.50" $MyFile | awk -F: '{print $1}'
|
---|
244 | #grep -n "2.16.840.1.113883.10.20.1.50" $MyFile | awk -F: '{print $1}' >> MyValueLinesInProblems.txt
|
---|
245 | #for i in $(cat MyValueLinesInProblems.txt)
|
---|
246 | #do
|
---|
247 | # sed -in "$i","$((i+6))"p "$MyFile"
|
---|
248 | #done
|
---|
249 | #rm -rf MyValueLinesInProblems.txt
|
---|
250 | echo "done adding good value line"
|
---|
251 | read
|
---|
252 |
|
---|
253 | #PROBLEM #6 - XSI PROBLEM
|
---|
254 | #Fix the missing xsi:code value lines
|
---|
255 | #Fix any wrong value elements in the problem section
|
---|
256 | #I don't think there are any
|
---|
257 |
|
---|
258 | #cat MyStatusTemplates.txt
|
---|
259 | #echo "above checking the MyStatusTemplates.txt file content"
|
---|
260 | read
|
---|
261 |
|
---|
262 | echo "issuing the sed command to delete the buffer"
|
---|
263 |
|
---|
264 | sed -e 'd' /home/nancy/CCR-Template/MyFile.txt
|
---|
265 | read
|
---|
266 | Startline="$(cat "$MyFile" | grep -n "11450-4" | awk -F: '{print $1}')"
|
---|
267 | grep -n "2.16.840.1.113883.10.20.1.50" "$MyFile" | awk -F: '{print $1}' >> MyStatusTemplates.txt
|
---|
268 | Endline="$(tail -1 MyStatusTemplates.txt)"
|
---|
269 | cat -n "$MyFile" | grep '<value code'
|
---|
270 | echo "Endline is $Endline"
|
---|
271 | echo "startline is $Startline"
|
---|
272 |
|
---|
273 | #echo 'about to run the sed -fix the xsi code"
|
---|
274 | #sed -in "158,401{ s/<value code/<value xsi:type=\"CD\" code/ }" "$MyFile"
|
---|
275 | sed -in "$Startline,$Endline{ s/<value code/<value xsi:type=\"CD\" code/ }" "$MyFile"
|
---|
276 | sed -in "$Startline,$Endline{ s/<value displayName/<value xsi:type=\"CD\" displayName/ }" "$MyFile"
|
---|
277 |
|
---|
278 | StartLine=""
|
---|
279 | Endline=""
|
---|
280 | rm -rf MyStatusTemplates.txt
|
---|
281 | echo "done checking for bad value lines"
|
---|
282 | read
|
---|
283 |
|
---|
284 |
|
---|
285 | #Done fixing Problem Section**********
|
---|
286 |
|
---|
287 | #Fix that dummy number they gave us with the right entry for Matt or Nancy
|
---|
288 | echo "if grep -q Nancy $MyFile then"
|
---|
289 | if grep -q Nancy $MyFile then
|
---|
290 | then
|
---|
291 | sed -i 's/6558574524/1558574525/' $MyFile
|
---|
292 | else
|
---|
293 | sed -i 's/6558574524/1124022827/' $MyFile
|
---|
294 | fi
|
---|
295 |
|
---|
296 | echo "read change NPIs for Matt and Nancy"
|
---|
297 | read
|
---|
298 | #Line adminstrative gender code is on
|
---|
299 | a=$(grep -n birthTime $MyFile|awk -F: '{print $1}')
|
---|
300 |
|
---|
301 | sed -i 's/AdministrativeGender\"\ codeSystem=\"\"/AdministrativeGender\"\ codeSystem=\"2.16.840.1.113883.5.1\"/' $MyFile
|
---|
302 | #sed -i 's/AdministrativeGender\"\ codeSystem=\"\"/codeSystem=\"2.16.840.1.113883.5.1\"/' $MyFile
|
---|
303 | #sed -i 's/administrativeGenderCode displayName=\"FEMALE\"/administrativeGenderCode/' $MyFile
|
---|
304 | #sed -i 's/administrativeGenderCode displayName=\"MALE\"/administrativeGenderCode/' $MyFile
|
---|
305 |
|
---|
306 | #now that the adminstrativeGenderCode is fixed, save it in a variable
|
---|
307 | agc=$(grep AdminstrativeGender $MyFile)
|
---|
308 |
|
---|
309 | echo "Moving header including up to birthTime into MyNewFile.xml"
|
---|
310 | #Send the part of the file up to and including administrativeGenderCode and birthTime to MyNewFile
|
---|
311 | head -"$a" $MyFile >> MyNewFile.xml
|
---|
312 |
|
---|
313 | a=""
|
---|
314 | agc=""
|
---|
315 | read
|
---|
316 | #the race and ethnicity will eventually come from the CCR Social History
|
---|
317 | #orde needs to be adminGender, birthTIme, race, ethnicity
|
---|
318 | #Now add the administrative gender
|
---|
319 |
|
---|
320 |
|
---|
321 | #now add the race code line to my new file
|
---|
322 | #right now everybody is native Hawaiian until we get this fixed!
|
---|
323 | #Plan to use only the existing VistA codes which match meaningful use
|
---|
324 | echo '<raceCode code="2076-8" codeSystem="2.16.840.1.113883.5.104"/>' >> MyNewFile.xml
|
---|
325 | echo '<ethnicGroupCode code="2186-5" codeSystem="2.16.840.1.113883.5.50"/>' >> MyNewFile.xml
|
---|
326 | echo '</patient>' >> MyNewFile.xml
|
---|
327 |
|
---|
328 | tail -6 MyNewFile.xml
|
---|
329 |
|
---|
330 | #the race and ethnicity that will eventually come from the CCR Social History
|
---|
331 | echo "fix administrativeGender, birthTime, raceCode and ethnicGroup"
|
---|
332 | read
|
---|
333 | #copy the lines with the birthTime and <patient> and into the file in tieir proper place
|
---|
334 | #by pulling their locatin from the original file relative to the administrativeGenderCode line
|
---|
335 |
|
---|
336 |
|
---|
337 | #The providerOrganization sectiono is missing entrirely so put it in from these hard coded files for Matt and Nancy
|
---|
338 | #in their proper place right after the </patient tag
|
---|
339 |
|
---|
340 | if grep -q Nancy $MyFile
|
---|
341 | then
|
---|
342 | cat NancysProviderOranization.txt >> MyNewFile.xml
|
---|
343 | else
|
---|
344 | cat MatthewsProviderOranization.txt >> MyNewFile.xml
|
---|
345 | fi
|
---|
346 | #this just adds a line feed to MyNewFile.xml
|
---|
347 | echo >> MyNewFile.xml
|
---|
348 |
|
---|
349 | echo "read Provider organizaton added"
|
---|
350 | read
|
---|
351 | #put the document beginning with /patientRole until the </participant> tag that is 2 lines after the only incidence of </associated person just before the <documentationOf> into MyNewFile.xml
|
---|
352 | d=$(grep -n "/patientRole" $MyFile|awk -F: '{print $1}');echo $d
|
---|
353 | e=$(($d+1));echo $e
|
---|
354 | f=$(grep -n "/associatedPerson" $MyFile|awk -F: '{print $1}');echo $f
|
---|
355 | g=$(($f+2));echo $g
|
---|
356 | cat $MyFile | sed -n $d,$g"p" >> MyNewFile.xml
|
---|
357 | #now add in the </patient role and </recordTarget>
|
---|
358 | echo "read /patientRole to /participant Person added"
|
---|
359 | read
|
---|
360 | #now add the documentation of pulling the data from the encounter procedures later in the document. Searches for Encounters that are
|
---|
361 | #appropriate for the measure which will be in Encounter.txt
|
---|
362 |
|
---|
363 | #!!!!ADD MATT HERE
|
---|
364 | for i in $(cat AllM1EncounterCodes.txt);
|
---|
365 | do
|
---|
366 | echo $i
|
---|
367 | if grep -q $i $MyFile
|
---|
368 | then
|
---|
369 | echo $(grep -n $i $MyFile | awk -F: '{print $1}') >> Encounters.txt
|
---|
370 | fi
|
---|
371 | done
|
---|
372 | cat Encounters.txt
|
---|
373 | for i in $(cat Encounters.txt);
|
---|
374 | do
|
---|
375 | echo
|
---|
376 | echo "<documentationOf>" >> MyNewFile.xml
|
---|
377 | echo "<serviceEvent>" >> MyNewFile.xml
|
---|
378 | cat $MyFile | sed -n $i"p" >> MyNewFile.xml
|
---|
379 | x=$(($i+5)); echo $x
|
---|
380 | y=$(($i+8)); echo $y
|
---|
381 | echo "sed -n "$x","$y"p >> MyNewFile.xml"
|
---|
382 | cat "$MyFile" | sed -n "$x","$y"p >> MyNewFile.xml
|
---|
383 | cat EndDocumentationOfSectionNancy.txt >> MyNewFile.xml
|
---|
384 | #added a line feed
|
---|
385 | echo >> MyNewFile.xml
|
---|
386 | #for testing
|
---|
387 | tail MyNewFile.xml
|
---|
388 |
|
---|
389 | done
|
---|
390 | rm -rf Encounters.txt
|
---|
391 | y=""
|
---|
392 | x=""
|
---|
393 |
|
---|
394 | echo "read documentationOf added and each section of that tailed -10"
|
---|
395 | read
|
---|
396 | #takes the low value date and puts it in the high value if the the is a nullFlavor there and it also corrects the dates by adding a 0
|
---|
397 | #in the 5th digit position if the date is 7 long instead of 8 and a zero in the 5th and next to the last position if the date is 6 long (ie,too short in either the low or high value) The latter is fixed now so it can be trimmed out - soon All dates and times are 8 or more
|
---|
398 | echo "<component>" >> MyNewFile.xml
|
---|
399 | p=$(grep -n '<structuredBody>' $MyFile | awk -F: '{print $1}')
|
---|
400 | q=$(grep -n '</ClinicalDocument>' $MyFile | awk -F: '{print $1}')
|
---|
401 | cat "$MyFile" | sed -n "$p","$q"p >> MyNewFile.xml
|
---|
402 | # take out <high nullFlavor="UNK"/> and replace it with the same value that is in low value everywhere it appears
|
---|
403 |
|
---|
404 | grep -n '<high nullFlavor="UNK"/>' MyNewFile.xml | awk -F: '{print $1}' >> NullFlavorTimes.txt
|
---|
405 | #NullFlavorTimes.txt has the line numbers
|
---|
406 | for i in $(cat NullFlavorTimes.txt);
|
---|
407 | do
|
---|
408 | #low value is one line above the high value with the nullFlavor, so get the date as it is
|
---|
409 | l=$(($i-1));echo $l
|
---|
410 | m=$(sed -n "$l"p MyNewFile.xml)
|
---|
411 | n=$(echo "$m" | awk -F\" '{print $2}')
|
---|
412 | u=$(echo "${#n}")
|
---|
413 | #fixes the date in low value if it is 7 long
|
---|
414 | if [ $u = 7 ]
|
---|
415 | then
|
---|
416 | v=$(echo $n |cut -c1-4)
|
---|
417 | w=$(echo $n |cut -c5-7)
|
---|
418 | j=$(echo $v"0"$w);echo $n
|
---|
419 | sed -i "$l"s/"$n"/"$j"/ MyNewFile.xml
|
---|
420 | n="$j"
|
---|
421 | #fixes the date if it is 6 long
|
---|
422 | elif [ $u = 6 ]
|
---|
423 | then
|
---|
424 | v=$(echo $n |cut -c1-4)
|
---|
425 | w=$(echo $n |cut -c5)
|
---|
426 | x=$(echo $n |cut -c6)
|
---|
427 | j=$(echo $v"0"$w"0"$x);echo $n
|
---|
428 | sed -i "$l"s/"$n"/"$j"/ MyNewFile.xml
|
---|
429 | n="$j"
|
---|
430 | fi
|
---|
431 | #now puts the low value corrected date in the high value
|
---|
432 | o="value="\""$n"\"""
|
---|
433 | echo $o
|
---|
434 | echo $i
|
---|
435 | #echo "sed -i "$i"s/nullFlavor=\"UNK\"/$o/ MyNewFile.xml"
|
---|
436 | sed -i "$i"s/'nullFlavor=\"UNK\"'/"$o"/ MyNewFile.xml
|
---|
437 | done
|
---|
438 | rm -rf NullFlavorTimes.txt
|
---|
439 |
|
---|
440 | l=""
|
---|
441 | m=""
|
---|
442 | n=""
|
---|
443 | u=""
|
---|
444 | v=""
|
---|
445 | w=""
|
---|
446 | j=""
|
---|
447 | o=""
|
---|
448 | i=""
|
---|
449 | echo "read NullFlavorTimes Fixed"
|
---|
450 | #
|
---|
451 | read
|
---|
452 |
|
---|
453 |
|
---|
454 | #Remove all of the sections that are not for M1 which begin 2 lines before the PQRI-2 entry and end 2 lines before the reporting parameters code entry 55187.9 This section to be developed
|
---|
455 |
|
---|
456 |
|
---|
457 |
|
---|
458 | #Now remove the Procedures section from the M1 report as the procedures are not in the downloadable resource table. Need to find the code 47519-4 and delete the whole component that begins with <component> and and goes to the </component> immediately after the code line.47519-4 is the code for the procedures section
|
---|
459 | if grep -q "47519-4" MyNewFile.xml
|
---|
460 | then
|
---|
461 | #Sets a to the line number with the code in it
|
---|
462 | LineNum="$(grep -n "47519-4" MyNewFile.xml|awk -F: '{print $1}')"
|
---|
463 | echo "$LineNum"
|
---|
464 |
|
---|
465 |
|
---|
466 | #about two lines above line with 47519-4 in it is a line that is just <component>. Go backward one line at a time and find the line number of that line which is set to a1
|
---|
467 | #GrepForComponentLineNumber returns $? with 0 is true and 1 is false
|
---|
468 | #work backwards from LineNum to find the line with <component> in it
|
---|
469 |
|
---|
470 | Result="$(sed -n "$LineNum"p MyNewFile.xml | grep -n "<component>";echo $?)"
|
---|
471 | echo "$Result"
|
---|
472 | echo "$LineNum"
|
---|
473 | echo "$(($LineNum-1))"
|
---|
474 | while [ "1" = "$Result" ];
|
---|
475 | do
|
---|
476 | LineNum="$(($LineNum-1))"
|
---|
477 | echo "$LineNum"
|
---|
478 | Result="$(sed -n "$LineNum"p MyNewFile.xml | grep -n "<component>";echo $?)"
|
---|
479 | done
|
---|
480 |
|
---|
481 | BeginLineNum="$LineNum"; echo "BeginLineNum is $BeginLineNum"
|
---|
482 |
|
---|
483 | #initialize EndLineNum which will ultimately be the line with the ending component tag, </component>
|
---|
484 | EndLineNum="$(($LineNum+1))"; echo "EndLineNum is $EndLineNum"
|
---|
485 |
|
---|
486 | #This is to check the line and if it does not contain </component>, add 1 to EndLineNum and go to the next line and check that one
|
---|
487 |
|
---|
488 | Result2="$(sed -n "$EndLineNum"p MyNewFile.xml | grep -n '</component>';echo "$?")"
|
---|
489 | echo "Result2 is $Result2"
|
---|
490 | while [ "$Result2" = "1" ];
|
---|
491 | do
|
---|
492 | EndLineNum="$(($EndLineNum+1))"
|
---|
493 | echo "EndLineNum is $EndLineNum"
|
---|
494 | Result2="$(sed -n "$EndLineNum"p MyNewFile.xml | grep -n '</component>';echo "$?")"
|
---|
495 | done
|
---|
496 | echo "Beginning line Number of the Procedure Section is $BeginLineNum"
|
---|
497 | echo "Ending Line Number of the Procedure Section is $EndLineNum"
|
---|
498 | #Now delete the procedure section
|
---|
499 |
|
---|
500 | sed -in "$BeginLineNum","$EndLineNum"d MyNewFile.xml
|
---|
501 | fi
|
---|
502 |
|
---|
503 | echo "read deleted the procedures section"
|
---|
504 | read
|
---|
505 |
|
---|
506 |
|
---|
507 | #Replace anything with SNOMED or SNOMED-CT with SNM and replace anything with ICD9CM with I9 and and replace where it says codeSystem="" in the problem list with codeSysetm="2.16.840.1.113883.6.103"
|
---|
508 | #in lines that contain ICD9CM, replace codeSystem="" with codeSystem="2.16.840.1.113883.6.103"
|
---|
509 | sed -i '/ICD9CM/s/codeSystem=\"\"/codeSystem=\"2.16.840.1.113883.6.103\"/' MyNewFile.xml
|
---|
510 | sed -i 's/SNOMED-CT/SNM/' MyNewFile.xml
|
---|
511 | sed -i 's/ICD9CM/I9/' MyNewFile.xml
|
---|
512 | sed -i 's/ICD9/I9/' MyNewFile.xml
|
---|
513 | sed -i 's/SNOMED/SNM/' MyNewFile.xml
|
---|
514 |
|
---|
515 |
|
---|
516 | #Now put out a new file that has the same name as the original with Ver2 at the end which will contain the corrected header
|
---|
517 | echo "replace the codes with their proper names"
|
---|
518 | #read
|
---|
519 |
|
---|
520 |
|
---|
521 | cp MyNewFile.xml $(echo $MyFile | echo $(awk -F. '{print $1}')"Ver2.xml")
|
---|
522 | #mv MyNewFile.xml $(echo $MyFile | echo $(awk -F. '{print $1}')"Ver2.xml")
|
---|
523 | if grep -q 30954-2 MyNewFile.xml
|
---|
524 | then
|
---|
525 | echo "$MyFile contains results" >> FilesWithResults.txt
|
---|
526 | echo "$MyFile contains results"
|
---|
527 | fi
|
---|
528 | rm -rf MyNewFile.xml
|
---|
529 | rm -rf MyNewFile.xmln
|
---|
530 | echo "this is the end"
|
---|
531 | #read
|
---|
532 | echo "end $MyFile"
|
---|
533 | done
|
---|
534 |
|
---|
535 | echo "read FilesWithResults.txt has the names of files for running the results script"
|
---|
536 | read
|
---|
537 | exit
|
---|