From e0d2b2a00df6874b2136ddac92ad937470c846d8 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Thu, 4 Jun 2020 23:56:41 +0200 Subject: [PATCH 1/8] refactor to ValidationEngine/ElementModel --- .../r5/test/FHIRMappingLanguageTests.java | 128 ++++++------------ 1 file changed, 44 insertions(+), 84 deletions(-) diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java index a39648b17..d9e3fe208 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java @@ -1,41 +1,28 @@ package org.hl7.fhir.r5.test; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; import javax.xml.parsers.ParserConfigurationException; -import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.SimpleWorkerContext; -import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; -import org.hl7.fhir.r5.formats.IParser.OutputStyle; -import org.hl7.fhir.r5.formats.JsonParser; -import org.hl7.fhir.r5.model.Base; -import org.hl7.fhir.r5.model.Coding; +import org.hl7.fhir.r5.formats.IParser; import org.hl7.fhir.r5.model.Resource; -import org.hl7.fhir.r5.model.ResourceFactory; import org.hl7.fhir.r5.model.StructureDefinition; -import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r5.model.StructureMap; -import org.hl7.fhir.r5.terminologies.ConceptMapEngine; import org.hl7.fhir.r5.test.utils.TestingUtilities; -import org.hl7.fhir.r5.utils.StructureMapUtilities; -import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; -import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager; -import org.hl7.fhir.utilities.cache.ToolsVersion; import org.hl7.fhir.utilities.xml.XMLUtil; +import org.hl7.fhir.validation.ValidationEngine; import org.hl7.fhir.validation.instance.InstanceValidatorFactory; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; @@ -45,12 +32,13 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; -public class FHIRMappingLanguageTests implements ITransformerServices { +public class FHIRMappingLanguageTests { private List outputs = new ArrayList(); + static private ValidationEngine validationEngine; + static private SimpleWorkerContext context; - static private JsonParser jsonParser; public static Stream data() throws FileNotFoundException, IOException, ParserConfigurationException, SAXException { @@ -67,91 +55,63 @@ public class FHIRMappingLanguageTests implements ITransformerServices { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r5.core", "current")); + validationEngine = new ValidationEngine("hl7.fhir.r4.core#4.0.1"); + context = validationEngine.getContext(); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null); + for (StructureDefinition sd : context.getStructures()) { + if (!sd.hasSnapshot()) { + System.out.println("generate snapshot for " + sd.getUrl()); + context.generateSnapshot(sd, true); + } + } if (context.getValidatorFactory() == null) { context.setValidatorFactory(new InstanceValidatorFactory()); } - jsonParser = new JsonParser(); - jsonParser.setOutputStyle(OutputStyle.PRETTY); } @ParameterizedTest(name = "{index}: {0}") @MethodSource("data") public void test(String name, String source, String map, String output) throws Exception { - InputStream fileSource = TestingUtilities.loadTestResourceStream("r5", "fml", source); - InputStream fileMap = TestingUtilities.loadTestResourceStream("r5", "fml", map); + byte[] byteSource = TestingUtilities.loadTestResourceBytes("r5", "fml", source); + String stringMap = TestingUtilities.loadTestResource("r5", "fml", map); String outputJson = TestingUtilities.loadTestResource("r5", "fml", output); String fileOutputRes = TestingUtilities.tempFile("fml", output) + ".out"; - + String fileOutputResOrig = TestingUtilities.tempFile("fml", output) + ".orig.out"; + ByteArrayOutputStream s = null; outputs.clear(); - boolean ok = false; String msg = null; - Resource resource = null; try { - StructureMapUtilities scu = new StructureMapUtilities(context, this); - org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, - new ByteArrayInputStream(TextFile.streamToBytes(fileSource)), FhirFormat.JSON); - StructureMap structureMap = scu.parse(TextFile.streamToString(fileMap), name); - String typeName = scu.getTargetType(structureMap).getType(); - resource = ResourceFactory.createResource(typeName); - scu.transform(null, src, structureMap, resource); - ok = true; + StructureMap r = new org.hl7.fhir.r5.utils.StructureMapUtilities(context).parse(stringMap, map); + context.cacheResource(r); + org.hl7.fhir.r5.elementmodel.Element element = validationEngine.transform(byteSource, FhirFormat.JSON, r.getUrl()); + s = new ByteArrayOutputStream(); + if (output.endsWith(".json")) + new org.hl7.fhir.r5.elementmodel.JsonParser(context).compose(element, s, IParser.OutputStyle.PRETTY, null); + else + new org.hl7.fhir.r5.elementmodel.XmlParser(context).compose(element, s, IParser.OutputStyle.PRETTY, null); + context.dropResource(r); } catch (Exception e) { - ok = false; - msg = e.getMessage(); + assertTrue(e.getMessage(), false); } - if (ok) { - ByteArrayOutputStream boas = new ByteArrayOutputStream(); - jsonParser.compose(boas, resource); - String result = boas.toString(); - log(result); - TextFile.bytesToFile(boas.toByteArray(), fileOutputRes); - msg = TestingUtilities.checkJsonSrcIsSame(result, outputJson); - assertTrue(msg, Utilities.noString(msg)); - } else - assertEquals("Error, but proper output was expected (" + msg + ")", "$error", output); - } - - @Override - public void log(String message) { - System.out.println(message); - } - - @Override - public Base createType(Object appInfo, String name) throws FHIRException { - StructureDefinition sd = context.fetchResource(StructureDefinition.class, name); - if (sd != null && sd.getKind() == StructureDefinitionKind.LOGICAL) { - return Manager.build(context, sd); + if (output.endsWith("json")) { + msg = TestingUtilities.checkJsonSrcIsSame(s.toString(), outputJson); } else { - if (name.startsWith("http://hl7.org/fhir/StructureDefinition/")) - name = name.substring("http://hl7.org/fhir/StructureDefinition/".length()); - return ResourceFactory.createResourceOrType(name); + TextFile.bytesToFile(s.toByteArray(), fileOutputRes); + TextFile.bytesToFile(outputJson.getBytes(), fileOutputResOrig); + msg = TestingUtilities.checkXMLIsSame(new FileInputStream(fileOutputRes), new FileInputStream(fileOutputResOrig)); } + if (!Utilities.noString(msg)) { + System.out.print(s.toString()); + } + assertTrue(msg, Utilities.noString(msg)); } - @Override - public Base createResource(Object appInfo, Base res, boolean atRootofTransform) { - if (atRootofTransform) - outputs.add((Resource) res); - return res; - } - - @Override - public Coding translate(Object appInfo, Coding source, String conceptMapUrl) throws FHIRException { - ConceptMapEngine cme = new ConceptMapEngine(context); - return cme.translate(source, conceptMapUrl); - } - - @Override - public Base resolveReference(Object appContext, String url) throws FHIRException { - throw new FHIRException("resolveReference is not supported yet"); - } - - @Override - public List performSearch(Object appContext, String url) throws FHIRException { - throw new FHIRException("performSearch is not supported yet"); - } } \ No newline at end of file From 22ec0924daf36c5eaef994361f5415686aa6a722 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Fri, 10 Jan 2020 21:33:29 +0100 Subject: [PATCH 2/8] logical model not as resource (create xsi:type) --- .../src/main/java/org/hl7/fhir/r5/elementmodel/Property.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java index aeb5e927a..0d17634d8 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java @@ -206,7 +206,7 @@ public class Property { if (definition.getType().size() > 0) return definition.getType().size() == 1 && ("Resource".equals(definition.getType().get(0).getCode()) || "DomainResource".equals(definition.getType().get(0).getCode())); else - return !definition.getPath().contains(".") && (structure.getKind() == StructureDefinitionKind.RESOURCE || structure.getKind() == StructureDefinitionKind.LOGICAL); + return !definition.getPath().contains(".") && (structure.getKind() == StructureDefinitionKind.RESOURCE); } public boolean isList() { From 5576a0237804128db97b6bddff1e6938563c93fb Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Thu, 14 May 2020 12:00:49 +0200 Subject: [PATCH 3/8] add ed/st type definition and roundrip --- .../org/hl7/fhir/r5/test/CDARoundTripTests.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java index 860fb6cde..1ff468574 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java @@ -6,6 +6,7 @@ import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; +import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; @@ -13,22 +14,10 @@ import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.cache.ToolsVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class CDARoundTripTests { -// private SimpleWorkerContext context; -// old-test private FHIRPathEngine fp; - - @BeforeAll - public static void setUp() throws Exception { -// old-test context = new SimpleWorkerContext(); -// old-test PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); -// old-test context.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "dev"), null, "StructureDefinition"); -// old-test context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda", "dev"), null, "StructureDefinition"); -// old-test fp = new FHIRPathEngine(context); - } // old-test // @Test @@ -172,11 +161,11 @@ public class CDARoundTripTests { // FhirFormat.TURTLE, OutputStyle.PRETTY, null); // } - @Test public void testSimple() throws IOException { FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); SimpleWorkerContext context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); + FHIRPathEngine fp = new FHIRPathEngine(context); context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null); context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null); context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null); @@ -191,7 +180,6 @@ public class CDARoundTripTests { } } Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"), FhirFormat.XML); - FHIRPathEngine fp = new FHIRPathEngine(context); Assertions.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.templateId.root"))); Assertions.assertEquals("SoEN", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.code.displayName"))); Assertions.assertEquals("SoEN2", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.code.sdtcDisplayName"))); From d0ee44dfa80f3d65368238c9ba198a7f82aa1e36 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Thu, 14 May 2020 13:38:54 +0200 Subject: [PATCH 4/8] json roundtrip cda title --- .../hl7/fhir/r5/elementmodel/JsonParser.java | 2 +- .../hl7/fhir/r5/test/CDARoundTripTests.java | 99 ++++++++++++++----- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index e98f50711..82701ee7f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -184,7 +184,7 @@ public class JsonParser extends ParserBase { } public void parseChildItem(String path, JsonObject object, Element context, Set processed, Property property) { - if (property.isChoice()) { + if (property.isChoice() || property.getDefinition().getPath().endsWith("data[x]")) { for (TypeRefComponent type : property.getDefinition().getType()) { String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getWorkingCode()); if (!isPrimitive(type.getWorkingCode()) && object.has(eName)) { diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java index 1ff468574..f9fd0efe2 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java @@ -1,5 +1,7 @@ package org.hl7.fhir.r5.test; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import org.hl7.fhir.r5.context.SimpleWorkerContext; @@ -18,6 +20,29 @@ import org.junit.jupiter.api.Test; public class CDARoundTripTests { + private static SimpleWorkerContext context; + private static FHIRPathEngine fp; + + @BeforeAll + public static void setUp() throws Exception { + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); + fp = new FHIRPathEngine(context); + + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null); + context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null); + for (StructureDefinition sd : context.getStructures()) { + if (!sd.hasSnapshot()) { + System.out.println("generate snapshot for " + sd.getUrl()); + context.generateSnapshot(sd, true); + } + } + } // old-test // @Test @@ -161,28 +186,58 @@ public class CDARoundTripTests { // FhirFormat.TURTLE, OutputStyle.PRETTY, null); // } - @Test - public void testSimple() throws IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - SimpleWorkerContext context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); - FHIRPathEngine fp = new FHIRPathEngine(context); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null); - context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null); - for (StructureDefinition sd : context.getStructures()) { - if (!sd.hasSnapshot()) { - System.out.println("generate snapshot for " + sd.getUrl()); - context.generateSnapshot(sd, true); - } - } - Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"), FhirFormat.XML); - Assertions.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.templateId.root"))); - Assertions.assertEquals("SoEN", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.code.displayName"))); - Assertions.assertEquals("SoEN2", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.code.sdtcDisplayName"))); + public void assertsExample(Element cdaExample) { + Assertions.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.templateId.root"))); + Assertions.assertEquals("SoEN", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.displayName"))); + Assertions.assertEquals("SoEN2", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.sdtcDisplayName"))); + Assertions.assertEquals("c266", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.id.extension"))); + Assertions.assertEquals("2.16.840.1.113883.19.4", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.id.root"))); + Assertions.assertEquals("X-34133-9", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.code"))); + Assertions.assertEquals("2.16.840.1.113883.6.1", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.codeSystem"))); + Assertions.assertEquals("LOINC", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.code.codeSystemName"))); + Assertions.assertEquals("Episode Note", fp.evaluateToString(null, cdaExample, cdaExample, cdaExample, fp.parse("ClinicalDocument.title.dataString"))); } + @Test + /** + * Deserializes a simplified CDA example into the logical model and checks that + * xml deserialization/serialization + * + * @throws IOException + */ + public void testClinicalDocumentXmlParser() throws IOException { + Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"), + FhirFormat.XML); + + assertsExample(cda); + + ByteArrayOutputStream baosXml = new ByteArrayOutputStream(); + Manager.compose(context, cda, baosXml, FhirFormat.XML, OutputStyle.PRETTY, null); + Element cdaXmlRoundtrip = Manager.parse(context, new ByteArrayInputStream(baosXml.toString().getBytes()), FhirFormat.XML); + +// assertsExample(cdaXmlRoundtrip); + } + + @Test + /** + * Deserializes a simplified CDA example into the logical model and checks that + * json deserialization/serialization works + * + * @throws IOException + */ + public void testClinicalDocumentJsonParser() throws IOException { + Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"), + FhirFormat.XML); + + assertsExample(cda); + + ByteArrayOutputStream baosJson = new ByteArrayOutputStream(); + Manager.compose(context, cda, baosJson, FhirFormat.JSON, OutputStyle.PRETTY, null); + Element cdaJsonRoundtrip = Manager.parse(context, new ByteArrayInputStream(baosJson.toString().getBytes()), + FhirFormat.JSON); + + assertsExample(cdaJsonRoundtrip); + + } + } \ No newline at end of file From 8d59817d26b2b05a2ceb97ac4bf6408eda96b335 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Thu, 14 May 2020 14:25:05 +0200 Subject: [PATCH 5/8] json parse r4 --- .../src/main/java/org/hl7/fhir/r4/elementmodel/JsonParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/elementmodel/JsonParser.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/elementmodel/JsonParser.java index c5ae3d979..470397a70 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/elementmodel/JsonParser.java @@ -183,7 +183,7 @@ public class JsonParser extends ParserBase { } public void parseChildItem(String path, JsonObject object, Element context, Set processed, Property property) { - if (property.isChoice()) { + if (property.isChoice() || property.getDefinition().getPath().endsWith("data[x]")) { for (TypeRefComponent type : property.getDefinition().getType()) { String eName = property.getName().substring(0, property.getName().length()-3) + Utilities.capitalize(type.getWorkingCode()); if (!isPrimitive(type.getWorkingCode()) && object.has(eName)) { From 473a9aab0a10b00b70fbcc364542a74725527f14 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Mon, 8 Jun 2020 15:48:13 +0200 Subject: [PATCH 6/8] roundtrip for sdtc, add ns, xml name to serialize --- .../hl7/fhir/r5/elementmodel/XmlParser.java | 104 +++++++++++------- .../hl7/fhir/r5/test/CDARoundTripTests.java | 3 +- 2 files changed, 65 insertions(+), 42 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index d795fb2a1..362cf8364 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -1,33 +1,33 @@ package org.hl7.fhir.r5.elementmodel; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ import java.io.IOException; @@ -210,6 +210,10 @@ public class XmlParser extends ParserBase { return "h:"; if (ns.equals("urn:hl7-org:v3")) return "v3:"; + if (ns.equals("urn:hl7-org:sdtc")) + return "sdtc:"; + if (ns.equals("urn:ihe:pharm")) + return "pharm:"; return "?:"; } @@ -538,11 +542,31 @@ public class XmlParser extends ParserBase { xml.setDefaultNamespace(e.getProperty().getXmlNamespace()); if (hasTypeAttr(e)) xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); + addNamespaces(xml, e); composeElement(xml, e, e.getType(), true); xml.end(); - } + private void addNamespaces(IXMLWriter xml, Element e) throws IOException { + String ns = e.getProperty().getXmlNamespace(); + if (ns!=null && !xml.getDefaultNamespace().equals(ns)){ + if (!xml.namespaceDefined(ns)) { + String prefix = pathPrefix(ns); + if (prefix.endsWith(":")) { + prefix = prefix.substring(0, prefix.length()-1); + } + if ("?".equals(prefix)) { + xml.namespace(ns); + } else { + xml.namespace(ns, prefix); + } + } + } + for (Element c : e.getChildren()) { + addNamespaces(xml, c); + } + } + private boolean hasTypeAttr(Element e) { if (isTypeAttr(e.getProperty())) return true; @@ -584,9 +608,9 @@ public class XmlParser extends ParserBase { if (isText(element.getProperty())) { if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); - xml.enter(elementName); + xml.enter(element.getProperty().getXmlNamespace(),elementName); xml.text(element.getValue()); - xml.exit(elementName); + xml.exit(element.getProperty().getXmlNamespace(),elementName); } else if (!element.hasChildren() && !element.hasValue()) { if (element.getExplicitType() != null) xml.attribute("xsi:type", element.getExplicitType()); @@ -614,10 +638,10 @@ public class XmlParser extends ParserBase { if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); if (element.hasChildren()) { - xml.enter(elementName); - for (Element child : element.getChildren()) + xml.enter(element.getProperty().getXmlNamespace(), elementName); + for (Element child : element.getChildren()) composeElement(xml, child, child.getName(), false); - xml.exit(elementName); + xml.exit(element.getProperty().getXmlNamespace(),elementName); } else xml.element(elementName); } @@ -630,16 +654,16 @@ public class XmlParser extends ParserBase { String av = child.getValue(); if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat")) av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), "http://www.healthintersections.com.au/fhir/StructureDefinition/elementdefinition-dateformat"), av); - xml.attribute(child.getName(), av); - } + xml.attribute(child.getProperty().getXmlNamespace(),child.getProperty().getXmlName(), av); + } } if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); - xml.enter(elementName); + xml.enter(element.getProperty().getXmlNamespace(),elementName); if (!root && element.getSpecial() != null) { if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); - xml.enter(element.getType()); + xml.enter(element.getProperty().getXmlNamespace(),element.getType()); } for (Element child : element.getChildren()) { if (isText(child.getProperty())) { @@ -650,8 +674,8 @@ public class XmlParser extends ParserBase { composeElement(xml, child, child.getName(), false); } if (!root && element.getSpecial() != null) - xml.exit(element.getType()); - xml.exit(elementName); + xml.exit(element.getProperty().getXmlNamespace(),element.getType()); + xml.exit(element.getProperty().getXmlNamespace(),elementName); } } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java index f9fd0efe2..57d676eb7 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java @@ -214,8 +214,7 @@ public class CDARoundTripTests { ByteArrayOutputStream baosXml = new ByteArrayOutputStream(); Manager.compose(context, cda, baosXml, FhirFormat.XML, OutputStyle.PRETTY, null); Element cdaXmlRoundtrip = Manager.parse(context, new ByteArrayInputStream(baosXml.toString().getBytes()), FhirFormat.XML); - -// assertsExample(cdaXmlRoundtrip); + assertsExample(cdaXmlRoundtrip); } @Test From 31a4d31755ebe44aae7b0179fcb3fbd3dde1386e Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Thu, 9 Jan 2020 22:45:00 +0100 Subject: [PATCH 7/8] CDA Narrative conversion from FHIR NP fix --- .../src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index d795fb2a1..f7b88dc9c 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -595,7 +595,7 @@ public class XmlParser extends ParserBase { if (element.getType().equals("xhtml")) { String rawXhtml = element.getValue(); if (isCdaText(element.getProperty())) { - new CDANarrativeFormat().convert(xml, element.getXhtml()); + new CDANarrativeFormat().convert(xml, new XhtmlParser().parseFragment(rawXhtml)); } else { xml.escapedText(rawXhtml); xml.anchor("end-xhtml"); From 2f85c2fd75f263222d508829778f5bcc2f100af2 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 9 Jun 2020 05:38:42 -0400 Subject: [PATCH 8/8] Converter STU3-R4 improvements --- .../convertors/VersionConvertor_30_40.java | 10 + .../convertors/conv30_40/Account30_40.java | 191 ++++++++++++++++++ .../convertors/conv30_40/Coverage30_40.java | 154 ++++++++++++++ .../conv30_40/MedicationRequest30_40.java | 6 + .../conv30_40/RelatedPerson30_40.java | 4 +- 5 files changed, 363 insertions(+), 2 deletions(-) create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Account30_40.java create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Coverage30_40.java diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_40.java index cdc97b71f..f9f0322d5 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_40.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import org.hl7.fhir.convertors.conv30_40.Account30_40; import org.hl7.fhir.convertors.conv30_40.ActivityDefinition30_40; import org.hl7.fhir.convertors.conv30_40.AllergyIntolerance30_40; import org.hl7.fhir.convertors.conv30_40.Appointment30_40; @@ -24,6 +25,7 @@ import org.hl7.fhir.convertors.conv30_40.Composition30_40; import org.hl7.fhir.convertors.conv30_40.ConceptMap30_40; import org.hl7.fhir.convertors.conv30_40.Condition30_40; import org.hl7.fhir.convertors.conv30_40.Consent30_40; +import org.hl7.fhir.convertors.conv30_40.Coverage30_40; import org.hl7.fhir.convertors.conv30_40.DataElement30_40; import org.hl7.fhir.convertors.conv30_40.DetectedIssue30_40; import org.hl7.fhir.convertors.conv30_40.DeviceUseStatement30_40; @@ -4931,6 +4933,8 @@ public class VersionConvertor_30_40 { return null; if (src instanceof org.hl7.fhir.dstu3.model.Parameters) return Parameters30_40.convertParameters((org.hl7.fhir.dstu3.model.Parameters) src); + if (src instanceof org.hl7.fhir.dstu3.model.Account) + return Account30_40.convertAccount((org.hl7.fhir.dstu3.model.Account) src); if (src instanceof org.hl7.fhir.dstu3.model.ActivityDefinition) return ActivityDefinition30_40.convertActivityDefinition((org.hl7.fhir.dstu3.model.ActivityDefinition) src); if (src instanceof org.hl7.fhir.dstu3.model.AllergyIntolerance) @@ -4971,6 +4975,8 @@ public class VersionConvertor_30_40 { return Condition30_40.convertCondition((org.hl7.fhir.dstu3.model.Condition) src); if (src instanceof org.hl7.fhir.dstu3.model.Consent) return Consent30_40.convertConsent((org.hl7.fhir.dstu3.model.Consent) src); + if (src instanceof org.hl7.fhir.dstu3.model.Coverage) + return Coverage30_40.convertCoverage((org.hl7.fhir.dstu3.model.Coverage) src); if (src instanceof org.hl7.fhir.dstu3.model.DataElement) return DataElement30_40.convertDataElement((org.hl7.fhir.dstu3.model.DataElement) src); if (src instanceof org.hl7.fhir.dstu3.model.DetectedIssue) @@ -5108,6 +5114,8 @@ public class VersionConvertor_30_40 { else return Parameters30_40.convertParameters((org.hl7.fhir.r4.model.Parameters) src); } + if (src instanceof org.hl7.fhir.r4.model.Account) + return Account30_40.convertAccount((org.hl7.fhir.r4.model.Account) src); if (src instanceof org.hl7.fhir.r4.model.ActivityDefinition) return ActivityDefinition30_40.convertActivityDefinition((org.hl7.fhir.r4.model.ActivityDefinition) src); if (src instanceof org.hl7.fhir.r4.model.AllergyIntolerance) @@ -5148,6 +5156,8 @@ public class VersionConvertor_30_40 { return Condition30_40.convertCondition((org.hl7.fhir.r4.model.Condition) src); if (src instanceof org.hl7.fhir.r4.model.Consent) return Consent30_40.convertConsent((org.hl7.fhir.r4.model.Consent) src); + if (src instanceof org.hl7.fhir.r4.model.Coverage) + return Coverage30_40.convertCoverage((org.hl7.fhir.r4.model.Coverage) src); if (src instanceof org.hl7.fhir.r4.model.DetectedIssue) return DetectedIssue30_40.convertDetectedIssue((org.hl7.fhir.r4.model.DetectedIssue) src); if (src instanceof org.hl7.fhir.r4.model.DeviceUseStatement) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Account30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Account30_40.java new file mode 100644 index 000000000..d0c9436ae --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Account30_40.java @@ -0,0 +1,191 @@ +package org.hl7.fhir.convertors.conv30_40; + + +import org.hl7.fhir.convertors.VersionConvertor_30_40; +import org.hl7.fhir.exceptions.FHIRException; + +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ +// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0 +public class Account30_40 extends VersionConvertor_30_40 { + + public static org.hl7.fhir.r4.model.Account convertAccount(org.hl7.fhir.dstu3.model.Account src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.r4.model.Account tgt = new org.hl7.fhir.r4.model.Account(); + copyDomainResource(src, tgt); + for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); + if (src.hasStatus()) + tgt.setStatusElement(convertAccountStatus(src.getStatusElement())); + if (src.hasType()) + tgt.setType(convertCodeableConcept(src.getType())); + if (src.hasName()) + tgt.setNameElement(convertString(src.getNameElement())); + if (src.hasSubject()) { + tgt.addSubject(convertReference(src.getSubject())); + } + if (src.hasPeriod()) + tgt.setServicePeriod(convertPeriod(src.getPeriod())); + for (org.hl7.fhir.dstu3.model.Account.CoverageComponent t : src.getCoverage()) tgt.addCoverage(convertCoverageComponent(t)); + if (src.hasOwner()) + tgt.setOwner(convertReference(src.getOwner())); + if (src.hasDescription()) + tgt.setDescriptionElement(convertString(src.getDescriptionElement())); + for (org.hl7.fhir.dstu3.model.Account.GuarantorComponent t : src.getGuarantor()) tgt.addGuarantor(convertGuarantorComponent(t)); + return tgt; + } + + public static org.hl7.fhir.dstu3.model.Account convertAccount(org.hl7.fhir.r4.model.Account src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.dstu3.model.Account tgt = new org.hl7.fhir.dstu3.model.Account(); + copyDomainResource(src, tgt); + for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); + if (src.hasStatus()) + tgt.setStatusElement(convertAccountStatus(src.getStatusElement())); + if (src.hasType()) + tgt.setType(convertCodeableConcept(src.getType())); + if (src.hasName()) + tgt.setNameElement(convertString(src.getNameElement())); + if (src.getSubject().size() > 0) { + tgt.setSubject(convertReference(src.getSubjectFirstRep())); + } + if (src.hasServicePeriod()) + tgt.setPeriod(convertPeriod(src.getServicePeriod())); + for (org.hl7.fhir.r4.model.Account.CoverageComponent t : src.getCoverage()) tgt.addCoverage(convertCoverageComponent(t)); + if (src.hasOwner()) + tgt.setOwner(convertReference(src.getOwner())); + if (src.hasDescription()) + tgt.setDescriptionElement(convertString(src.getDescriptionElement())); + for (org.hl7.fhir.r4.model.Account.GuarantorComponent t : src.getGuarantor()) tgt.addGuarantor(convertGuarantorComponent(t)); + return tgt; + } + + static public org.hl7.fhir.r4.model.Enumeration convertAccountStatus(org.hl7.fhir.dstu3.model.Enumeration src) throws FHIRException { + if (src == null || src.isEmpty()) + return null; + org.hl7.fhir.r4.model.Enumeration tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Account.AccountStatusEnumFactory()); + VersionConvertor_30_40.copyElement(src, tgt); + switch(src.getValue()) { + case ACTIVE: + tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.ACTIVE); + break; + case INACTIVE: + tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.INACTIVE); + break; + case ENTEREDINERROR: + tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.ENTEREDINERROR); + break; + default: + tgt.setValue(org.hl7.fhir.r4.model.Account.AccountStatus.NULL); + break; + } + return tgt; + } + + static public org.hl7.fhir.dstu3.model.Enumeration convertAccountStatus(org.hl7.fhir.r4.model.Enumeration src) throws FHIRException { + if (src == null || src.isEmpty()) + return null; + org.hl7.fhir.dstu3.model.Enumeration tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Account.AccountStatusEnumFactory()); + VersionConvertor_30_40.copyElement(src, tgt); + switch(src.getValue()) { + case ACTIVE: + tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ACTIVE); + break; + case INACTIVE: + tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.INACTIVE); + break; + case ENTEREDINERROR: + tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ENTEREDINERROR); + break; + case ONHOLD: + tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ACTIVE); + break; + case UNKNOWN: + tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.ACTIVE); + break; + default: + tgt.setValue(org.hl7.fhir.dstu3.model.Account.AccountStatus.NULL); + break; + } + return tgt; + } + + public static org.hl7.fhir.r4.model.Account.CoverageComponent convertCoverageComponent(org.hl7.fhir.dstu3.model.Account.CoverageComponent src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.r4.model.Account.CoverageComponent tgt = new org.hl7.fhir.r4.model.Account.CoverageComponent(); + copyElement(src, tgt); + if (src.hasCoverage()) + tgt.setCoverage(convertReference(src.getCoverage())); + if (src.hasPriority()) + tgt.setPriorityElement(convertPositiveInt(src.getPriorityElement())); + return tgt; + } + + public static org.hl7.fhir.dstu3.model.Account.CoverageComponent convertCoverageComponent(org.hl7.fhir.r4.model.Account.CoverageComponent src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.dstu3.model.Account.CoverageComponent tgt = new org.hl7.fhir.dstu3.model.Account.CoverageComponent(); + copyElement(src, tgt); + if (src.hasCoverage()) + tgt.setCoverage(convertReference(src.getCoverage())); + if (src.hasPriority()) + tgt.setPriorityElement(convertPositiveInt(src.getPriorityElement())); + return tgt; + } + + public static org.hl7.fhir.r4.model.Account.GuarantorComponent convertGuarantorComponent(org.hl7.fhir.dstu3.model.Account.GuarantorComponent src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.r4.model.Account.GuarantorComponent tgt = new org.hl7.fhir.r4.model.Account.GuarantorComponent(); + copyElement(src, tgt); + if (src.hasParty()) + tgt.setParty(convertReference(src.getParty())); + if (src.hasOnHold()) + tgt.setOnHoldElement(convertBoolean(src.getOnHoldElement())); + if (src.hasPeriod()) + tgt.setPeriod(convertPeriod(src.getPeriod())); + return tgt; + } + + public static org.hl7.fhir.dstu3.model.Account.GuarantorComponent convertGuarantorComponent(org.hl7.fhir.r4.model.Account.GuarantorComponent src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.dstu3.model.Account.GuarantorComponent tgt = new org.hl7.fhir.dstu3.model.Account.GuarantorComponent(); + copyElement(src, tgt); + if (src.hasParty()) + tgt.setParty(convertReference(src.getParty())); + if (src.hasOnHold()) + tgt.setOnHoldElement(convertBoolean(src.getOnHoldElement())); + if (src.hasPeriod()) + tgt.setPeriod(convertPeriod(src.getPeriod())); + return tgt; + } +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Coverage30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Coverage30_40.java new file mode 100644 index 000000000..788d52e5c --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/Coverage30_40.java @@ -0,0 +1,154 @@ +package org.hl7.fhir.convertors.conv30_40; + + +import org.hl7.fhir.convertors.VersionConvertor_30_40; +import org.hl7.fhir.exceptions.FHIRException; + +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ +// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0 +public class Coverage30_40 extends VersionConvertor_30_40 { + + public static org.hl7.fhir.dstu3.model.Coverage convertCoverage(org.hl7.fhir.r4.model.Coverage src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.dstu3.model.Coverage tgt = new org.hl7.fhir.dstu3.model.Coverage(); + copyDomainResource(src, tgt); + for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); + if (src.hasStatus()) + tgt.setStatusElement(convertCoverageStatus(src.getStatusElement())); + if (src.hasType()) + tgt.setType(convertCodeableConcept(src.getType())); + if (src.hasPolicyHolder()) + tgt.setPolicyHolder(convertReference(src.getPolicyHolder())); + if (src.hasSubscriber()) + tgt.setSubscriber(convertReference(src.getSubscriber())); + if (src.hasSubscriberId()) + tgt.setSubscriberIdElement(convertString(src.getSubscriberIdElement())); + if (src.hasBeneficiary()) + tgt.setBeneficiary(convertReference(src.getBeneficiary())); + if (src.hasDependent()) + tgt.setDependentElement(convertString(src.getDependentElement())); + if (src.hasRelationship()) + tgt.setRelationship(convertCodeableConcept(src.getRelationship())); + if (src.hasPeriod()) + tgt.setPeriod(convertPeriod(src.getPeriod())); + for (org.hl7.fhir.r4.model.Reference t : src.getPayor()) tgt.addPayor(convertReference(t)); + if (src.hasOrder()) + tgt.setOrderElement(convertPositiveInt(src.getOrderElement())); + if (src.hasNetwork()) + tgt.setNetworkElement(convertString(src.getNetworkElement())); + for (org.hl7.fhir.r4.model.Reference t : src.getContract()) tgt.addContract(convertReference(t)); + return tgt; + } + + public static org.hl7.fhir.r4.model.Coverage convertCoverage(org.hl7.fhir.dstu3.model.Coverage src) throws FHIRException { + if (src == null) + return null; + org.hl7.fhir.r4.model.Coverage tgt = new org.hl7.fhir.r4.model.Coverage(); + copyDomainResource(src, tgt); + for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); + if (src.hasStatus()) + tgt.setStatusElement(convertCoverageStatus(src.getStatusElement())); + if (src.hasType()) + tgt.setType(convertCodeableConcept(src.getType())); + if (src.hasPolicyHolder()) + tgt.setPolicyHolder(convertReference(src.getPolicyHolder())); + if (src.hasSubscriber()) + tgt.setSubscriber(convertReference(src.getSubscriber())); + if (src.hasSubscriberId()) + tgt.setSubscriberIdElement(convertString(src.getSubscriberIdElement())); + if (src.hasBeneficiary()) + tgt.setBeneficiary(convertReference(src.getBeneficiary())); + if (src.hasDependent()) + tgt.setDependentElement(convertString(src.getDependentElement())); + if (src.hasRelationship()) + tgt.setRelationship(convertCodeableConcept(src.getRelationship())); + if (src.hasPeriod()) + tgt.setPeriod(convertPeriod(src.getPeriod())); + for (org.hl7.fhir.dstu3.model.Reference t : src.getPayor()) tgt.addPayor(convertReference(t)); + if (src.hasOrder()) + tgt.setOrderElement(convertPositiveInt(src.getOrderElement())); + if (src.hasNetwork()) + tgt.setNetworkElement(convertString(src.getNetworkElement())); + for (org.hl7.fhir.dstu3.model.Reference t : src.getContract()) tgt.addContract(convertReference(t)); + return tgt; + } + + static public org.hl7.fhir.dstu3.model.Enumeration convertCoverageStatus(org.hl7.fhir.r4.model.Enumeration src) throws FHIRException { + if (src == null || src.isEmpty()) + return null; + org.hl7.fhir.dstu3.model.Enumeration tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Coverage.CoverageStatusEnumFactory()); + VersionConvertor_30_40.copyElement(src, tgt); + switch(src.getValue()) { + case ACTIVE: + tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.ACTIVE); + break; + case CANCELLED: + tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.CANCELLED); + break; + case DRAFT: + tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.DRAFT); + break; + case ENTEREDINERROR: + tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.ENTEREDINERROR); + break; + default: + tgt.setValue(org.hl7.fhir.dstu3.model.Coverage.CoverageStatus.NULL); + break; + } + return tgt; + } + + static public org.hl7.fhir.r4.model.Enumeration convertCoverageStatus(org.hl7.fhir.dstu3.model.Enumeration src) throws FHIRException { + if (src == null || src.isEmpty()) + return null; + org.hl7.fhir.r4.model.Enumeration tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Coverage.CoverageStatusEnumFactory()); + VersionConvertor_30_40.copyElement(src, tgt); + switch(src.getValue()) { + case ACTIVE: + tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.ACTIVE); + break; + case CANCELLED: + tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.CANCELLED); + break; + case DRAFT: + tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.DRAFT); + break; + case ENTEREDINERROR: + tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.ENTEREDINERROR); + break; + default: + tgt.setValue(org.hl7.fhir.r4.model.Coverage.CoverageStatus.NULL); + break; + } + return tgt; + } + +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/MedicationRequest30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/MedicationRequest30_40.java index 996f98fe8..03a47a3ac 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/MedicationRequest30_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/MedicationRequest30_40.java @@ -43,6 +43,9 @@ public class MedicationRequest30_40 { tgt.setPriorPrescription(VersionConvertor_30_40.convertReference(src.getPriorPrescription())); for (org.hl7.fhir.dstu3.model.Reference t : src.getDetectedIssue()) tgt.addDetectedIssue(VersionConvertor_30_40.convertReference(t)); for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory()) tgt.addEventHistory(VersionConvertor_30_40.convertReference(t)); + if (src.hasRequester() && src.getRequester().hasAgent()) { + tgt.setRequester(VersionConvertor_30_40.convertReference(src.getRequester().getAgent())); + } return tgt; } @@ -84,6 +87,9 @@ public class MedicationRequest30_40 { tgt.setPriorPrescription(VersionConvertor_30_40.convertReference(src.getPriorPrescription())); for (org.hl7.fhir.r4.model.Reference t : src.getDetectedIssue()) tgt.addDetectedIssue(VersionConvertor_30_40.convertReference(t)); for (org.hl7.fhir.r4.model.Reference t : src.getEventHistory()) tgt.addEventHistory(VersionConvertor_30_40.convertReference(t)); + if (src.hasRequester()) { + tgt.getRequester().setAgent(VersionConvertor_30_40.convertReference(src.getRequester())); + } return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/RelatedPerson30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/RelatedPerson30_40.java index 5f8262100..289142fee 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/RelatedPerson30_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/RelatedPerson30_40.java @@ -40,7 +40,7 @@ public class RelatedPerson30_40 { tgt.setGenderElement(VersionConvertor_30_40.convertAdministrativeGender(src.getGenderElement())); } if (src.hasBirthDate()) { - tgt.setBirthDate(tgt.getBirthDate()); + tgt.setBirthDate(src.getBirthDate()); } for (org.hl7.fhir.r4.model.Address t : src.getAddress()) { tgt.addAddress(VersionConvertor_30_40.convertAddress(t)); @@ -84,7 +84,7 @@ public class RelatedPerson30_40 { tgt.setGenderElement(VersionConvertor_30_40.convertAdministrativeGender(src.getGenderElement())); } if (src.hasBirthDate()) { - tgt.setBirthDate(tgt.getBirthDate()); + tgt.setBirthDate(src.getBirthDate()); } for (org.hl7.fhir.dstu3.model.Address t : src.getAddress()) { tgt.addAddress(VersionConvertor_30_40.convertAddress(t));