diff --git a/pom.xml b/pom.xml
index 085ae18..6628fae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -94,7 +94,14 @@
4.4.4
-
+
+
+
+ xmlunit
+ xmlunit
+ 1.6
+
+
diff --git a/src/main/java/capstone/app/DocFhir.java b/src/main/java/capstone/app/DocFhir.java
new file mode 100755
index 0000000..2443ba2
--- /dev/null
+++ b/src/main/java/capstone/app/DocFhir.java
@@ -0,0 +1,60 @@
+package capstone.app;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class DocFhir {
+
+ public static boolean convertDocGraphData(String in_filepath){
+
+ return convertDocGraphData(in_filepath, in_filepath + "-FHIR.xml");
+
+ }
+
+ public static boolean convertDocGraphData(String in_filepath, String out_filepath){
+ DocReader reader = new DocReader();
+ FhirMapper mapper = new FhirMapper();
+ FhirPrinter printer = new FhirPrinter();
+ DocData data = null;
+ boolean passedFirstIteration = false;
+
+ try
+ {
+ FileInputStream inputStream = new FileInputStream(in_filepath); //put filename here
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+
+ String line;
+ while ((line = bufferedReader.readLine()) != null) // going to go through each line of the file
+ {
+ data = reader.processLine(line); // put a line into a DocData Element
+ if(passedFirstIteration == true && mapper.exists(data.get_NPI()) == false) //if we passed the first line and the NPI's don't match meaning we found a new doctor or first one
+ {
+ printer.outputResource(mapper.getResource(), out_filepath); // before overriding, output the current resource to a file if there is one to print
+
+ mapper.createPractitioner(data); // mapper will use all fields for the practitioner
+ }
+ else // the NPI's match so we keep adding observations to the practitioner resource
+ {
+ mapper.addAttributes(data); //having mapper add just the necessary fields to the practitioner
+ }
+
+ passedFirstIteration = true; // we now know there will always exist a resource from now until the end.
+ }
+ bufferedReader.close();
+ return true;
+
+ } catch (FileNotFoundException e)
+ {
+ System.out.println("File Not Found! File Not Found Exception");
+ return false;
+ }
+ catch (IOException e)
+ {
+ System.out.println("File Not Found! IO Exception");
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/capstone/app/DocReader.java b/src/main/java/capstone/app/DocReader.java
index 26731a6..4619859 100755
--- a/src/main/java/capstone/app/DocReader.java
+++ b/src/main/java/capstone/app/DocReader.java
@@ -5,11 +5,6 @@
*/
package capstone.app;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.util.ArrayList;
/**
diff --git a/src/main/java/capstone/app/FhirMapper.java b/src/main/java/capstone/app/FhirMapper.java
index efda90c..db58a01 100755
--- a/src/main/java/capstone/app/FhirMapper.java
+++ b/src/main/java/capstone/app/FhirMapper.java
@@ -5,15 +5,12 @@
*/
package capstone.app;
-import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.dstu2.composite.AddressDt;
-import ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Observation;
-import ca.uhn.fhir.model.dstu2.resource.Observation.Component;
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
import ca.uhn.fhir.model.dstu2.resource.Practitioner.PractitionerRole;
import ca.uhn.fhir.model.dstu2.resource.Practitioner.Qualification;
@@ -40,9 +37,9 @@ public boolean exists(String NPI)
public void createPractitioner(DocData data)
{
- ArrayList addresses = new ArrayList(); //addresses requires an array argument
- ArrayList roles = new ArrayList(); // practitioner role resouce requires an array of roles
- ArrayList descriptions = new ArrayList(); // practitioner healthcareServiceProvided also requires an array aof healthCareServices provided
+ ArrayList addresses = new ArrayList(); //addresses requires an array argument
+ ArrayList roles = new ArrayList(); // practitioner role resouce requires an array of roles
+ ArrayList descriptions = new ArrayList(); // practitioner healthcareServiceProvided also requires an array aof healthCareServices provided
Qualification credential;
@@ -80,10 +77,10 @@ else if(data.get_nppes_provider_gende().equals("F")) // gender of Female
practitioner.setGender(AdministrativeGenderEnum.UNKNOWN);
}
- performers = new ArrayList(); // make the array list a new one to empty it for the new practitioner
+ performers = new ArrayList(); // make the array list a new one to empty it for the new practitioner
performers.add(new ResourceReferenceDt(practitioner)); // put the practitioner in as a performer
- observations = new ArrayList(); // clear the observations array for the new practitioner
+ observations = new ArrayList(); // clear the observations array for the new practitioner
Observation observation = new Observation();
observation.setPerformer(performers);
@@ -146,6 +143,7 @@ else if(data.get_nppes_provider_gende().equals("F")) // gender of Female
public void addAttributes(DocData data)
{
+ observations = new ArrayList();
Observation observation = new Observation();
observation.setPerformer(performers);
observation.setCode(new CodeableConceptDt("system", "average_Medicare_allowed_amt")); //according to HAPI documentation, this is where the name goes
diff --git a/src/main/java/capstone/app/FhirPrinter.java b/src/main/java/capstone/app/FhirPrinter.java
index e6baa0c..5b5df12 100755
--- a/src/main/java/capstone/app/FhirPrinter.java
+++ b/src/main/java/capstone/app/FhirPrinter.java
@@ -13,9 +13,13 @@
*/
public class FhirPrinter
{
- public void outputResource(Practitioner dr)
+ public void outputResource(Practitioner dr, String Filename)
{
- // write resource to file
+ // open file (does it exist yet?)
+
+ // append resource to end of file
+
+ // close file
}
}
diff --git a/src/main/java/capstone/app/HAPI_Playground.java b/src/main/java/capstone/app/HAPI_Playground.java
index c33b127..a9358d4 100755
--- a/src/main/java/capstone/app/HAPI_Playground.java
+++ b/src/main/java/capstone/app/HAPI_Playground.java
@@ -9,12 +9,8 @@
import ca.uhn.fhir.model.dstu2.composite.AddressDt;
import ca.uhn.fhir.model.dstu2.composite.ContactPointDt;
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
-import ca.uhn.fhir.model.dstu2.resource.Practitioner.PractitionerRole;
import java.util.ArrayList;
-import java.util.List;
@@ -29,7 +25,7 @@ public static void main(String[] args)
Practitioner dr = new Practitioner();
dr.setId("1234556789");
dr.setName(new HumanNameDt().addGiven("John").addFamily("Doe"));
- ArrayList addresses = new ArrayList();
+ ArrayList addresses = new ArrayList();
addresses.add(new AddressDt());
addresses.get(0).addLine("1408 Hitchcock Lane").setCity("Bethlehem").setState("PA").setPostalCode("12345"); //addresses can only be set in form of list
dr.setAddress(addresses);
diff --git a/src/main/java/capstone/app/Main.java b/src/main/java/capstone/app/Main.java
index 468cd1d..7819b5c 100755
--- a/src/main/java/capstone/app/Main.java
+++ b/src/main/java/capstone/app/Main.java
@@ -1,19 +1,5 @@
package capstone.app;
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.resource.Composition;
-import ca.uhn.fhir.model.dstu2.resource.Composition.Section;
-import ca.uhn.fhir.model.dstu2.valueset.NameUseEnum;
-import ca.uhn.fhir.parser.IParser;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
/**
* Hello HAPI!
*
@@ -22,99 +8,9 @@ public class Main
{
public static void main( String[] args )
{
- // Alternately, create a context for DSTU2
- FhirContext ctx = FhirContext.forDstu2();
-
- // The following is an example Patient resource
- String msgString = ""
- + "John Cardinal
"
- + ""
- + ""
- + "
"
- + ""
- + "";
-
- // The hapi context object is used to create a new XML parser
- // instance. The parser can then be used to parse (or unmarshall) the
- // string message into a Patient object
- IParser parser = ctx.newXmlParser();
- Patient patient = parser.parseResource(Patient.class, msgString);
-
- // The patient object has accessor methods to retrieve all of the
- // data which has been parsed into the instance.
- String patientId = patient.getIdentifier().get(0).getValue();
- String familyName = patient.getName().get(0).getFamily().get(0).getValue();
- String gender = patient.getGender();
-
- System.out.println(patientId); // PRP1660
- System.out.println(familyName); // Cardinal
- System.out.println(gender); // M
-
-
- /**
- * FHIR model types in HAPI are simple POJOs. To create a new
- * one, invoke the default constructor and then
- * start populating values.
- */
- Patient patient2 = new Patient();
-
- // Add an MRN (a patient identifier)
- IdentifierDt id = patient2.addIdentifier();
- id.setSystem("http://example.com/fictitious-mrns");
- id.setValue("MRN001");
-
- // Add a name
- HumanNameDt name = patient2.addName();
- name.setUse(NameUseEnum.OFFICIAL);
- name.addFamily("Tester");
- name.addGiven("John");
- name.addGiven("Q");
-
-
- Composition comp= new Composition();
-
- Section sect= new Section();
-
- // We can now use a parser to encode this resource into a string.
- String encoded = ctx.newXmlParser().encodeResourceToString(patient2);
- System.out.println(encoded);
-//-----------------------------------------------------------------------------------------------------------------------------------
-// Our Code Starts here, I left above code so we could still see the example stuff while we are still playing
- DocReader reader = new DocReader();
- FhirMapper mapper = new FhirMapper();
- FhirPrinter printer = new FhirPrinter();
- DocData data = null;
- boolean passedFirstIteration = false;
-
- try
- {
- FileInputStream inputStream = new FileInputStream("\\docgraph\\Medicare-Physician-and-Other-Supplier-PUF-CY2012-head.txt"); //put filename here
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
-
- String line;
- while ((line = bufferedReader.readLine()) != null) // going to go through each line of the file
- {
- data = reader.processLine(line); // put a line into a DocData Element
- if(passedFirstIteration == true && mapper.exists(data.get_NPI()) == false) //if we passed the first line and the NPI's don't match meaning we found a new doctor or first one
- {
- printer.outputResource(mapper.getResource()); // before overriding, output the current resource to a file if there is one to print
- mapper.createPractitioner(data); // mapper will use all fields for the practitioner
- }
- else // the NPI's match so we keep adding observations to the practitioner resource
- {
- mapper.addAttributes(data); //having mapper add just the necessary fields to the practitioner
- }
-
- passedFirstIteration = true; // we now know there will always exist a resource from now until the end.
- }
- } catch (FileNotFoundException e)
- {
- System.out.println("File Not Found! File Not Found Exception");
- }
- catch (IOException e)
- {
- System.out.println("File Not Found! IO Exception");
- }
+
+ DocFhir.convertDocGraphData("\\docgraph\\Medicare-Physician-and-Other-Supplier-PUF-CY2012-head.txt");
}
+
}
diff --git a/src/test/Readme.txt b/src/test/Readme.txt
new file mode 100755
index 0000000..cbd34c9
--- /dev/null
+++ b/src/test/Readme.txt
@@ -0,0 +1,10 @@
+README
+
+In order to test the final output of DocFhir:
+
+1) Add docgraph test data to the test inputs folder
+
+2) Add an expected result to test expected outputs folder.
+ Use the same filename as your input file, whitespace will be ignored.
+ If you do not specify an expected output, then the file will be converted
+ but the testing will skip verifying the programs output as correct.
\ No newline at end of file
diff --git a/src/test/java/capstone/app/AppTest.java b/src/test/java/capstone/app/AppTest.java
index 54b377d..5facb8d 100755
--- a/src/test/java/capstone/app/AppTest.java
+++ b/src/test/java/capstone/app/AppTest.java
@@ -30,7 +30,7 @@ public void testApp()
}
/**
- * Tests FHIRWriter when reading in data from medicare data to make sure it
+ * Tests DocReader when reading in data from medicare data to make sure it
* gets 27 fields of data.
*
* @throws IOException
@@ -38,14 +38,14 @@ public void testApp()
@Test
public void testFHIRwriter27Items() throws IOException
{
+ //readIn does not exist anymore
+ //FW.readIn("src/test/test files/TestFieldData.txt");
- FW.readIn("src/test/test files/TestFieldData.txt");
-
- assertEquals(27, FW.getFields().size());
+ //assertEquals(27, FW.getFields().size());
}
/**
- * Test FHIRWriter when reading in data from ha1c data to make sure it gets
+ * Test DocReader when reading in data from ha1c data to make sure it gets
* 16 fields of data.
* Uncomment test once parser has been updated to read in this data.
*
@@ -60,7 +60,7 @@ public void testFHIRwriter27Items() throws IOException
// assertEquals(16,FW.getFields().size());
// }
/**
- * Test FHIRWriter when reading in data from medicare data to make
+ * Test DocReader when reading in data from medicare data to make
* sure the data is read in the proper order.
*
* @throws IOException
@@ -96,8 +96,9 @@ public void testFHIRWriterMedCorrectOrder() throws IOException
testData.add("0");
testData.add("123.45678901");
testData.add("1.2345678901");
-
- FW.readIn("src/test/test files/TestFieldData.txt");
+
+ //readIn does not exist anymore
+ //FW.readIn("src/test/test files/TestFieldData.txt");
for (int i = 0; i < FW.getFields().size(); i++)
{
diff --git a/src/test/java/capstone/app/FileConversionTest.java b/src/test/java/capstone/app/FileConversionTest.java
new file mode 100755
index 0000000..7c8a9f0
--- /dev/null
+++ b/src/test/java/capstone/app/FileConversionTest.java
@@ -0,0 +1,63 @@
+package capstone.app;
+
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.*;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+
+public class FileConversionTest extends XMLTestCase{
+
+ @Before
+ public void Setup()
+ {
+ //ignore whitespace in XML
+ XMLUnit.setIgnoreWhitespace(true);
+ }
+
+ /**
+ * Convert all files given in the testing folder. Then compare those files to the expected if one exists.
+ */
+ @Test
+ public void testFileConversion()
+ {
+
+ // loop through all files in test inputs
+ File test_dir = new File("src\\test\\test inputs\\");
+
+ for (File test_file : test_dir.listFiles()){
+ System.out.println(test_file.getAbsolutePath());
+ boolean file_converted = convertTestFile(test_file);
+ //if we converted the file, and
+ if(file_converted ){
+ try {
+ // if a correct results file exists to compare
+ if(new File("\\test\\test expected outputs\\" + test_file.getName()).exists()) {
+ assertXMLEqual("\\test\\test outputs\\" + test_file.getName(),
+ "\\test\\test expected outputs\\" + test_file.getName());
+ }
+ System.out.println("Success");
+ } catch (SAXException e) {
+ e.printStackTrace();
+ fail("Some failure on vserification");
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("I/O failure on verification");
+ }
+ }else{
+ fail("File not successfully converted");
+ }
+ }
+
+ }
+
+ private boolean convertTestFile(File test_file){
+ String out_path = "\\test\\test outputs\\" + test_file.getName();
+
+ return DocFhir.convertDocGraphData(test_file.getAbsolutePath(), out_path);
+
+ }
+
+}
diff --git a/src/test/test expected outputs/TestFieldData.txt b/src/test/test expected outputs/TestFieldData.txt
new file mode 100755
index 0000000..4f3a1ed
--- /dev/null
+++ b/src/test/test expected outputs/TestFieldData.txt
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/test/test files/TestFieldData.txt b/src/test/test inputs/TestFieldData.txt
similarity index 100%
rename from src/test/test files/TestFieldData.txt
rename to src/test/test inputs/TestFieldData.txt
diff --git a/src/test/test outputs/TestFieldData.txt b/src/test/test outputs/TestFieldData.txt
new file mode 100755
index 0000000..266e4b1
--- /dev/null
+++ b/src/test/test outputs/TestFieldData.txt
@@ -0,0 +1 @@
+
\ No newline at end of file