Index: /ccr2ccd-xslt/trunk/make/FunctionProcessProblemSection
===================================================================
--- /ccr2ccd-xslt/trunk/make/FunctionProcessProblemSection	(revision 1033)
+++ /ccr2ccd-xslt/trunk/make/FunctionProcessProblemSection	(revision 1033)
@@ -0,0 +1,108 @@
+#!/bin/bash/
+#Find the last line number in the Problem Section by finding the next <component line that is after the last
+#line  entry in the MyFileToProcess.txt
+#Process each section found in MyFileToProcess.txt one line at a time to determine whether or not they are in the downloadable resource file
+#by Beginning at the KeyLineNumber which is $1 proceed down until you find a line beginning with <value and process that line to 
+#extract the I9 code found in code="xxxx" and check to see if that is in the list of AllI9ProblemCodes.txt
+#if it is not in the list, store the beginning and ending line numbers to prepare to delete the problem.
+#Delete the offending Problem
+#Delete the text files that were created which are
+#PatientProblemEntryTemplateRows.txt
+#ProblemCodes.txt
+#You will need the following files
+#   LineNumberDownFunction
+#   AllI9ProblemCodes.txt
+#   LineNumberUpDownFunction
+#   This file FunctionProcessProblemSection
+FunctionProcessProblemSection ()
+{
+local File
+local LastLineInProblemSection
+local ProblemCode
+local BeginProblemSectionCodeLineNumber
+local EndProblemSectionLineNumber
+local a
+local b
+local i
+local KeyLineNumber
+File="$1"
+echo "File is $File"
+read
+#read
+  #Find the code that identifies the near beginning of the problem section
+  BeginProblemSectionCodeLineNumber="$(grep -n "11450-4" "$File" | awk -F: '{ print $1 }')"
+  echo "BeginProblemSectionCodeLineNumber is $BeginProblemSectionCodeLineNumber"
+  #Use the LineNumberDownFunction to find the last line in the problem section
+  source LineNumberDownFunction
+  LineNumberDownFunction $BeginProblemSectionCodeLineNumber "$BeginProblemSectionCodeLineNumber" '</component>' "$File"
+  echo "result of LineNumberDownFunction is $TestSectionInformation which has the last line of the problem section in the second entry with a separator that is a colon"
+  #read
+  #Parse the Variable that comes out from that function to get the last line of the section
+  echo "$TestSectionInformation" | awk -F: '{ print $2 }'
+  EndProblemSectionLineNumber="$(echo "$TestSectionInformation" | awk -F: '{ print $2 }')"
+  echo "$EndProblemSectionLineNumber is the last line in the problem section"
+  #read
+  #Search the problem section to extract the problem codes by finding the template lines for problems, seaching the next 10 lines for the value line and parsing that to get the problem code
+  echo "BeginProblemSectionCodeLineNumber is $BeginProblemSectionCodeLineNumber and EndProblemSectionLineNumber is $EndProblemSectionLineNumber"
+  echo "$File"
+  grep -n "2.16.840.1.113883.3.249.11.100.8" "$File" | awk -F: '{ print $1 }' >> PatientProblemEntryTemplateRows.txt 
+  #head -"$EndProblemSectionLineNumber" "$File" | tail -"$(($EndProblemSectionLineNumber-$BeginProblemSectionCodeLineNumber))" | grep -n "2.16.840.1.113883.3.249.11.100.8" | awk -F: '{ print $1 }' >> PatientProblemEntryTemplateRows.txt 
+  #sed -n "$BeginProblemSectionCodeLineNumber","$EndProblemSectionLineNumber"p "$File" | grep -n "2.16.840.1.113883.3.249.11.100.8" | awk -F: '{ print $1 }' >> PatientProblemEntryTemplateRows.txt 
+  cat PatientProblemEntryTemplateRows.txt
+  echo "Template 2.16.840.1.113883.3.249.11.100.8 row numbers are above"
+  if [ -s PatientProblemEntryTemplateRows.txt ]
+  then
+    for i in $(cat PatientProblemEntryTemplateRows.txt)
+      do
+      echo "$i"
+      head -"$(( $i+10 ))" "$File" \
+        | tail \
+	 | grep '<value ' \
+	  | awk -F'code="' '{ print $2 }' \
+	    | awk -F\" '{ print $1}' >> ProblemCodes.txt 
+      done
+   fi
+  echo "Problem codes in the problem section are"
+  cat "ProblemCodes.txt"
+  read
+  #Now find out what I9 problem codes are not in the downloadable resource and print those to a file
+  for i in $(cat ProblemCodes.txt) 
+    do 
+      cat AllI9ProblemCodes.txt \
+	|grep -q "$i";echo $?
+      cat AllI9ProblemCodes.txt \
+	|grep -q "$i"
+	if [ "1" = "$?" ]
+	then 
+	  echo "There was an problem not found in the Downloadable Resource list of I9 problems"
+	  echo "$i"
+	  echo "the line above should have a single problem number"
+	  grep -n "code=\"$i" "$File" | awk -F: '{ print $1 }'
+	  echo "the line above should have a line number where the problem number was found"
+	  echo "that line number will be set to KeyLineNumber and handed off to the LineUpDownFunction"
+	  KeyLineNumber=$(grep -n "code=\"$i" "$File" | awk -F: '{ print $1 }')
+	  echo "The KeyNumber to hand the LineUpDownFunction is $KeyLineNumber"
+	  read
+	  source LineNumberUpDownFunction
+	  LineNumberUpDownFunction "$KeyLineNumber" '<entry ' '</entry>' "$File"
+	  echo "above is the output from the LineNumberUpDownFunction. It is in variable called SectionInformation"
+	  echo "that has the key line number, the line with <entry and the line with </entry and then the File name"
+	  echo "separated by colons"
+          a=$(echo "$SectionInformation" | awk -F: '{print $2 }')
+	  b=$(echo "$SectionInformation" | awk -F: '{print $3 }')
+	  sed -n "$a","$b"d "$File"
+	  echo "Problem $i was deleted from $File"
+	  echo "Confirming Problem was deleted with grep -q"
+	  grep -q "$ProblemToDeleted" "$File"
+	  echo " Is the problem deleted? dollar? is $?"
+	  #read
+	  xmlwf "$File"
+	  echo "Just checked to see if $File is well formed and dollar? is $?"
+	  read 
+	  
+	fi
+    done
+   rm -rf PatientProblemEntryTemplateRows.txt
+  rm -rf ProblemCodes.txt
+ 
+  }
Index: /ccr2ccd-xslt/trunk/make/LineNumberDownFunction
===================================================================
--- /ccr2ccd-xslt/trunk/make/LineNumberDownFunction	(revision 1033)
+++ /ccr2ccd-xslt/trunk/make/LineNumberDownFunction	(revision 1033)
@@ -0,0 +1,59 @@
+#!/bin/bash
+#Takes the $1 argument of the beginning line number, and the 
+# $2 argument of the element you are looking for
+# $3 is the name of the file
+LineNumberDownFunction ()
+{
+echo "arguments are $1 $2 and $3"
+
+local BeginLineNumber
+#BeginLineNumber=""
+BeginLineNumber="$1"
+
+local EndSectionElement
+#EndSectionElement=""
+EndSectionElement="$2"
+
+local File
+#File=""
+File="$3"
+
+local FoundEndSectionElement
+FoundEndSectionElement=""
+
+local EndLineNum
+#EndLineNum=""
+local LineNum
+
+local EndSectionLineNumber
+#TestSectionInformation=""
+echo "file is $File"
+LineNum="$BeginLineNumber"; echo "BeginLineNumber is $BeginLineNumber"
+#read
+#initialize EndLineNum which will ultimately be the line with the ending component tag, "$EndSectionElement"
+EndLineNum="$(($LineNum+1))"; echo "EndLineNum is $EndLineNum"
+#This is to check the line and if it does not contain $EndSectionElement, add 1 to EndLineNum and go to the next line and check that one
+head -"$EndLineNum" "$File" | tail -1| grep -q "$EndSectionElement" > /dev/null
+FoundEndSectionElement="$?"
+#FoundEndSectionElement="$(head -"$EndLineNum" "$File" | tail -1| grep -q "$EndSectionElement";echo "$?")"
+#FoundEndSectionElement="$(sed -n "$EndLineNum"p "$File" | grep -q "$EndSectionElement";echo "$?")"
+echo "FoundEndSectionElement is $FoundEndSectionElement"
+#read
+while [ "$FoundEndSectionElement" = "1" ];
+do 
+  EndLineNum="$(($EndLineNum+1))"
+  echo "EndLineNum is $EndLineNum"
+  # echo "$(head -"$EndLineNum" "$File" | tail -1)"
+  head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndSectionElement"
+  FoundEndSectionElement="$?"
+  #FoundEndSectionElement="$(head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndSectionElement";echo "$?")"
+  echo "FoundEndSectionElement is $FoundEndSectionElement and the EndSectionElement is $EndSectionElement and current line being tested is $EndLineNum"
+done
+echo "Beginning line Number of the Section is $BeginLineNumber"
+EndSectionLineNumber="$EndLineNum"
+echo "Ending Line Number of the Section is $EndSectionLineNumber"
+
+TestSectionInformation=$(echo "$BeginLineNumber:$EndSectionLineNumber:$EndSectionElement:$File")
+echo "end LineNumberDownFunction"
+
+}
Index: /ccr2ccd-xslt/trunk/make/LineNumberUpDownFunction
===================================================================
--- /ccr2ccd-xslt/trunk/make/LineNumberUpDownFunction	(revision 1033)
+++ /ccr2ccd-xslt/trunk/make/LineNumberUpDownFunction	(revision 1033)
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+
+#Recomment that all arguments that are not stright forward be enclosed in single quotes
+#Example call is  
+#$ source KeyUpDownFunction
+#$ KeyUpDownFunction 'root="PROCEDURE_4234_52' '<entry ' '</entry>' 'MyTestFile.xml'
+
+#First argument is the line number inside the section you wish to isolate. for instance for a problem, it might be a number you have collected from a file containing all of the line numbers of the problem QRDA template, 2.16.840.1.113883.3.249.11.100.8
+#Second argument is the tag or some other marker of the top of the section you with to isolate such as <component> or prehaps <entry>
+#Third argument is the tag or some other marker of the top of the section you with to isolate such as </component> or prehaps </entry>
+#fourth argument is the filename you are doing this in
+#The fifth argument is optional and is the Marker you wish to leave in the file showing where this section began.  It might be an empty tag or a comment - this part has not been added to the function yet
+LineNumberUpDownFunction()
+{
+  local LineNum
+  local Result
+  local BeginLineNum
+  local EndLineNum
+  local Result2
+  local KeyLineNumber
+  local Marker
+  
+  File="$4"
+  echo "File is $File"
+  KeyLineNumber="$1"
+  echo "KeyLineNumber is $KeyLineNumber"
+  StartElement="$2"
+  echo "Starting Element is $StartElement"
+  EndElement="$3"
+  echo "EndElement is $EndElement"
+  #Marker="$5"
+ LineNum="$KeyLineNumber"
+ echo "LineNum is starting at $KeyLineNumber"
+    #Start at the line number you have chosen and move 
+    #backward one line at a time and find the line number of that has what is in the second argument
+    #Greping for the Element LineNumb returns $? with 0 is true and 1 is false if the element is in the line
+    #work backwards from LineNum to find the line with what you want in it
+    Result="$(head -"$LineNum" "$File" |tail -1 | grep -q "$StartElement";echo $?)"
+    echo "Result of last check of the line number is $Result"
+    echo "The current line number being tested is $LineNum"
+    echo "The next line number to test is $(($LineNum-1))"
+    while [ "1" = "$Result" ]
+    do 
+      LineNum="$(($LineNum-1))"
+      echo "$LineNum"
+      Result="$(head -"$LineNum" "$File" |tail -1 | grep -q "$StartElement";echo $?)"
+    done
+    BeginLineNum="$LineNum"; echo "BeginLineNum is $BeginLineNum"
+    #initialize EndLineNum which will ultimately be the line with the ending component tag, "$EndElement"
+    EndLineNum="$(($LineNum+1))"; echo "EndLineNum is starting at $EndLineNum"
+    #This is to check the line and if it does not contain $EndElement, add 1 to EndLineNum and go to the next line and check that one
+    Result2="$(head -"$EndLineNum" "$File" | tail -1| grep -q "$EndElement";echo "$?")"
+    #Result2="$(sed -n "$EndLineNum"p "$File" | grep -q "$EndElement";echo "$?")"
+    echo "Result2 is $Result2"
+    while [ "$Result2" = "1" ]  
+    do 
+      EndLineNum="$(($EndLineNum+1))"
+      echo "EndLineNum is $EndLineNum"
+      # echo "$(head -"$EndLineNum" "$File" | tail -1)"
+      Result2="$(head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndElement";echo "$?")"
+      echo "Result2 is $Result2 and the EndElement is $EndElement and current line being teste is $EndLineNum"
+    done
+    echo "Beginning line Number of the Section is $BeginLineNum"
+    echo "Ending Line Number of the Section is $EndLineNum"
+
+    #Now you know the beginning and ending line number of the section so you can delete it or process it somehow.  It returns the key and name beginning line number the ending line number, the marker and the file
+    echo " KeyLineNumber is $KeyLineNumber, the Beginning of the section has the starting element $StartElement and is on line number $BeginLineNum  and the line number that EndElement which is $EndElement is $EndLineNum, the File name is $File and the place holder left in the file, if there is one, is $Marker"
+    #The Test Section information variable is available to use in your additional processing
+    SectionInformation="$(echo "$KeyLineNumber:$BeginLineNum:$EndLineNum:$File $Marker")"
+    echo "end LineNumberUpDownFunction"
+    echo "the KeyLineNumer BeginlineNum and EndLineNum File and Marker have been written to the variable SectionInformation separated by colons."
+    echo "$KeyLineNumber:$BeginLineNum:$EndLineNum:$File $Marker"
+    #echo "Do you wish to delete the Marker?"
+    read 
+
+}
