Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Testing Harness #6

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@
<version>4.4.4</version>
</dependency>


<!-- XMLUnit for unit testing -->
<!-- http://mvnrepository.com/artifact/xmlunit/xmlunit -->
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>

</dependencies>

</project>
60 changes: 60 additions & 0 deletions src/main/java/capstone/app/DocFhir.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
5 changes: 0 additions & 5 deletions src/main/java/capstone/app/DocReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/capstone/app/FhirMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,9 +37,9 @@ public boolean exists(String NPI)

public void createPractitioner(DocData data)
{
ArrayList<AddressDt> addresses = new ArrayList(); //addresses requires an array argument
ArrayList<PractitionerRole> roles = new ArrayList(); // practitioner role resouce requires an array of roles
ArrayList<ResourceReferenceDt> descriptions = new ArrayList(); // practitioner healthcareServiceProvided also requires an array aof healthCareServices provided
ArrayList<AddressDt> addresses = new ArrayList<AddressDt>(); //addresses requires an array argument
ArrayList<PractitionerRole> roles = new ArrayList<PractitionerRole>(); // practitioner role resouce requires an array of roles
ArrayList<ResourceReferenceDt> descriptions = new ArrayList<ResourceReferenceDt>(); // practitioner healthcareServiceProvided also requires an array aof healthCareServices provided
Qualification credential;


Expand Down Expand Up @@ -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<ResourceReferenceDt>(); // 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<Observation>(); // clear the observations array for the new practitioner

Observation observation = new Observation();
observation.setPerformer(performers);
Expand Down Expand Up @@ -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 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
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/capstone/app/FhirPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
6 changes: 1 addition & 5 deletions src/main/java/capstone/app/HAPI_Playground.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;



Expand All @@ -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<AddressDt> addresses = new ArrayList();
ArrayList<AddressDt> addresses = new ArrayList<AddressDt>();
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);
Expand Down
110 changes: 3 additions & 107 deletions src/main/java/capstone/app/Main.java
Original file line number Diff line number Diff line change
@@ -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!
*
Expand All @@ -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 = "<Patient xmlns=\"http://hl7.org/fhir\">"
+ "<text><status value=\"generated\" /><div xmlns=\"http://www.w3.org/1999/xhtml\">John Cardinal</div></text>"
+ "<identifier><system value=\"http://orionhealth.com/mrn\" /><value value=\"PRP1660\" /></identifier>"
+ "<name><use value=\"official\" /><family value=\"Cardinal\" /><given value=\"John\" /></name>"
+ "<gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\" /><code value=\"M\" /></coding></gender>"
+ "<address><use value=\"home\" /><line value=\"2222 Home Street\" /></address><active value=\"true\" />"
+ "</Patient>";

// 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");

}

}
10 changes: 10 additions & 0 deletions src/test/Readme.txt
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 9 additions & 8 deletions src/test/java/capstone/app/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ 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
*/
@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.
*
Expand All @@ -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
Expand Down Expand Up @@ -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++)
{
Expand Down
Loading