Search in sources :

Example 1 with VersionConvertor_10_30

use of org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30 in project org.hl7.fhir.core by hapifhir.

the class ConceptMap10_30 method convertConceptMap.

public static org.hl7.fhir.dstu3.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.dstu3.model.ConceptMap tgt = new org.hl7.fhir.dstu3.model.ConceptMap();
    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
    if (src.hasUrlElement())
        tgt.setUrlElement(Uri10_30.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.setIdentifier(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.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(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.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    if (src.hasSource())
        tgt.setSource(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getSource()));
    if (src.hasTarget())
        tgt.setTarget(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getTarget()));
    for (org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent t : src.getElement()) {
        List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> ws = convertSourceElementComponent(t);
        for (SourceElementComponentWrapper<ConceptMap.SourceElementComponent> w : ws) getGroup(tgt, w.getSource(), w.getTarget()).addElement(w.getComp());
    }
    return tgt;
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) SourceElementComponentWrapper(org.hl7.fhir.convertors.SourceElementComponentWrapper) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap)

Example 2 with VersionConvertor_10_30

use of org.hl7.fhir.convertors.conv10_30.VersionConvertor_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 VersionConvertor_10_30

use of org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30 in project org.hl7.fhir.core by hapifhir.

the class VersionConvertorPrimitiveTypeTests method testDirectConversion.

@ParameterizedTest(name = "Test index: {index} Source Class={1} First Value={3} Second Class={4} Second Value={6}")
@MethodSource("getDirectConversionParams")
public <K, L> void testDirectConversion(Class<K> srcTypeClazz, Class<L> tgtTypeClazz, Function<K, L> convertFunction, String[] srcStrings, String[] tgtStrings) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
    ConversionContext10_30.INSTANCE.init(mock(VersionConvertor_10_30.class), CONTEXT_PATH);
    ConversionContext10_40.INSTANCE.init(mock(VersionConvertor_10_40.class), CONTEXT_PATH);
    ConversionContext10_50.INSTANCE.init(mock(VersionConvertor_10_50.class), CONTEXT_PATH);
    ConversionContext14_50.INSTANCE.init(mock(VersionConvertor_14_50.class), CONTEXT_PATH);
    ConversionContext30_50.INSTANCE.init(mock(VersionConvertor_30_50.class), CONTEXT_PATH);
    ConversionContext40_50.INSTANCE.init(mock(VersionConvertor_40_50.class), CONTEXT_PATH);
    Method srcSetValueAsStringMethod = srcTypeClazz.getMethod("setValueAsString", String.class);
    Method srcGetValueAsString = srcTypeClazz.getMethod("getValueAsString");
    Method srcHasValue = srcTypeClazz.getMethod("hasValue");
    for (int i = 0; i < srcStrings.length; i++) {
        K srcInstance = srcTypeClazz.getDeclaredConstructor().newInstance();
        srcSetValueAsStringMethod.invoke(srcInstance, srcStrings[i]);
        String srcValueAsString = (String) srcGetValueAsString.invoke(srcInstance);
        Assertions.assertEquals(srcStrings[i], srcValueAsString);
        boolean srcHasValueReturn = (boolean) srcHasValue.invoke(srcInstance);
        L tgtInstance = convertFunction.apply(srcInstance);
        Method tgtGetValueAsString = tgtTypeClazz.getMethod("getValueAsString");
        Method tgtHasValue = tgtTypeClazz.getMethod("hasValue");
        if (srcHasValueReturn) {
            String tgtValueAsString = (String) tgtGetValueAsString.invoke(tgtInstance);
            Assertions.assertEquals(tgtStrings[i], tgtValueAsString);
        } else {
            boolean tgtHasValueReturn = (boolean) tgtHasValue.invoke(tgtInstance);
            Assertions.assertFalse(tgtHasValueReturn);
        }
    }
    ConversionContext10_30.INSTANCE.close(CONTEXT_PATH);
    ConversionContext10_40.INSTANCE.close(CONTEXT_PATH);
    ConversionContext10_50.INSTANCE.close(CONTEXT_PATH);
    ConversionContext14_50.INSTANCE.close(CONTEXT_PATH);
    ConversionContext30_50.INSTANCE.close(CONTEXT_PATH);
    ConversionContext40_50.INSTANCE.close(CONTEXT_PATH);
}
Also used : VersionConvertor_30_50(org.hl7.fhir.convertors.conv30_50.VersionConvertor_30_50) VersionConvertor_14_50(org.hl7.fhir.convertors.conv14_50.VersionConvertor_14_50) VersionConvertor_40_50(org.hl7.fhir.convertors.conv40_50.VersionConvertor_40_50) VersionConvertor_10_40(org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40) VersionConvertor_10_50(org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50) Method(java.lang.reflect.Method) VersionConvertor_10_30(org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Method (java.lang.reflect.Method)1 SourceElementComponentWrapper (org.hl7.fhir.convertors.SourceElementComponentWrapper)1 VersionConvertor_10_30 (org.hl7.fhir.convertors.conv10_30.VersionConvertor_10_30)1 VersionConvertor_10_40 (org.hl7.fhir.convertors.conv10_40.VersionConvertor_10_40)1 VersionConvertor_10_50 (org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50)1 VersionConvertor_14_50 (org.hl7.fhir.convertors.conv14_50.VersionConvertor_14_50)1 VersionConvertor_30_50 (org.hl7.fhir.convertors.conv30_50.VersionConvertor_30_50)1 VersionConvertor_40_50 (org.hl7.fhir.convertors.conv40_50.VersionConvertor_40_50)1 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)1 CodeSystem (org.hl7.fhir.dstu3.model.CodeSystem)1 ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1