Search in sources :

Example 1 with SourceElementComponentWrapper

use of org.hl7.fhir.convertors.SourceElementComponentWrapper 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 SourceElementComponentWrapper

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

the class ConceptMap14_30 method convertConceptMap.

public static org.hl7.fhir.dstu3.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2016may.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();
    ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyDomainResource(src, tgt);
    if (src.hasUrl())
        tgt.setUrlElement(Uri14_30.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.setIdentifier(Identifier14_30.convertIdentifier(src.getIdentifier()));
    if (src.hasVersion())
        tgt.setVersionElement(String14_30.convertString(src.getVersionElement()));
    if (src.hasName())
        tgt.setNameElement(String14_30.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations14_30.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean14_30.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisher())
        tgt.setPublisherElement(String14_30.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2016may.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime14_30.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2016may.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_14_30.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept14_30.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept14_30.convertCodeableConceptToUsageContext(t));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    if (src.hasSource())
        tgt.setSource(ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().convertType(src.getSource()));
    if (src.hasTarget())
        tgt.setTarget(ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().convertType(src.getTarget()));
    for (org.hl7.fhir.dstu2016may.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 3 with SourceElementComponentWrapper

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

the class ConceptMap10_40 method convertConceptMap.

public static org.hl7.fhir.r4.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r4.model.ConceptMap tgt = new org.hl7.fhir.r4.model.ConceptMap();
    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
    if (src.hasUrlElement())
        tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.setIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
    if (src.hasVersionElement())
        tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
    if (src.hasNameElement())
        tgt.setNameElement(String10_40.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisherElement())
        tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_40.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    org.hl7.fhir.r4.model.Type r = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getSource());
    tgt.setSource(r instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) r).getReference()) : r);
    r = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getTarget());
    tgt.setTarget(r instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) r).getReference()) : r);
    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.r4.model.ConceptMap) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) SourceElementComponentWrapper(org.hl7.fhir.convertors.SourceElementComponentWrapper)

Example 4 with SourceElementComponentWrapper

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

the class ConceptMap14_50 method convertConceptMap.

public static org.hl7.fhir.r5.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2016may.model.ConceptMap src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.ConceptMap tgt = new org.hl7.fhir.r5.model.ConceptMap();
    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt);
    if (src.hasUrl())
        tgt.setUrlElement(Uri14_50.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.addIdentifier(Identifier14_50.convertIdentifier(src.getIdentifier()));
    if (src.hasVersion())
        tgt.setVersionElement(String14_50.convertString(src.getVersionElement()));
    if (src.hasName())
        tgt.setNameElement(String14_50.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations14_50.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean14_50.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisher())
        tgt.setPublisherElement(String14_50.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2016may.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime14_50.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2016may.model.CodeableConcept t : src.getUseContext()) if (CodeableConcept14_50.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept14_50.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept14_50.convertCodeableConceptToUsageContext(t));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    org.hl7.fhir.r5.model.DataType tt = ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getSource());
    tgt.setSource(tt instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) tt).getReference()) : tt);
    tt = ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getTarget());
    tgt.setTarget(tt instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) tt).getReference()) : tt);
    for (org.hl7.fhir.dstu2016may.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 : CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) SourceElementComponentWrapper(org.hl7.fhir.convertors.SourceElementComponentWrapper)

Example 5 with SourceElementComponentWrapper

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

the class StructureMapUtilities method translate.

public Base translate(TransformContext context, StructureMap map, Base source, String conceptMapUrl, String fieldToReturn) throws FHIRException {
    Coding src = new Coding();
    if (source.isPrimitive()) {
        src.setCode(source.primitiveValue());
    } else if ("Coding".equals(source.fhirType())) {
        Base[] b = source.getProperty("system".hashCode(), "system", true);
        if (b.length == 1)
            src.setSystem(b[0].primitiveValue());
        b = source.getProperty("code".hashCode(), "code", true);
        if (b.length == 1)
            src.setCode(b[0].primitiveValue());
    } else if ("CE".equals(source.fhirType())) {
        Base[] b = source.getProperty("codeSystem".hashCode(), "codeSystem", true);
        if (b.length == 1)
            src.setSystem(b[0].primitiveValue());
        b = source.getProperty("code".hashCode(), "code", true);
        if (b.length == 1)
            src.setCode(b[0].primitiveValue());
    } else
        throw new FHIRException("Unable to translate source " + source.fhirType());
    String su = conceptMapUrl;
    if (conceptMapUrl.equals("http://hl7.org/fhir/ConceptMap/special-oid2uri")) {
        String uri = worker.oid2Uri(src.getCode());
        if (uri == null)
            uri = "urn:oid:" + src.getCode();
        if ("uri".equals(fieldToReturn))
            return new UriType(uri);
        else
            throw new FHIRException("Error in return code");
    } else {
        ConceptMap cmap = null;
        if (conceptMapUrl.startsWith("#")) {
            for (Resource r : map.getContained()) {
                if (r instanceof ConceptMap && ((ConceptMap) r).getId().equals(conceptMapUrl.substring(1))) {
                    cmap = (ConceptMap) r;
                    su = map.getUrl() + "#" + conceptMapUrl;
                }
            }
            if (cmap == null)
                throw new FHIRException("Unable to translate - cannot find map " + conceptMapUrl);
        } else {
            if (conceptMapUrl.contains("#")) {
                String[] p = conceptMapUrl.split("\\#");
                StructureMap mapU = worker.fetchResource(StructureMap.class, p[0]);
                for (Resource r : mapU.getContained()) {
                    if (r instanceof ConceptMap && ((ConceptMap) r).getId().equals(p[1])) {
                        cmap = (ConceptMap) r;
                        su = conceptMapUrl;
                    }
                }
            }
            if (cmap == null)
                cmap = worker.fetchResource(ConceptMap.class, conceptMapUrl);
        }
        Coding outcome = null;
        boolean done = false;
        String message = null;
        if (cmap == null) {
            if (services == null)
                message = "No map found for " + conceptMapUrl;
            else {
                outcome = services.translate(context.getAppInfo(), src, conceptMapUrl);
                done = true;
            }
        } else {
            List<SourceElementComponentWrapper> list = new ArrayList<SourceElementComponentWrapper>();
            for (ConceptMapGroupComponent g : cmap.getGroup()) {
                for (SourceElementComponent e : g.getElement()) {
                    if (!src.hasSystem() && src.getCode().equals(e.getCode()))
                        list.add(new SourceElementComponentWrapper(g, e));
                    else if (src.hasSystem() && src.getSystem().equals(g.getSource()) && src.getCode().equals(e.getCode()))
                        list.add(new SourceElementComponentWrapper(g, e));
                }
            }
            if (list.size() == 0)
                done = true;
            else if (list.get(0).comp.getTarget().size() == 0)
                message = "Concept map " + su + " found no translation for " + src.getCode();
            else {
                for (TargetElementComponent tgt : list.get(0).comp.getTarget()) {
                    if (tgt.getEquivalence() == null || EnumSet.of(ConceptMapEquivalence.EQUAL, ConceptMapEquivalence.RELATEDTO, ConceptMapEquivalence.EQUIVALENT, ConceptMapEquivalence.WIDER).contains(tgt.getEquivalence())) {
                        if (done) {
                            message = "Concept map " + su + " found multiple matches for " + src.getCode();
                            done = false;
                        } else {
                            done = true;
                            outcome = new Coding().setCode(tgt.getCode()).setSystem(list.get(0).group.getTarget());
                        }
                    } else if (tgt.getEquivalence() == ConceptMapEquivalence.UNMATCHED) {
                        done = true;
                    }
                }
                if (!done)
                    message = "Concept map " + su + " found no usable translation for " + src.getCode();
            }
        }
        if (!done)
            throw new FHIRException(message);
        if (outcome == null)
            return null;
        if ("code".equals(fieldToReturn))
            return new CodeType(outcome.getCode());
        else
            return outcome;
    }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMap(org.hl7.fhir.r4b.model.StructureMap) TargetElementComponent(org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)

Aggregations

SourceElementComponentWrapper (org.hl7.fhir.convertors.SourceElementComponentWrapper)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)3 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)3 ArrayList (java.util.ArrayList)2 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)2 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)2 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)2 Base (org.hl7.fhir.dstu3.model.Base)1 CodeType (org.hl7.fhir.dstu3.model.CodeType)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)1 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent)1 Resource (org.hl7.fhir.dstu3.model.Resource)1 UriType (org.hl7.fhir.dstu3.model.UriType)1 Base (org.hl7.fhir.r4.model.Base)1 CodeType (org.hl7.fhir.r4.model.CodeType)1 Coding (org.hl7.fhir.r4.model.Coding)1 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)1