Search in sources :

Example 1 with VersionConvertorFactory_10_30

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

the class VersionConvertorPrimitiveType10_30Test method testNullValueDstu2Primitive.

@ParameterizedTest(name = "Testing dstu2 -> dstu3 conversion of null value {0}.")
@MethodSource("dstu2PrimitiveTypes")
public <T extends PrimitiveType> void testNullValueDstu2Primitive(String classname, T obj) {
    obj.addExtension().setUrl("http://example.com/AnyValue").setValue(new StringType("A value"));
    Assertions.assertNull(((org.hl7.fhir.dstu3.model.PrimitiveType) VersionConvertorFactory_10_30.convertType(obj)).getValue());
}
Also used : StringType(org.hl7.fhir.dstu2.model.StringType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with VersionConvertorFactory_10_30

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

the class R2ToR3Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_10_30.convertResource(r2, advisor_10_30);
    Bundle b;
    if (r3 instanceof Bundle) {
        b = (Bundle) r3;
    } else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r3).setFullUrl(r3 instanceof MetadataResource ? ((MetadataResource) r3).getUrl() : null);
    }
    advisor_10_30.getCslist().forEach(cs -> {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    });
    advisor_10_30.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.dstu3.model.MetadataResource) StructureDefinitionKind(org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionKind) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser) Bundle(org.hl7.fhir.dstu3.model.Bundle) VersionConvertorFactory_10_30(org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) UriType(org.hl7.fhir.dstu3.model.UriType) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) BaseAdvisor_10_30(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30) IOException(java.io.IOException) UUID(java.util.UUID) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) ArrayList(java.util.ArrayList) List(java.util.List) Resource(org.hl7.fhir.dstu2.model.Resource) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) InputStream(java.io.InputStream) XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Bundle(org.hl7.fhir.dstu3.model.Bundle) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu2.model.Resource) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.dstu3.model.UriType) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 3 with VersionConvertorFactory_10_30

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

the class TimingRepeatComponent10_30Test method testMedicationRequestConversion.

@Test
@DisplayName("Issue #383 - Test 10_30 TimingRepeatComponent with Timing.when as null")
public void testMedicationRequestConversion() {
    final int SET_COUNT = 11;
    org.hl7.fhir.dstu2.model.Timing src_timing = new org.hl7.fhir.dstu2.model.Timing();
    org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent src_timing_repeat = new org.hl7.fhir.dstu2.model.Timing.TimingRepeatComponent();
    src_timing_repeat.setCount(SET_COUNT);
    src_timing.setRepeat(src_timing_repeat);
    org.hl7.fhir.dstu3.model.Timing tgt_timing = (Timing) VersionConvertorFactory_10_30.convertType(src_timing);
    org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent tgt_timing_repeat = tgt_timing.getRepeat();
    Assertions.assertEquals(SET_COUNT, tgt_timing_repeat.getCount(), "Count field not preserved through version conversion.");
    Assertions.assertFalse(tgt_timing_repeat.hasWhen(), "hasWhen() should return false for this conversion.");
    Assertions.assertTrue(tgt_timing_repeat.getWhen().isEmpty(), "When no _when time_ is provided, getWhen() should return an empty list.");
}
Also used : Timing(org.hl7.fhir.dstu3.model.Timing) Timing(org.hl7.fhir.dstu3.model.Timing) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with VersionConvertorFactory_10_30

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

the class VersionConvertor method convertVersionNativeR2b.

public static byte[] convertVersionNativeR2b(String targetVer, Content cnt, Manager.FhirFormat format) throws IOException, Exception {
    org.hl7.fhir.dstu2016may.model.Resource r2b;
    switch(cnt.cntType) {
        case JSON:
            r2b = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt.focus);
            break;
        case XML:
            r2b = new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(cnt.focus);
            break;
        default:
            throw new FHIRException("Unsupported input format: " + cnt.cntType.toString());
    }
    if (VersionUtilities.isR2Ver(targetVer)) {
        org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_14_30.convertResource(r2b);
        org.hl7.fhir.dstu2.model.Resource r2 = VersionConvertorFactory_10_30.convertResource(r3);
        return getBytesDstu2(cnt, format, r2);
    } else if (VersionUtilities.isR2BVer(targetVer)) {
        return getBytesDstu2016(cnt, format, r2b);
    } else if (VersionUtilities.isR3Ver(targetVer)) {
        return getBytesDstu3(cnt, format, VersionConvertorFactory_14_30.convertResource(r2b));
    } else if (VersionUtilities.isR4Ver(targetVer)) {
        return getBytesR4(cnt, format, VersionConvertorFactory_14_40.convertResource(r2b));
    } else {
        throw new FHIRException("Target Version not supported yet: " + targetVer);
    }
}
Also used : Resource(org.hl7.fhir.dstu2016may.model.Resource) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with VersionConvertorFactory_10_30

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

the class AdministrativeGender10_30Test method testMedicationRequestConversion.

@Test
@DisplayName("Test 10_30 extension present, value is not")
public void testMedicationRequestConversion() throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream("/administrative_gender_null.json");
    org.hl7.fhir.dstu2.model.Patient dstu2 = (org.hl7.fhir.dstu2.model.Patient) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
    VersionConvertorFactory_10_30.convertResource(dstu2, new BaseAdvisor_10_30());
}
Also used : InputStream(java.io.InputStream) BaseAdvisor_10_30(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

InputStream (java.io.InputStream)3 BaseAdvisor_10_30 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30)3 DisplayName (org.junit.jupiter.api.DisplayName)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 VersionConvertorFactory_10_30 (org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30)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 Resource (org.hl7.fhir.dstu2016may.model.Resource)1 Bundle (org.hl7.fhir.dstu3.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)1 BundleType (org.hl7.fhir.dstu3.model.Bundle.BundleType)1