source: ccr2ccd-xslt/trunk/make/FixQRDAFewReadsVer19.sh@ 1187

Last change on this file since 1187 was 1004, checked in by George Lilly, 14 years ago

final PQRI files

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