From 56738f7acf7f97f0536d9a6e68ad6989ad4b8ded Mon Sep 17 00:00:00 2001 From: tyfni Date: Tue, 18 May 2021 13:39:36 +0200 Subject: [PATCH] add copying of aggregation mode for conversion from 50 to 30 --- RELEASE_NOTES.md | 1 + .../convertors/VersionConvertor_30_50.java | 4 +++ .../StructureDefinition30_50Test.java | 28 ++++++++++++++++ .../resources/0_structuredefinition_30.json | 33 +++++++++++++++++++ .../resources/0_structuredefinition_50.json | 33 +++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_50/StructureDefinition30_50Test.java create mode 100644 org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_30.json create mode 100644 org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_50.json diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 42148db59..f1ddce8ef 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,4 @@ +* add copying of aggregation mode for conversion from 50 to 30 * add test for Observation conversion from 10 to 40 * add procedures conversion form dstu2 to r4 * add medication conversion from dstu2 to r4 \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_50.java index a2462232f..c18a7784d 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_30_50.java @@ -1826,6 +1826,10 @@ public class VersionConvertor_30_50 { tgt.setProfile(u.getValue()); } } + for (org.hl7.fhir.r5.model.Enumeration t : src.getAggregation()) { + org.hl7.fhir.dstu3.model.Enumeration a = convertAggregationMode(t); + if (!tgt.hasAggregation(a.getValue())) copyElement(t, tgt.addAggregation(a.getValue())); + } } static public org.hl7.fhir.r5.model.Enumeration convertAggregationMode(org.hl7.fhir.dstu3.model.Enumeration src) throws FHIRException { diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_50/StructureDefinition30_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_50/StructureDefinition30_50Test.java new file mode 100644 index 000000000..51f5873c0 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_50/StructureDefinition30_50Test.java @@ -0,0 +1,28 @@ +package org.hl7.fhir.convertors.conv30_50; + +import org.hl7.fhir.convertors.VersionConvertor_30_40; +import org.hl7.fhir.convertors.VersionConvertor_30_50; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +public class StructureDefinition30_50Test { + @Test + @DisplayName("Test r5 -> dstu3 device conversion.") + public void test1() throws IOException { + InputStream r5_input = this.getClass().getResourceAsStream("/0_structuredefinition_50.json"); + InputStream dstu3_expected_output = this.getClass().getResourceAsStream("/0_structuredefinition_30.json"); + + org.hl7.fhir.r5.model.StructureDefinition r5_actual = (org.hl7.fhir.r5.model.StructureDefinition) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_input); + org.hl7.fhir.dstu3.model.Resource dstu3_conv = VersionConvertor_30_50.convertResource(r5_actual, true); + + org.hl7.fhir.dstu3.formats.JsonParser dstu3_parser = new org.hl7.fhir.dstu3.formats.JsonParser(); + org.hl7.fhir.dstu3.model.Resource dstu3_expected = dstu3_parser.parse(dstu3_expected_output); + + Assertions.assertTrue(dstu3_expected.equalsDeep(dstu3_conv), + "Failed comparing\n" + dstu3_parser.composeString(dstu3_expected) + "\nand\n" + dstu3_parser.composeString(dstu3_conv)); + } +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_30.json b/org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_30.json new file mode 100644 index 000000000..03fe8fc5a --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_30.json @@ -0,0 +1,33 @@ +{ + "resourceType": "StructureDefinition", + "id": "ehealth-observation", + "url": "http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-observation", + "name": "ehealth-observation", + "title": "eHealth Observation", + "status": "draft", + "kind": "resource", + "abstract": "false", + "type": "Observation", + "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Observation", + "derivation": "constraint", + "snapshot": { + "element": [ + { + "id": "Observation.subject", + "path": "Observation.subject", + "min": "1", + "type": [ + { + "code": "Reference", + "targetProfile": [ + "http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-patient" + ], + "aggregation": [ + "referenced" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_50.json b/org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_50.json new file mode 100644 index 000000000..03fe8fc5a --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/0_structuredefinition_50.json @@ -0,0 +1,33 @@ +{ + "resourceType": "StructureDefinition", + "id": "ehealth-observation", + "url": "http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-observation", + "name": "ehealth-observation", + "title": "eHealth Observation", + "status": "draft", + "kind": "resource", + "abstract": "false", + "type": "Observation", + "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Observation", + "derivation": "constraint", + "snapshot": { + "element": [ + { + "id": "Observation.subject", + "path": "Observation.subject", + "min": "1", + "type": [ + { + "code": "Reference", + "targetProfile": [ + "http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-patient" + ], + "aggregation": [ + "referenced" + ] + } + ] + } + ] + } +} \ No newline at end of file