Search in sources :

Example 1 with BaseAdvisor_30_40

use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40 in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method loadResource.

private Resource loadResource(InputStream inputStream, FHIRVersion v) throws IOException, FHIRException {
    if (v == FHIRVersion._3_0_1) {
        org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(inputStream);
        return VersionConvertorFactory_30_40.convertResource(res, new BaseAdvisor_30_40(false));
    } else if (v == FHIRVersion._1_4_0) {
        org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(inputStream);
        return VersionConvertorFactory_14_40.convertResource(res);
    } else if (v == FHIRVersion._1_0_2) {
        org.hl7.fhir.dstu2.model.Resource res = new org.hl7.fhir.dstu2.formats.JsonParser().parse(inputStream);
        BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
        return VersionConvertorFactory_10_40.convertResource(res, advisor);
    } else if (v == FHIRVersion._4_0_0) {
        return new JsonParser().parse(inputStream);
    } else
        throw new Error("Unsupported version " + v);
}
Also used : Resource(org.hl7.fhir.r4.model.Resource) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) BaseAdvisor_30_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Example 2 with BaseAdvisor_30_40

use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40 in project org.hl7.fhir.core by hapifhir.

the class Device30_40Test method test1.

@Test
@DisplayName("Test r4 -> dstu3 device conversion.")
public void test1() throws IOException {
    InputStream r4_input = this.getClass().getResourceAsStream("/0_device_40.json");
    InputStream dstu3_expected_output = this.getClass().getResourceAsStream("/0_device_30.json");
    org.hl7.fhir.r4.model.Device r4_actual = (org.hl7.fhir.r4.model.Device) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_input);
    org.hl7.fhir.dstu3.model.Resource dstu3_conv = VersionConvertorFactory_30_40.convertResource(r4_actual, new BaseAdvisor_30_40(false));
    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));
}
Also used : InputStream(java.io.InputStream) BaseAdvisor_30_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with BaseAdvisor_30_40

use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40 in project org.hl7.fhir.core by hapifhir.

the class Device30_40Test method test2.

@Test
@DisplayName("Test r4 -> dstu3 device conversion, part 2.")
public void test2() throws IOException {
    InputStream r4_input = this.getClass().getResourceAsStream("/1_device_40.json");
    InputStream dstu3_expected_output = this.getClass().getResourceAsStream("/1_device_30.json");
    org.hl7.fhir.r4.model.Device r4_actual = (org.hl7.fhir.r4.model.Device) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_input);
    org.hl7.fhir.dstu3.model.Resource dstu3_conv = VersionConvertorFactory_30_40.convertResource(r4_actual, new BaseAdvisor_30_40(false));
    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_expected));
}
Also used : InputStream(java.io.InputStream) BaseAdvisor_30_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with BaseAdvisor_30_40

use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40 in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method saveResource.

private byte[] saveResource(Resource resource, FHIRVersion v) throws IOException, FHIRException {
    if (v == FHIRVersion._3_0_1) {
        org.hl7.fhir.dstu3.model.Resource res = VersionConvertorFactory_30_40.convertResource(resource, new BaseAdvisor_30_40(false));
        return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(res);
    } else if (v == FHIRVersion._1_4_0) {
        org.hl7.fhir.dstu2016may.model.Resource res = VersionConvertorFactory_14_40.convertResource(resource);
        return new org.hl7.fhir.dstu2016may.formats.JsonParser().composeBytes(res);
    } else if (v == FHIRVersion._1_0_2) {
        BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
        org.hl7.fhir.dstu2.model.Resource res = VersionConvertorFactory_10_40.convertResource(resource, advisor);
        return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(res);
    } else if (v == FHIRVersion._4_0_0) {
        return new JsonParser().composeBytes(resource);
    } else
        throw new Error("Unsupported version " + v);
}
Also used : Resource(org.hl7.fhir.r4.model.Resource) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) BaseAdvisor_30_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Aggregations

BaseAdvisor_30_40 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40)4 InputStream (java.io.InputStream)2 BaseAdvisor_10_40 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40)2 IGR2ConvertorAdvisor (org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor)2 JsonParser (org.hl7.fhir.r4.formats.JsonParser)2 Resource (org.hl7.fhir.r4.model.Resource)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2