Search in sources :

Example 1 with VersionConvertorFactory_10_40

use of org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_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 VersionConvertorFactory_10_40

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

the class VersionConvertorPrimitiveType10_50Test method testNullValueDstu2Primitive.

@ParameterizedTest(name = "Testing dstu2 -> r5 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.r4.model.PrimitiveType) VersionConvertorFactory_10_40.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 3 with VersionConvertorFactory_10_40

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

the class Procedure10_40Test method testProcedureConversion.

@Test
@DisplayName("Test 10_40 Procedure conversion")
public void testProcedureConversion() throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream("/0_procedure_10.json");
    InputStream r4_exepected_input = this.getClass().getResourceAsStream("/0_procedure_40.json");
    org.hl7.fhir.dstu2.model.Procedure dstu2 = (org.hl7.fhir.dstu2.model.Procedure) 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 4 with VersionConvertorFactory_10_40

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

the class Expression40Test method testAdvisorExpressionConversion40_10.

@Test
@DisplayName("Test Advisor is used in Expression R4 -> DSTU3 conversion.")
public void testAdvisorExpressionConversion40_10() throws IOException {
    InputStream r4_stream = this.getClass().getResourceAsStream("/questionnaire_with_expression_40.json");
    org.hl7.fhir.r4.model.Questionnaire r4_input = (org.hl7.fhir.r4.model.Questionnaire) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_stream);
    InputStream r2_stream = this.getClass().getResourceAsStream("/questionnaire_with_converted_expression_40_10.json");
    org.hl7.fhir.dstu2.model.Questionnaire r2_expected_output = (org.hl7.fhir.dstu2.model.Questionnaire) new org.hl7.fhir.dstu2.formats.JsonParser().parse(r2_stream);
    org.hl7.fhir.dstu2.model.Questionnaire convertedDstu2Questionnaire = (org.hl7.fhir.dstu2.model.Questionnaire) VersionConvertorFactory_10_40.convertResource(r4_input, new ExpressionAdvisor40());
    org.hl7.fhir.dstu2.formats.JsonParser dstu2_parser = new org.hl7.fhir.dstu2.formats.JsonParser();
    String composeString1 = dstu2_parser.composeString(convertedDstu2Questionnaire);
    String composeString2 = dstu2_parser.composeString(r2_expected_output);
    System.out.println("Expected out ->\n" + composeString2 + "\n\nActual out ->\n" + composeString1);
    Assertions.assertTrue(r2_expected_output.equalsDeep(convertedDstu2Questionnaire));
}
Also used : InputStream(java.io.InputStream) ExpressionAdvisor40(org.hl7.fhir.convertors.advisors.support.ExpressionAdvisor40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with VersionConvertorFactory_10_40

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

the class ValueSet10_40Test method testValueSetConversion.

@Test
@DisplayName("Test 10_40 ValueSet conversion")
public void testValueSetConversion() throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream("/0_valueset_vision_base_codes_10.json");
    InputStream r4_exepected_input = this.getClass().getResourceAsStream("/0_valueset_vision_base_codes_40.json");
    org.hl7.fhir.dstu2.model.ValueSet dstu2 = (org.hl7.fhir.dstu2.model.ValueSet) 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();
    JsonParser parser = new JsonParser();
    String composeString = parser.composeString(r4_actual);
    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) JsonParser(org.hl7.fhir.r4.formats.JsonParser) JsonParser(org.hl7.fhir.r4.formats.JsonParser) Test(org.junit.jupiter.api.Test) 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