Search in sources :

Example 6 with VersionConvertorFactory_10_40

use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40 in project org.hl7.fhir.core by hapifhir.

the class R2ToR4Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2 = null;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_10_40.convertResource(r2, advisor);
    Bundle b;
    if (r4 instanceof Bundle) {
        b = (Bundle) r4;
    } else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r4).setFullUrl(r4 instanceof MetadataResource ? ((MetadataResource) r4).getUrl() : null);
    }
    // Add any code systems defined as part of processing value sets to the end of the converted Bundle
    advisor.getCslist().forEach(cs -> {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    });
    advisor.getCslist().clear();
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        b.getEntry().stream().filter(be -> be.hasResource() && be.getResource() instanceof StructureDefinition).map(be -> (StructureDefinition) be.getResource()).forEach(sd -> {
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
        });
    }
    return b;
}
Also used : MetadataResource(org.hl7.fhir.r4.model.MetadataResource) StructureDefinitionKind(org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) VersionConvertorFactory_10_40(org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40) IOException(java.io.IOException) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) UUID(java.util.UUID) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) ArrayList(java.util.ArrayList) List(java.util.List) Resource(org.hl7.fhir.dstu2.model.Resource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) UriType(org.hl7.fhir.r4.model.UriType) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) InputStream(java.io.InputStream) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.dstu2.model.Resource) MetadataResource(org.hl7.fhir.r4.model.MetadataResource) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.r4.model.UriType) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 7 with VersionConvertorFactory_10_40

use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40 in project org.hl7.fhir.core by hapifhir.

the class AllergyIntolerance10_40Test method testMedicationRequestConversion.

@ParameterizedTest
@MethodSource("filesPaths")
@DisplayName("Test 10_40 AllergyIntolerance conversion")
public void testMedicationRequestConversion(String dstu2_path, String r4_path) throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream(dstu2_path);
    InputStream r4_exepected_input = this.getClass().getResourceAsStream(r4_path);
    org.hl7.fhir.dstu2.model.AllergyIntolerance dstu2 = (org.hl7.fhir.dstu2.model.AllergyIntolerance) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
    BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
    org.hl7.fhir.r4.model.Resource r4_actual = VersionConvertorFactory_10_40.convertResource(dstu2, advisor);
    org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
    org.hl7.fhir.r4.model.Resource r4_expected = r4_parser.parse(r4_exepected_input);
    if (!r4_expected.equalsDeep(r4_actual)) {
        System.out.println("Expected");
        System.out.println(r4_parser.composeString(r4_expected));
        System.out.println();
        System.out.println("Actual");
        System.out.println(r4_parser.composeString(r4_actual));
    }
    Assertions.assertTrue(r4_expected.equalsDeep(r4_actual), "Failed comparing\n" + r4_parser.composeString(r4_actual) + "\nand\n" + r4_parser.composeString(r4_expected));
}
Also used : InputStream(java.io.InputStream) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with VersionConvertorFactory_10_40

use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40 in project org.hl7.fhir.core by hapifhir.

the class Medication10_40Test method testMedicationConversion.

@Test
@DisplayName("Test 10_40 Medication conversion")
public void testMedicationConversion() throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream("/0_medication_10.json");
    InputStream r4_exepected_input = this.getClass().getResourceAsStream("/0_medication_40.json");
    org.hl7.fhir.dstu2.model.Medication dstu2 = (org.hl7.fhir.dstu2.model.Medication) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
    BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
    org.hl7.fhir.r4.model.Resource r4_actual = VersionConvertorFactory_10_40.convertResource(dstu2, advisor);
    org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
    org.hl7.fhir.r4.model.Resource r4_expected = r4_parser.parse(r4_exepected_input);
    Assertions.assertTrue(r4_expected.equalsDeep(r4_actual), "Failed comparing\n" + r4_parser.composeString(r4_actual) + "\nand\n" + r4_parser.composeString(r4_expected));
}
Also used : InputStream(java.io.InputStream) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with VersionConvertorFactory_10_40

use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40 in project org.hl7.fhir.core by hapifhir.

the class Observation10_40Test method testObservationConversion.

@Test
@DisplayName("Test 10_40 Observation conversion")
public void testObservationConversion() throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream("/0_observation_10.json");
    InputStream r4_exepected_input = this.getClass().getResourceAsStream("/0_observation_40.json");
    org.hl7.fhir.dstu2.model.Observation dstu2 = (org.hl7.fhir.dstu2.model.Observation) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
    BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
    org.hl7.fhir.r4.model.Resource r4_actual = VersionConvertorFactory_10_40.convertResource(dstu2, advisor);
    org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
    org.hl7.fhir.r4.model.Resource r4_expected = r4_parser.parse(r4_exepected_input);
    Assertions.assertTrue(r4_expected.equalsDeep(r4_actual), "Failed comparing\n" + r4_parser.composeString(r4_actual) + "\nand\n" + r4_parser.composeString(r4_expected));
}
Also used : InputStream(java.io.InputStream) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with VersionConvertorFactory_10_40

use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40 in project org.hl7.fhir.core by hapifhir.

the class MedicationRequest10_40Test method testMedicationRequestConversion.

@ParameterizedTest
@MethodSource("filesPaths")
@DisplayName("Test 10_40 MedicationRequest conversion")
public void testMedicationRequestConversion(String dstu2_path, String r4_path) throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream(dstu2_path);
    InputStream r4_exepected_input = this.getClass().getResourceAsStream(r4_path);
    org.hl7.fhir.dstu2.model.MedicationOrder dstu2 = (org.hl7.fhir.dstu2.model.MedicationOrder) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
    BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
    org.hl7.fhir.r4.model.Resource r4_actual = VersionConvertorFactory_10_40.convertResource(dstu2, advisor);
    org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
    org.hl7.fhir.r4.model.Resource r4_expected = r4_parser.parse(r4_exepected_input);
    Assertions.assertTrue(r4_expected.equalsDeep(r4_actual), "Failed comparing\n" + r4_parser.composeString(r4_actual) + "\nand\n" + r4_parser.composeString(r4_expected));
}
Also used : InputStream(java.io.InputStream) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

BaseAdvisor_10_40 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40)9 InputStream (java.io.InputStream)8 IGR2ConvertorAdvisor (org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor)8 DisplayName (org.junit.jupiter.api.DisplayName)7 Test (org.junit.jupiter.api.Test)5 JsonParser (org.hl7.fhir.r4.formats.JsonParser)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 BaseAdvisor_30_40 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40)2 Resource (org.hl7.fhir.r4.model.Resource)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 ExpressionAdvisor40 (org.hl7.fhir.convertors.advisors.support.ExpressionAdvisor40)1 VersionConvertorFactory_10_40 (org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40)1 JsonParser (org.hl7.fhir.dstu2.formats.JsonParser)1 XmlParser (org.hl7.fhir.dstu2.formats.XmlParser)1 Resource (org.hl7.fhir.dstu2.model.Resource)1 StringType (org.hl7.fhir.dstu2.model.StringType)1