Merge pull request #89 from ahdis/oliveregger_cdacore20parseandtest
CDA Parsing tests with FHIRPath, ED datatype handling
This commit is contained in:
commit
6b1f345f6b
|
@ -40,6 +40,7 @@ import javax.xml.transform.sax.SAXSource;
|
||||||
import org.hl7.fhir.exceptions.DefinitionException;
|
import org.hl7.fhir.exceptions.DefinitionException;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||||
|
import org.hl7.fhir.r5.elementmodel.Element;
|
||||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||||
import org.hl7.fhir.r5.elementmodel.Element.SpecialElement;
|
import org.hl7.fhir.r5.elementmodel.Element.SpecialElement;
|
||||||
|
@ -244,8 +245,18 @@ public class XmlParser extends ParserBase {
|
||||||
if (!Utilities.noString(text)) {
|
if (!Utilities.noString(text)) {
|
||||||
Property property = getTextProp(properties);
|
Property property = getTextProp(properties);
|
||||||
if (property != null) {
|
if (property != null) {
|
||||||
context.getChildren().add(new Element(property.getName(), property, property.getType(), text).markLocation(line(node), col(node)));
|
if ("ED.data[x]".equals(property.getDefinition().getId())) {
|
||||||
} else {
|
if ("B64".equals(node.getAttribute("representation"))) {
|
||||||
|
context.getChildren().add(new Element("dataBase64Binary", property, "base64Binary", text).markLocation(line(node), col(node)));
|
||||||
|
} else {
|
||||||
|
context.getChildren().add(new Element("dataString", property, "string", text).markLocation(line(node), col(node)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.getChildren().add(
|
||||||
|
new Element(property.getName(), property, property.getType(), text).markLocation(line(node), col(node)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
logError(line(node), col(node), path, IssueType.STRUCTURE, "Text should not be present", IssueSeverity.ERROR);
|
logError(line(node), col(node), path, IssueType.STRUCTURE, "Text should not be present", IssueSeverity.ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.hl7.fhir.r5.test;
|
package org.hl7.fhir.r5.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -13,28 +16,119 @@ import org.hl7.fhir.r5.elementmodel.Element;
|
||||||
import org.hl7.fhir.r5.elementmodel.Manager;
|
import org.hl7.fhir.r5.elementmodel.Manager;
|
||||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||||
|
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||||
|
import org.hl7.fhir.r5.utils.FHIRPathEngine;
|
||||||
import org.hl7.fhir.utilities.cache.PackageCacheManager;
|
import org.hl7.fhir.utilities.cache.PackageCacheManager;
|
||||||
import org.hl7.fhir.utilities.cache.ToolsVersion;
|
import org.hl7.fhir.utilities.cache.ToolsVersion;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CDARoundTripTests {
|
public class CDARoundTripTests {
|
||||||
|
|
||||||
private SimpleWorkerContext context;
|
private SimpleWorkerContext context;
|
||||||
|
private FHIRPathEngine fp;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
context = new SimpleWorkerContext();
|
context = new SimpleWorkerContext();
|
||||||
PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||||
context.loadFromPackage(pcm.loadPackage("hl7.fhir.core"), null, "StructureDefinition");
|
context.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "dev"), null, "StructureDefinition");
|
||||||
context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda"), null, "StructureDefinition");
|
context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda", "dev"), null, "StructureDefinition");
|
||||||
|
fp = new FHIRPathEngine(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
public void testCDA() throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String fileSource = TestingUtilities.resourceNameToFile("cda", "cda-original.xml");
|
||||||
|
String roundTrip = TestingUtilities.resourceNameToFile("cda", "cda-roundtrip.xml");
|
||||||
|
String jsonRoundTrip = TestingUtilities.resourceNameToFile("cda", "cda-roundtrip.json");
|
||||||
|
|
||||||
|
Element e = Manager.parse(context, new FileInputStream(fileSource), FhirFormat.XML);
|
||||||
|
|
||||||
|
Manager.compose(context, e, new FileOutputStream(roundTrip), FhirFormat.XML, OutputStyle.PRETTY, null);
|
||||||
|
Manager.compose(context, e, new FileOutputStream(jsonRoundTrip), FhirFormat.JSON, OutputStyle.PRETTY, null);
|
||||||
|
|
||||||
|
// <typeId root="2.16.840.1.113883.1.3" extension="POCD_HD000040"/>
|
||||||
|
// assertEquals("POCD_HD000040", fp.evaluateToString(e, "typeId.extension"));
|
||||||
|
// assertEquals("2.16.840.1.113883.1.3", fp.evaluateToString(e, "typeId.root"));
|
||||||
|
// <templateId root="2.16.840.1.113883.3.27.1776"/>
|
||||||
|
// assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(e, "templateId.root"));
|
||||||
|
// <id extension="c266" root="2.16.840.1.113883.19.4"/>
|
||||||
|
assertEquals("2.16.840.1.113883.19.4", fp.evaluateToString(e, "id.root"));
|
||||||
|
assertEquals("c266", fp.evaluateToString(e, "id.extension"));
|
||||||
|
|
||||||
|
// <title>Good Health Clinic Consultation Note</title>
|
||||||
|
assertEquals("Good Health Clinic Consultation Note", fp.evaluateToString(e, "title.dataString"));
|
||||||
|
// <effectiveTime value="20000407"/>
|
||||||
|
assertEquals("2000-04-07", fp.evaluateToString(e, "effectiveTime.value"));
|
||||||
|
// <confidentialityCode code="N" codeSystem="2.16.840.1.113883.5.25"/>
|
||||||
|
assertEquals("N", fp.evaluateToString(e, "confidentialityCode.code"));
|
||||||
|
assertEquals("2.16.840.1.113883.5.25", fp.evaluateToString(e, "confidentialityCode.codeSystem"));
|
||||||
|
// <languageCode code="en-US"/>
|
||||||
|
assertEquals("en-US", fp.evaluateToString(e, "languageCode.code"));
|
||||||
|
// <setId extension="BB35" root="2.16.840.1.113883.19.7"/>
|
||||||
|
assertEquals("BB35", fp.evaluateToString(e, "setId.extension"));
|
||||||
|
assertEquals("2.16.840.1.113883.19.7", fp.evaluateToString(e, "setId.root"));
|
||||||
|
// <versionNumber value="2"/>
|
||||||
|
assertEquals("2", fp.evaluateToString(e, "versionNumber.value"));
|
||||||
|
// <recordTarget>
|
||||||
|
// <patientRole>
|
||||||
|
// <id extension="12345" root="2.16.840.1.113883.19.5"/>
|
||||||
|
assertEquals("12345", fp.evaluateToString(e, "recordTarget.patientRole.id.extension"));
|
||||||
|
assertEquals("2.16.840.1.113883.19.5", fp.evaluateToString(e, "recordTarget.patientRole.id.root"));
|
||||||
|
// <patient>
|
||||||
|
// <name>
|
||||||
|
// <family>Levin</family>
|
||||||
|
assertEquals("Levin", fp.evaluateToString(e, "recordTarget.patientRole.patient.name.family.dataString"));
|
||||||
|
// <given>Henry</given>
|
||||||
|
assertEquals("Henry", fp.evaluateToString(e, "recordTarget.patientRole.patient.name.given.dataString"));
|
||||||
|
// <suffix>the 7th</suffix>
|
||||||
|
// </name>
|
||||||
|
// <administrativeGenderCode code="M" codeSystem="2.16.840.1.113883.5.1"/>
|
||||||
|
// <birthTime value="19320924"/>
|
||||||
|
// </patient>
|
||||||
|
// <providerOrganization>
|
||||||
|
// <id root="2.16.840.1.113883.19.5"/>
|
||||||
|
// </providerOrganization>
|
||||||
|
// </patientRole>
|
||||||
|
// </recordTarget>
|
||||||
|
|
||||||
|
// <component>
|
||||||
|
// <structuredBody>
|
||||||
|
// <component>
|
||||||
|
// <section>
|
||||||
|
|
||||||
|
// <component>
|
||||||
|
// <section>
|
||||||
|
// <code code="8709-8" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>
|
||||||
|
// <title>Skin Exam</title>
|
||||||
|
// <text>Erythematous rash, palmar surface, left index finger.
|
||||||
|
// <renderMultiMedia referencedObject="MM1"/>
|
||||||
|
// </text>
|
||||||
|
|
||||||
|
assertEquals("Skin Exam", fp.evaluateToString(e, "component.structuredBody.component.section.component.section.where(code.code='8709-8' and code.codeSystem='2.16.840.1.113883.6.1').title.dataString"));
|
||||||
|
// <div>Erythematous rash, palmar surface, left index finger.
|
||||||
|
// <img src="MM1"/></div>
|
||||||
|
String text = fp.evaluateToString(e, "component.structuredBody.component.section.component.section.where(code.code='8709-8' and code.codeSystem='2.16.840.1.113883.6.1').text");
|
||||||
|
assertTrue(text.contains("<img src=\"MM1\"/>"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
public void testDCI() throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
public void testDCI() throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
||||||
try {
|
try {
|
||||||
Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir.us\\ccda-to-fhir-maps\\cda\\IAT2-Discharge_Summary-DCI.xml"), FhirFormat.XML);
|
Element e = Manager.parse(context,
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\temp\\ccda.xml"), FhirFormat.XML, OutputStyle.PRETTY, null);
|
new FileInputStream("C:\\work\\org.hl7.fhir.us\\ccda-to-fhir-maps\\cda\\IAT2-Discharge_Summary-DCI.xml"),
|
||||||
|
FhirFormat.XML);
|
||||||
|
|
||||||
|
Manager.compose(context, e, new FileOutputStream("C:\\temp\\ccda.xml"), FhirFormat.XML, OutputStyle.PRETTY, null);
|
||||||
// Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge_Summary-DCI.out.json"), FhirFormat.JSON, OutputStyle.PRETTY, null);
|
// Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge_Summary-DCI.out.json"), FhirFormat.JSON, OutputStyle.PRETTY, null);
|
||||||
// Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge_Summary-DCI.out.ttl"), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
|
// Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge_Summary-DCI.out.ttl"), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -44,20 +138,44 @@ public class CDARoundTripTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Ignore
|
||||||
public void testEpic() throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
public void testEpic()
|
||||||
Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.xml"), FhirFormat.XML);
|
throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.out.xml"), FhirFormat.XML, OutputStyle.PRETTY, null);
|
Element e = Manager.parse(context,
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.out.json"), FhirFormat.JSON, OutputStyle.PRETTY, null);
|
new FileInputStream(
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.out.ttl"), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.xml"),
|
||||||
|
FhirFormat.XML);
|
||||||
|
Manager.compose(context, e,
|
||||||
|
new FileOutputStream(
|
||||||
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.out.xml"),
|
||||||
|
FhirFormat.XML, OutputStyle.PRETTY, null);
|
||||||
|
Manager.compose(context, e,
|
||||||
|
new FileOutputStream(
|
||||||
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.out.json"),
|
||||||
|
FhirFormat.JSON, OutputStyle.PRETTY, null);
|
||||||
|
Manager.compose(context, e,
|
||||||
|
new FileOutputStream(
|
||||||
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-Discharge-Homework-Epic.out.ttl"),
|
||||||
|
FhirFormat.TURTLE, OutputStyle.PRETTY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Ignore
|
||||||
public void testDHIT() throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
public void testDHIT()
|
||||||
Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.xml"), FhirFormat.XML);
|
throws FHIRFormatError, DefinitionException, FileNotFoundException, IOException, FHIRException {
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.out.xml"), FhirFormat.XML, OutputStyle.PRETTY, null);
|
Element e = Manager.parse(context,
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.out.json"), FhirFormat.JSON, OutputStyle.PRETTY, null);
|
new FileInputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.xml"),
|
||||||
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.out.ttl"), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
|
FhirFormat.XML);
|
||||||
|
Manager.compose(context, e,
|
||||||
|
new FileOutputStream(
|
||||||
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.out.xml"),
|
||||||
|
FhirFormat.XML, OutputStyle.PRETTY, null);
|
||||||
|
Manager.compose(context, e,
|
||||||
|
new FileOutputStream(
|
||||||
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.out.json"),
|
||||||
|
FhirFormat.JSON, OutputStyle.PRETTY, null);
|
||||||
|
Manager.compose(context, e,
|
||||||
|
new FileOutputStream(
|
||||||
|
"C:\\work\\org.hl7.fhir.test\\ccda-to-fhir-maps\\testdocuments\\IAT2-DS-Homework-DHIT.out.ttl"),
|
||||||
|
FhirFormat.TURTLE, OutputStyle.PRETTY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -187,7 +187,7 @@ public class CDANarrativeFormat {
|
||||||
private void processRenderMultiMedia(Element e, XhtmlNode xn) throws FHIRException {
|
private void processRenderMultiMedia(Element e, XhtmlNode xn) throws FHIRException {
|
||||||
XhtmlNode xc = xn.addTag("img");
|
XhtmlNode xc = xn.addTag("img");
|
||||||
String v = e.getAttribute("referencedObject");
|
String v = e.getAttribute("referencedObject");
|
||||||
xn.attribute("src", v);
|
xc.attribute("src", v);
|
||||||
processAttributes(e, xc, "ID", "language", "styleCode");
|
processAttributes(e, xc, "ID", "language", "styleCode");
|
||||||
processChildren(e, xc);
|
processChildren(e, xc);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue