Skip to content

Commit

Permalink
Merge pull request #27 from lisadier/codereview_0510
Browse files Browse the repository at this point in the history
Addressed code review comments
  • Loading branch information
klwhaley authored May 10, 2021
2 parents e6ab635 + e6b6e05 commit d53e95b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -187,10 +187,6 @@ public void multipleOBXWithNoId() throws IOException {
HL7ToFHIRConverter ftv = new HL7ToFHIRConverter();
String json = ftv.convert(new File("../hl7v2-fhir-converter/src/test/resources/ORU-multiline-short.hl7"), OPTIONS_PRETTYPRINT);

System.out.println("-----------------------------------------------------");
System.out.println(json);
System.out.println("-----------------------------------------------------");

//Verify conversion
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
Expand Down Expand Up @@ -239,18 +235,79 @@ public void multipleOBXWithNoId() throws IOException {
Assert.assertTrue("Incorrect content type", a.getContentType().equalsIgnoreCase("text"));
Assert.assertTrue("Incorrect language", a.getLanguage().equalsIgnoreCase("en"));

//TODO: Validate data by decoding
//Assert.assertTrue("Incorrect data", Base64.getDecoder().decode((a.getData())).equals("~[PII] Emergency Department~ED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:~"));
//Base64.getEncoder().encodeToString(val.getBytes());
//Verify data attachment after decoding
String decoded = new String(Base64.getDecoder().decode(a.getDataElement().getValueAsString()));
Assert.assertTrue("Incorrect data", decoded.equals("~[PII] Emergency Department~ED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:~"));

Assert.assertTrue("Incorrect title", a.getTitle().equalsIgnoreCase("ECHO CARDIOGRAM COMPLETE"));

//TODO: validate date
// System.out.println(OffsetDateTime.of(2020, 8, 2, 12, 44, 55, 0, ZoneOffset.of("+08:00")));
// Assert.assertTrue("Incorrect creation date", a.getCreation().equals("2020-08-02T12.44:55+08.00"));
//Verify creation data is persisted correctly - 2020-08-02T12:44:55+08:00
Calendar c = Calendar.getInstance();
c.clear(); // needed to completely clear out calendar object
c.set(2020, 7, 2, 12, 44, 55);
c.setTimeZone(TimeZone.getTimeZone(ZoneId.of("+08:00")));

Date d = c.getTime();
Assert.assertTrue("Incorrect creation date", a.getCreation().equals(d));

}

/**
*
* Verifies ORU messages with mixed OBX types
*
* @throws IOException
*/
@Test
public void multipleOBXWithMixedType() throws IOException {
HL7ToFHIRConverter ftv = new HL7ToFHIRConverter();
String json = ftv.convert(new File("../hl7v2-fhir-converter/src/test/resources/ORU-multiline-short-mixed.hl7"), OPTIONS_PRETTYPRINT);

//Verify conversion
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
Bundle b = (Bundle) bundleResource;

Assert.assertTrue("Bundle type not expected", b.getType() == BundleType.COLLECTION);
b.getId();
b.getMeta().getLastUpdated();

List<BundleEntryComponent> e = b.getEntry();

List<Resource> patientResource = e.stream()
.filter(v -> ResourceType.Patient == v.getResource().getResourceType())
.map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(patientResource).hasSize(1);

List<Resource> organizationResource = e.stream()
.filter(v -> ResourceType.Organization == v.getResource().getResourceType())
.map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(organizationResource).hasSize(1);

List<Resource> messageHeader = e.stream()
.filter(v -> ResourceType.MessageHeader == v.getResource().getResourceType())
.map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(messageHeader).hasSize(1);

//Verify one observations is created
List<Resource> obsResource = e.stream()
.filter(v -> ResourceType.Observation == v.getResource().getResourceType())
.map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);

//Verify Diagnostic Report is created as expected
List<Resource> reportResource = e.stream()
.filter(v -> ResourceType.DiagnosticReport == v.getResource().getResourceType())
.map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(reportResource).hasSize(1);

DiagnosticReport report = (DiagnosticReport) reportResource.get(0);

//No attachment created since OBX with TX and no id is not first
List<Attachment> attachments = report.getPresentedForm();
Assert.assertTrue("Unexpected number of attachments", attachments.size() == 0);
}

private static DiagnosticReport getResource(Resource resource) {
String s = context.getParser().encodeResourceToString(resource);
Class<? extends IBaseResource> klass = DiagnosticReport.class;
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/ORU-multiline-short-mixed.hl7
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MSH|^~\&|WHI_Automation|IBM_Toronto_Lab|IMAGING_REPORT|Hartland|20200802124455||ORU^R01^ORU_R01|MSGID00231|T|2.6||||||||||||^4086::132:2A57:3C28^IPv6
PID|1||0d70c6c8^^^MRN||Patient^Autogenerated||19630306|M||Caucasian|^^^^L6G 1C7~^^^ON~^^Unionville~&Warden Av~8200~^^^^^^B||^^^^^^4042808~^^^^^905~^^^^001|||Married|Baptist|Account_0d70c6c8
NTE|1||Created for MRN: 0d70c6c8
PV1|1|I|^^^Toronto^^^8200 Warden Av|EM|||2905^Langa^Albert^J^IV||0007^SINGH^BALDEV||||||||5755^Kuczma^Sean^^Jr||Visit_0d70c6c8|||||||||||||||||||||||||20200802124455||||||||ABC
OBR|1|PON_0d70c6c8^LAB|FON_0d70c6c8^LAB|1487^ECHO CARDIOGRAM COMPLETE||20200802124455|20200802124455|||||||||OP_0d70c6c8^SINGH^BALDEV||||||||CT|F|||COP_0d70c6c8^GARCIA^LUIS
OBX|1|ST|12345||||||||F|||20200802124455
OBX|2|TX|||||||||F|||20200802124455
OBX|3|TX|||[PII] Emergency Department||||||F|||20200802124455
OBX|4|TX|||ED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:||||||F|||20200802124455

0 comments on commit d53e95b

Please sign in to comment.