Search in sources :

Example 21 with TargetElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent in project bunsen by cerner.

the class ConceptMaps method expandMappingsIterator.

private static Iterator<Mapping> expandMappingsIterator(ConceptMap map) {
    List<Mapping> mappings = new ArrayList<>();
    for (ConceptMapGroupComponent group : map.getGroup()) {
        for (SourceElementComponent element : group.getElement()) {
            for (TargetElementComponent target : element.getTarget()) {
                Mapping mapping = new Mapping();
                mapping.setConceptMapUri(map.getUrl());
                mapping.setConceptMapVersion(map.getVersion());
                try {
                    String sourceValue = map.getSource() instanceof UriType ? map.getSourceUriType().getValue() : map.getSourceUriType().getValue();
                    mapping.setSourceValueSet(sourceValue);
                    String targetValue = map.getTarget() instanceof UriType ? map.getTargetUriType().getValue() : map.getTargetUriType().getValue();
                    mapping.setTargetValueSet(targetValue);
                } catch (FHIRException fhirException) {
                    // an exception.
                    throw new RuntimeException(fhirException);
                }
                mapping.setSourceSystem(group.getSource());
                mapping.setSourceValue(element.getCode());
                mapping.setTargetSystem(group.getTarget());
                mapping.setTargetValue(target.getCode());
                if (target.getEquivalence() != null) {
                    mapping.setEquivalence(target.getEquivalence().toCode());
                }
                mappings.add(mapping);
            }
        }
    }
    return mappings.iterator();
}
Also used : ArrayList(java.util.ArrayList) TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) Mapping(com.cerner.bunsen.codes.Mapping) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent) UriType(org.hl7.fhir.r4.model.UriType)

Example 22 with TargetElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent in project bunsen by cerner.

the class ConceptMaps method expandMappingsIterator.

private static Iterator<Mapping> expandMappingsIterator(ConceptMap map) {
    List<Mapping> mappings = new ArrayList<>();
    for (ConceptMapGroupComponent group : map.getGroup()) {
        for (SourceElementComponent element : group.getElement()) {
            for (TargetElementComponent target : element.getTarget()) {
                Mapping mapping = new Mapping();
                mapping.setConceptMapUri(map.getUrl());
                mapping.setConceptMapVersion(map.getVersion());
                try {
                    String sourceValue = map.getSource() instanceof UriType ? map.getSourceUriType().getValue() : map.getSourceReference().getReference();
                    mapping.setSourceValueSet(sourceValue);
                    String targetValue = map.getTarget() instanceof UriType ? map.getTargetUriType().getValue() : map.getTargetReference().getReference();
                    mapping.setTargetValueSet(targetValue);
                } catch (FHIRException fhirException) {
                    // an exception.
                    throw new RuntimeException(fhirException);
                }
                mapping.setSourceSystem(group.getSource());
                mapping.setSourceValue(element.getCode());
                mapping.setTargetSystem(group.getTarget());
                mapping.setTargetValue(target.getCode());
                if (target.getEquivalence() != null) {
                    mapping.setEquivalence(target.getEquivalence().toCode());
                }
                mappings.add(mapping);
            }
        }
    }
    return mappings.iterator();
}
Also used : ArrayList(java.util.ArrayList) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) Mapping(com.cerner.bunsen.spark.codes.Mapping) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 23 with TargetElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent in project kindling by HL7.

the class CodeListToValueSetParser method processV3Map.

private void processV3Map(ConceptMap cm, String url, String code, String v3map) throws Exception {
    if (Utilities.noString(v3map))
        return;
    for (String m : v3map.split(",")) {
        // analyse m
        String[] n = m.split("\\(");
        String comm = (n.length > 1) ? n[1].substring(0, n[1].length() - 1) : null;
        n = n[0].split("\\.");
        if (n.length != 2)
            throw new Exception("Error processing v3 map value for " + cm.getName() + "." + code + " '" + m + "' - format should be CodeSystem.code (comment) - the comment bit is optional");
        String rel = null;
        String tbl = n[0];
        if (Utilities.existsInList(n[0].substring(0, 1), "=", "~", ">", "<")) {
            rel = n[0].substring(0, 1);
            tbl = n[0].substring(1);
        }
        String cd = n[1];
        ConceptMapGroupComponent grp = getGroup(cm, url, "http://terminology.hl7.org/CodeSystem/v3-" + tbl);
        SourceElementComponent src = getSource(grp, code);
        TargetElementComponent tgt = src.addTarget();
        tgt.setCode(cd.trim());
        tgt.setComment(comm);
        if (rel == null || rel.equals("="))
            tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
        else if (rel.equals("~"))
            tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
        else if (rel.equals("<"))
            tgt.setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
        else if (rel.equals(">")) {
            tgt.setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
            if (!tgt.hasComment())
                throw new Exception("Missing comment for narrower match on " + cm.getName() + "/" + code);
        } else
            throw new Exception("Unable to understand relationship character " + rel);
    }
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 24 with TargetElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent in project kindling by HL7.

the class CodeListToValueSetParser method processV2Map.

private void processV2Map(ConceptMap cm, String url, String code, String v2map) throws Exception {
    if (Utilities.noString(v2map))
        return;
    for (String m : v2map.split(",")) {
        // analyse m
        String[] n = m.split("\\(");
        String comm = (n.length > 1) ? n[1].substring(0, n[1].length() - 1) : null;
        n = n[0].split("\\.");
        if (n.length != 2)
            throw new Exception("Error processing v2 map value for " + cm.getName() + "." + code + " '" + m + "' - format should be CodeSystem.code (comment) - the comment bit is optional");
        String rel = n[0].substring(0, 1);
        String tbl = n[0].substring(1);
        String cd = n[1];
        ConceptMapGroupComponent grp = getGroup(cm, url, "http://terminology.hl7.org/CodeSystem/v2-" + tbl);
        SourceElementComponent src = getSource(grp, code);
        TargetElementComponent tgt = src.addTarget();
        tgt.setCode(cd.trim());
        tgt.setComment(comm);
        if (rel.equals("="))
            tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
        else if (rel.equals("~"))
            tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
        else if (rel.equals(">"))
            tgt.setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
        else if (rel.equals("<")) {
            tgt.setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
            if (!tgt.hasComment())
                throw new Exception("Missing comment for narrower match on " + cm.getName() + "/" + code);
        } else
            throw new Exception("Unable to understand relationship character " + rel);
    }
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 25 with TargetElementComponent

use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent in project kindling by HL7.

the class Publisher method buildConceptMap.

private ConceptMap buildConceptMap(String path, ValueSet vs, ResourceDefn rd) throws EOperationOutcome, FHIRException, IOException {
    ConceptMap cm = new ConceptMap();
    cm.setUserData("path", "sc-" + vs.getUserString("path"));
    cm.setUserData("resource-definition", rd);
    cm.setId("sc-" + vs.getId());
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setVersion(page.getVersion().toCode());
    cm.setName(vs.getName() + "CanonicalMap");
    cm.setTitle("Canonical Mapping for \"" + vs.present() + "\"");
    cm.setStatus(PublicationStatus.DRAFT);
    cm.setDate(vs.getDate());
    cm.setPublisher(vs.getPublisher());
    cm.addContact(vs.getContactFirstRep());
    cm.setDescription("Canonical Mapping for \"" + vs.getDescription() + "\"");
    cm.setSource(new CanonicalType(vs.getUrl()));
    cm.setTarget(new CanonicalType("http://hl7.org/fhir/ValueSet/resource-status"));
    List<String> canonical = page.getDefinitions().getStatusCodes().get("@code");
    List<String> self = page.getDefinitions().getStatusCodes().get(path);
    ConceptMapGroupComponent grp = cm.addGroup();
    grp.setTarget("http://hl7.org/fhir/resource-status");
    grp.setSource(vs.getCompose().getIncludeFirstRep().getSystem());
    for (int i = 0; i < self.size(); i++) {
        if (!Utilities.noString(self.get(i))) {
            String cc = canonical.get(i);
            String sc = self.get(i);
            SourceElementComponent e = grp.addElement();
            e.setCode(sc);
            TargetElementComponent t = e.addTarget();
            t.setCode(cc);
            t.setRelationship(ConceptMapRelationship.EQUIVALENT);
        }
    }
    if (!grp.hasElement())
        return null;
    page.getConceptMaps().see(cm, page.packageInfo());
    statusCodeConceptMaps.add(cm);
    return cm;
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)11 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 SourceElementComponent (org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)9 TargetElementComponent (org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent)9 HashMap (java.util.HashMap)8 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)8 ArrayList (java.util.ArrayList)7 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)6 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)6 TargetElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent)6 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)6 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)6 TargetElementComponent (org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent)6 SourceElementComponent (org.hl7.fhir.r4b.model.ConceptMap.SourceElementComponent)6 HashSet (java.util.HashSet)5 TargetElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.TargetElementComponent)5 ConceptMapGroupComponent (org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent)5 TargetElementComponent (org.hl7.fhir.r4b.model.ConceptMap.TargetElementComponent)5 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)4 TargetElementComponent (org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent)3