Search in sources :

Example 1 with BaseAdvisor_10_30

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

the class ValueSet10_30 method convertValueSet.

public static org.hl7.fhir.dstu2.model.ValueSet convertValueSet(org.hl7.fhir.dstu3.model.ValueSet src, BaseAdvisor_10_30 advisor) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu2.model.ValueSet tgt = new org.hl7.fhir.dstu2.model.ValueSet();
    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
    if (src.hasUrlElement())
        tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
    for (org.hl7.fhir.dstu3.model.Identifier i : src.getIdentifier()) tgt.setIdentifier(Identifier10_30.convertIdentifier(i));
    if (src.hasVersionElement())
        tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
    if (src.hasNameElement())
        tgt.setNameElement(String10_30.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisherElement())
        tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu3.model.ContactDetail t : src.getContact()) tgt.addContact(convertValueSetContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
    tgt.setLockedDate(src.getCompose().getLockedDate());
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu3.model.UsageContext t : src.getUseContext()) if (t.hasValueCodeableConcept())
        tgt.addUseContext(CodeableConcept10_30.convertCodeableConcept(t.getValueCodeableConcept()));
    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction()) tgt.addUseContext(CodeableConcept10_30.convertCodeableConcept(t));
    if (src.hasImmutableElement())
        tgt.setImmutableElement(Boolean10_30.convertBoolean(src.getImmutableElement()));
    if (src.hasPurpose())
        tgt.setRequirements(src.getPurpose());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    if (src.hasExtensibleElement())
        tgt.setExtensibleElement(Boolean10_30.convertBoolean(src.getExtensibleElement()));
    org.hl7.fhir.dstu3.model.CodeSystem srcCS = (CodeSystem) src.getUserData("r2-cs");
    if (srcCS == null)
        srcCS = advisor.getCodeSystem(src);
    if (srcCS != null) {
        tgt.getCodeSystem().setSystem(srcCS.getUrl());
        tgt.getCodeSystem().setVersion(srcCS.getVersion());
        tgt.getCodeSystem().setCaseSensitive(srcCS.getCaseSensitive());
        for (org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent cs : srcCS.getConcept()) processConcept(tgt.getCodeSystem().getConcept(), cs, srcCS);
    }
    if (src.hasCompose())
        tgt.setCompose(convertValueSetComposeComponent(src.getCompose(), srcCS == null ? null : srcCS.getUrl()));
    if (src.hasExpansion())
        tgt.setExpansion(convertValueSetExpansionComponent(src.getExpansion()));
    return tgt;
}
Also used : CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent)

Example 2 with BaseAdvisor_10_30

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

the class ValueSet10_30 method convertValueSet.

public static org.hl7.fhir.dstu3.model.ValueSet convertValueSet(org.hl7.fhir.dstu2.model.ValueSet src, BaseAdvisor_10_30 advisor) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu3.model.ValueSet tgt = new org.hl7.fhir.dstu3.model.ValueSet();
    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
    if (src.hasUrlElement())
        tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.addIdentifier(Identifier10_30.convertIdentifier(src.getIdentifier()));
    if (src.hasVersionElement())
        tgt.setVersionElement(String10_30.convertString(src.getVersionElement()));
    if (src.hasNameElement())
        tgt.setNameElement(String10_30.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean10_30.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisherElement())
        tgt.setPublisherElement(String10_30.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact()) tgt.addContact(convertValueSetContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime10_30.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_30.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept10_30.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept10_30.convertCodeableConceptToUsageContext(t));
    if (src.hasImmutableElement())
        tgt.setImmutableElement(Boolean10_30.convertBoolean(src.getImmutableElement()));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    if (src.hasExtensibleElement())
        tgt.setExtensibleElement(Boolean10_30.convertBoolean(src.getExtensibleElement()));
    if (src.hasCompose()) {
        if (src.hasCompose())
            tgt.setCompose(convertValueSetComposeComponent(src.getCompose()));
        tgt.getCompose().setLockedDate(src.getLockedDate());
    }
    // TODO
    if (src.hasCodeSystem() && advisor != null) {
        org.hl7.fhir.dstu3.model.CodeSystem tgtcs = new org.hl7.fhir.dstu3.model.CodeSystem();
        ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgtcs);
        tgtcs.setUrl(src.getCodeSystem().getSystem());
        tgtcs.setIdentifier(Identifier10_30.convertIdentifier(src.getIdentifier()));
        tgtcs.setVersion(src.getCodeSystem().getVersion());
        tgtcs.setName(src.getName() + " Code System");
        tgtcs.setStatusElement(Enumerations10_30.convertConformanceResourceStatus(src.getStatusElement()));
        if (src.hasExperimental())
            tgtcs.setExperimental(src.getExperimental());
        tgtcs.setPublisher(src.getPublisher());
        for (org.hl7.fhir.dstu2.model.ValueSet.ValueSetContactComponent t : src.getContact()) tgtcs.addContact(convertValueSetContactComponent(t));
        if (src.hasDate())
            tgtcs.setDate(src.getDate());
        tgtcs.setDescription(src.getDescription());
        for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_30.isJurisdiction(t))
            tgtcs.addJurisdiction(CodeableConcept10_30.convertCodeableConcept(t));
        else
            tgtcs.addUseContext(CodeableConcept10_30.convertCodeableConceptToUsageContext(t));
        tgtcs.setPurpose(src.getRequirements());
        tgtcs.setCopyright(src.getCopyright());
        tgtcs.setContent(CodeSystemContentMode.COMPLETE);
        tgtcs.setCaseSensitive(src.getCodeSystem().getCaseSensitive());
        for (org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent cs : src.getCodeSystem().getConcept()) processConcept(tgtcs.getConcept(), cs, tgtcs);
        advisor.handleCodeSystem(tgtcs, tgt);
        tgt.setUserData("r2-cs", tgtcs);
        tgt.getCompose().addInclude().setSystem(tgtcs.getUrl());
    }
    if (src.hasExpansion())
        tgt.setExpansion(convertValueSetExpansionComponent(src.getExpansion()));
    return tgt;
}
Also used : CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) ValueSet(org.hl7.fhir.dstu2.model.ValueSet)

Example 3 with BaseAdvisor_10_30

use of org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_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)

Example 4 with BaseAdvisor_10_30

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

the class AllergyIntolerance10_30Test method testMedicationRequestConversion.

@ParameterizedTest
@MethodSource("filesPaths")
@DisplayName("Test 10_30 AllergyIntolerance conversion")
public void testMedicationRequestConversion(String dstu2_path, String stu_path) throws IOException {
    InputStream dstu2_input = this.getClass().getResourceAsStream(dstu2_path);
    InputStream stu_exepected_input = this.getClass().getResourceAsStream(stu_path);
    org.hl7.fhir.dstu2.model.AllergyIntolerance dstu2 = (org.hl7.fhir.dstu2.model.AllergyIntolerance) new org.hl7.fhir.dstu2.formats.JsonParser().parse(dstu2_input);
    org.hl7.fhir.dstu3.model.Resource stu_actual = VersionConvertorFactory_10_30.convertResource(dstu2, new BaseAdvisor_10_30());
    org.hl7.fhir.dstu3.formats.JsonParser stu_parser = new org.hl7.fhir.dstu3.formats.JsonParser();
    org.hl7.fhir.dstu3.model.Resource stu_expected = stu_parser.parse(stu_exepected_input);
    if (!stu_expected.equalsDeep(stu_actual)) {
        System.out.println("Expected");
        System.out.println(stu_parser.composeString(stu_expected));
        System.out.println();
        System.out.println("Actual");
        System.out.println(stu_parser.composeString(stu_actual));
    }
    Assertions.assertTrue(stu_expected.equalsDeep(stu_actual), "Failed comparing\n" + stu_parser.composeString(stu_actual) + "\nand\n" + stu_parser.composeString(stu_expected));
}
Also used : InputStream(java.io.InputStream) BaseAdvisor_10_30(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

InputStream (java.io.InputStream)2 BaseAdvisor_10_30 (org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_30)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2 CodeSystem (org.hl7.fhir.dstu3.model.CodeSystem)2 DisplayName (org.junit.jupiter.api.DisplayName)2 ConceptDefinitionComponent (org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1