From 6a3041bbefdd812c5ab0e0fb020947217e145fc6 Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Sun, 5 Jun 2016 19:49:41 -0400 Subject: [PATCH 01/12] Code cleanup: now the main method is just 1 line calling a static method from the class DocFhir. This change serves to de-couple the file conversion code from the container running it. --- src/main/java/capstone/app/DocFhir.java | 48 ++++++++ src/main/java/capstone/app/Main.java | 146 ++++++++++-------------- src/test/java/capstone/app/AppTest.java | 6 +- 3 files changed, 109 insertions(+), 91 deletions(-) create mode 100755 src/main/java/capstone/app/DocFhir.java diff --git a/src/main/java/capstone/app/DocFhir.java b/src/main/java/capstone/app/DocFhir.java new file mode 100755 index 0000000..83d16ee --- /dev/null +++ b/src/main/java/capstone/app/DocFhir.java @@ -0,0 +1,48 @@ +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 void convertDocGraphData(String filepath){ + DocReader reader = new DocReader(); + FhirMapper mapper = new FhirMapper(); + FhirPrinter printer = new FhirPrinter(); + DocData data = null; + boolean passedFirstIteration = false; + + try + { + FileInputStream inputStream = new FileInputStream(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()); // 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"); + } + } +} diff --git a/src/main/java/capstone/app/Main.java b/src/main/java/capstone/app/Main.java index 468cd1d..808d4d8 100755 --- a/src/main/java/capstone/app/Main.java +++ b/src/main/java/capstone/app/Main.java @@ -22,99 +22,69 @@ public class Main { public static void main( String[] args ) { - // Alternately, create a context for DSTU2 - FhirContext ctx = FhirContext.forDstu2(); + + DocFhir.convertDocGraphData("\\docgraph\\Medicare-Physician-and-Other-Supplier-PUF-CY2012-head.txt"); - // The following is an example Patient resource - String msgString = "" - + "
John Cardinal
" - + "" - + "" - + "" - + "
" - + "
"; + } + /** + * This method is copied example code, replace this with main for debugging import issues + */ + private static void example(){ + // Alternately, create a context for DSTU2 + FhirContext ctx = FhirContext.forDstu2(); - // 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 following is an example Patient resource + String msgString = "" + + "
John Cardinal
" + + "" + + "" + + "" + + "
" + + "
"; - // 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(); + // 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); - System.out.println(patientId); // PRP1660 - System.out.println(familyName); // Cardinal - System.out.println(gender); // M - + // 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(); - /** - * 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"); - } + 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); } } diff --git a/src/test/java/capstone/app/AppTest.java b/src/test/java/capstone/app/AppTest.java index 54b377d..e6fbb71 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 @@ -45,7 +45,7 @@ public void testFHIRwriter27Items() throws IOException } /** - * 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 From 9a6436f7d87e5cfcc49b63d22fb4a6b6e9e2f0d3 Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Sun, 5 Jun 2016 20:24:24 -0400 Subject: [PATCH 02/12] Added String filename to outputResource. We need to know what file to add it to. In fact, it should probably take a File output_file instead. --- src/main/java/capstone/app/FhirPrinter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/capstone/app/FhirPrinter.java b/src/main/java/capstone/app/FhirPrinter.java index e6baa0c..50e60ca 100755 --- a/src/main/java/capstone/app/FhirPrinter.java +++ b/src/main/java/capstone/app/FhirPrinter.java @@ -13,7 +13,7 @@ */ public class FhirPrinter { - public void outputResource(Practitioner dr) + public void outputResource(Practitioner dr, String Filename) { // write resource to file } From 716c60d79f918d70728be2b011f23ab19bdfbbd3 Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Sun, 5 Jun 2016 21:31:19 -0400 Subject: [PATCH 03/12] Added String out_filepath to convertDocGraphData. Overloaded method to use a destination file of (original)-FHIR.xml if out_filepath is not given. --- src/main/java/capstone/app/DocFhir.java | 13 ++++++++++--- src/test/java/capstone/app/RunTestCases.java | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100755 src/test/java/capstone/app/RunTestCases.java diff --git a/src/main/java/capstone/app/DocFhir.java b/src/main/java/capstone/app/DocFhir.java index 83d16ee..8e2abe3 100755 --- a/src/main/java/capstone/app/DocFhir.java +++ b/src/main/java/capstone/app/DocFhir.java @@ -7,8 +7,14 @@ import java.io.InputStreamReader; public class DocFhir { + + public static void convertDocGraphData(String in_filepath){ + + convertDocGraphData(in_filepath, in_filepath + "-FHIR.xml"); + + } - public static void convertDocGraphData(String filepath){ + public static void convertDocGraphData(String in_filepath, String out_filepath){ DocReader reader = new DocReader(); FhirMapper mapper = new FhirMapper(); FhirPrinter printer = new FhirPrinter(); @@ -17,7 +23,7 @@ public static void convertDocGraphData(String filepath){ try { - FileInputStream inputStream = new FileInputStream(filepath); //put filename here + FileInputStream inputStream = new FileInputStream(in_filepath); //put filename here BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; @@ -26,7 +32,8 @@ public static void convertDocGraphData(String filepath){ 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 + 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 diff --git a/src/test/java/capstone/app/RunTestCases.java b/src/test/java/capstone/app/RunTestCases.java new file mode 100755 index 0000000..51e37ac --- /dev/null +++ b/src/test/java/capstone/app/RunTestCases.java @@ -0,0 +1,5 @@ +package capstone.app; + +public class RunTestCases { + +} From b7374cd4ced0893bd8a7b50fe59df2fd7f92bc1c Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 01:19:37 -0400 Subject: [PATCH 04/12] Added beginings of testing harness: now convertDocGraph data method of DocFhir returns a success/fail boolean. --- src/main/java/capstone/app/DocFhir.java | 10 +++-- src/test/java/capstone/app/RunTestCases.java | 40 +++++++++++++++++++ .../TestFieldData.txt | 0 3 files changed, 47 insertions(+), 3 deletions(-) rename src/test/{test files => test inputs}/TestFieldData.txt (100%) diff --git a/src/main/java/capstone/app/DocFhir.java b/src/main/java/capstone/app/DocFhir.java index 8e2abe3..b9f0528 100755 --- a/src/main/java/capstone/app/DocFhir.java +++ b/src/main/java/capstone/app/DocFhir.java @@ -8,13 +8,13 @@ public class DocFhir { - public static void convertDocGraphData(String in_filepath){ + public static boolean convertDocGraphData(String in_filepath){ - convertDocGraphData(in_filepath, in_filepath + "-FHIR.xml"); + return convertDocGraphData(in_filepath, in_filepath + "-FHIR.xml"); } - public static void convertDocGraphData(String in_filepath, String out_filepath){ + public static boolean convertDocGraphData(String in_filepath, String out_filepath){ DocReader reader = new DocReader(); FhirMapper mapper = new FhirMapper(); FhirPrinter printer = new FhirPrinter(); @@ -43,13 +43,17 @@ public static void convertDocGraphData(String in_filepath, String out_filepath){ passedFirstIteration = true; // we now know there will always exist a resource from now until the end. } + 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/test/java/capstone/app/RunTestCases.java b/src/test/java/capstone/app/RunTestCases.java index 51e37ac..ec5799e 100755 --- a/src/test/java/capstone/app/RunTestCases.java +++ b/src/test/java/capstone/app/RunTestCases.java @@ -1,5 +1,45 @@ package capstone.app; +import org.junit.*; +import static org.junit.Assert.*; + +import java.io.File; + public class RunTestCases { + + /** + * Convert all files given in the testing folder. Then compare those files to the expected if one exists. + */ + @Test + public void runTestFiles() + { + // loop through all files in test inputs + File test_dir = new File("\\test\\test inputs"); + for (File test_file : test_dir.listFiles()){ + + boolean file_converted = convertTestFile(test_file); + + if(file_converted){ + assertTrue(checkFileResult(test_file)); + }else{ + fail("File not successfully converted"); + } + } + + } + private boolean convertTestFile(File test_file){ + String in_path = test_file.getAbsolutePath(); + String out_path = in_path + "-output.xml"; + + return DocFhir.convertDocGraphData(in_path, out_path); + + } + + + private boolean checkFileResult(File test_file) { + // TODO Auto-generated method stub + return true; + } + } 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 From d5856aa4f4a8214cda86ba434690e9d835ba266f Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 21:43:45 -0400 Subject: [PATCH 05/12] Added comment to FhirPrinter for whoever is going to implement it. --- src/main/java/capstone/app/FhirPrinter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/capstone/app/FhirPrinter.java b/src/main/java/capstone/app/FhirPrinter.java index 50e60ca..5b5df12 100755 --- a/src/main/java/capstone/app/FhirPrinter.java +++ b/src/main/java/capstone/app/FhirPrinter.java @@ -15,7 +15,11 @@ public class FhirPrinter { 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 } } From 8ac1fcf18a117a9eb21d320b8c52c0e7aea0d685 Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 22:03:30 -0400 Subject: [PATCH 06/12] Had to remove tests that currently exist, as they are calling non-existant API methods. Also, added apache commons-io to dependency. --- pom.xml | 9 ++++++++- src/test/java/capstone/app/AppTest.java | 11 ++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 085ae18..8bd0de8 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,14 @@ 4.4.4 - + + + + commons-io + commons-io + 2.4 + + diff --git a/src/test/java/capstone/app/AppTest.java b/src/test/java/capstone/app/AppTest.java index e6fbb71..5facb8d 100755 --- a/src/test/java/capstone/app/AppTest.java +++ b/src/test/java/capstone/app/AppTest.java @@ -38,10 +38,10 @@ 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()); } /** @@ -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++) { From ef82627243e35b09146480bc0f16126fb3e1ac3d Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 22:06:38 -0400 Subject: [PATCH 07/12] Removing unused imports, unused methods, and closing bufferedReader streams. --- src/main/java/capstone/app/DocFhir.java | 1 + src/main/java/capstone/app/DocReader.java | 5 -- src/main/java/capstone/app/FhirMapper.java | 13 ++-- .../java/capstone/app/HAPI_Playground.java | 6 +- src/main/java/capstone/app/Main.java | 76 +------------------ 5 files changed, 8 insertions(+), 93 deletions(-) diff --git a/src/main/java/capstone/app/DocFhir.java b/src/main/java/capstone/app/DocFhir.java index b9f0528..2443ba2 100755 --- a/src/main/java/capstone/app/DocFhir.java +++ b/src/main/java/capstone/app/DocFhir.java @@ -43,6 +43,7 @@ public static boolean convertDocGraphData(String in_filepath, String out_filepat passedFirstIteration = true; // we now know there will always exist a resource from now until the end. } + bufferedReader.close(); return true; } catch (FileNotFoundException e) 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..02b662a 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); 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 808d4d8..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! * @@ -26,65 +12,5 @@ public static void main( String[] args ) DocFhir.convertDocGraphData("\\docgraph\\Medicare-Physician-and-Other-Supplier-PUF-CY2012-head.txt"); } - /** - * This method is copied example code, replace this with main for debugging import issues - */ - private static void example(){ - // 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); - } + } From 7b870c617a16eeca95d90432928f95ec45972ddd Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 23:44:28 -0400 Subject: [PATCH 08/12] Added initialization of oberservations array. If initialization is required, there should be a method constructor that does this. Currently, instance initalization seems to be a seperate method from the constructor, which is confusing and causes errors. --- src/main/java/capstone/app/FhirMapper.java | 1 + .../capstone/app/{RunTestCases.java => FileConversionTest.java} | 0 2 files changed, 1 insertion(+) rename src/test/java/capstone/app/{RunTestCases.java => FileConversionTest.java} (100%) diff --git a/src/main/java/capstone/app/FhirMapper.java b/src/main/java/capstone/app/FhirMapper.java index 02b662a..db58a01 100755 --- a/src/main/java/capstone/app/FhirMapper.java +++ b/src/main/java/capstone/app/FhirMapper.java @@ -143,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/test/java/capstone/app/RunTestCases.java b/src/test/java/capstone/app/FileConversionTest.java similarity index 100% rename from src/test/java/capstone/app/RunTestCases.java rename to src/test/java/capstone/app/FileConversionTest.java From 960b78268ca76c90594a2c7fc10dceaf0e847dca Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 23:48:52 -0400 Subject: [PATCH 09/12] Added testing harness, but lacking user documentation currently. Using XMLUnit to compare FHIR xml while ignoring whitespace (which is irrelavent to xml). --- .../java/capstone/app/FileConversionTest.java | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/test/java/capstone/app/FileConversionTest.java b/src/test/java/capstone/app/FileConversionTest.java index ec5799e..de2ff3e 100755 --- a/src/test/java/capstone/app/FileConversionTest.java +++ b/src/test/java/capstone/app/FileConversionTest.java @@ -1,26 +1,50 @@ package capstone.app; +import org.custommonkey.xmlunit.XMLTestCase; +import org.custommonkey.xmlunit.XMLUnit; import org.junit.*; -import static org.junit.Assert.*; +import org.xml.sax.SAXException; import java.io.File; +import java.io.IOException; -public class RunTestCases { +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 runTestFiles() + public void testFileConversion() { + // loop through all files in test inputs - File test_dir = new File("\\test\\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(file_converted){ - assertTrue(checkFileResult(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()); + } + } 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"); } @@ -29,17 +53,10 @@ public void runTestFiles() } private boolean convertTestFile(File test_file){ - String in_path = test_file.getAbsolutePath(); - String out_path = in_path + "-output.xml"; + String out_path = "\\test\\test outputs\\" + test_file.getName(); - return DocFhir.convertDocGraphData(in_path, out_path); + return DocFhir.convertDocGraphData(test_file.getAbsolutePath(), out_path); } - - - private boolean checkFileResult(File test_file) { - // TODO Auto-generated method stub - return true; - } } From 107589629c1dc429482f9c0cce010f8382056d6e Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Mon, 6 Jun 2016 23:49:22 -0400 Subject: [PATCH 10/12] Added XMLUnit dependency. --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 8bd0de8..6628fae 100644 --- a/pom.xml +++ b/pom.xml @@ -94,12 +94,12 @@ 4.4.4 - - + + - commons-io - commons-io - 2.4 + xmlunit + xmlunit + 1.6 From 5109484f6e9123d2cde29da3e2e13e29e0810e9b Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Tue, 7 Jun 2016 13:41:21 -0400 Subject: [PATCH 11/12] Added a readme for testing. --- src/test/Readme.txt | 10 ++++++++++ src/test/test expected outputs/TestFieldData.txt | 4 ++++ src/test/test outputs/TestFieldData.txt | 1 + 3 files changed, 15 insertions(+) create mode 100755 src/test/Readme.txt create mode 100755 src/test/test expected outputs/TestFieldData.txt create mode 100755 src/test/test outputs/TestFieldData.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/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 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 From 6beb7690baad3d433c4011a4481cbcbee5b071b0 Mon Sep 17 00:00:00 2001 From: Vincent Pillinger Date: Tue, 7 Jun 2016 13:42:15 -0400 Subject: [PATCH 12/12] Added success message. --- src/test/java/capstone/app/FileConversionTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/capstone/app/FileConversionTest.java b/src/test/java/capstone/app/FileConversionTest.java index de2ff3e..7c8a9f0 100755 --- a/src/test/java/capstone/app/FileConversionTest.java +++ b/src/test/java/capstone/app/FileConversionTest.java @@ -38,6 +38,7 @@ public void testFileConversion() 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");