Search in sources :

Example 1 with TargetElementComponent

use of org.hl7.fhir.dstu3.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) 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)

Aggregations

ArrayList (java.util.ArrayList)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 UriType (org.hl7.fhir.dstu3.model.UriType)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1