Search in sources :

Example 51 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method buildCoding.

private Coding buildCoding(String uri, String code) throws FHIRException {
    // if we can get this as a valueSet, we will
    String system = null;
    String display = null;
    String version = null;
    ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri);
    if (vs != null) {
        ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false);
        if (vse.getError() != null)
            throw new FHIRException(vse.getError());
        CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
        for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) {
            if (t.hasCode())
                b.append(t.getCode());
            if (code.equals(t.getCode()) && t.hasSystem()) {
                system = t.getSystem();
                version = t.getVersion();
                display = t.getDisplay();
                break;
            }
            if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
                system = t.getSystem();
                version = t.getVersion();
                display = t.getDisplay();
                break;
            }
        }
        if (system == null)
            throw new FHIRException("The code '" + code + "' is not in the value set '" + uri + "' (valid codes: " + b.toString() + "; also checked displays)");
    } else {
        system = uri;
    }
    ValidationResult vr = worker.validateCode(terminologyServiceOptions.setVersionFlexible(true), system, version, code, null);
    if (vr != null && vr.getDisplay() != null)
        display = vr.getDisplay();
    return new Coding().setSystem(system).setCode(code).setDisplay(display);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 52 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project snowstorm by IHTSDO.

the class HapiValueSetMapper method addExpansion.

private void addExpansion(ValueSet vs, List<ConceptMini> concepts, Map<String, Concept> conceptDetails, List<LanguageDialect> designations, Boolean includeDesignations) {
    // Will autocreate
    ValueSetExpansionComponent expansion = vs.getExpansion();
    for (ConceptMini concept : concepts) {
        ValueSetExpansionContainsComponent component = expansion.addContains().setCode(concept.getConceptId()).setSystem(SNOMED_URI);
        if (conceptDetails != null && conceptDetails.containsKey(concept.getConceptId())) {
            Concept c = conceptDetails.get(concept.getConceptId());
            for (Description d : c.getActiveDescriptions()) {
                if (includeDesignations && d.hasAcceptability(designations)) {
                    component.addDesignation(asDesignation(d));
                }
                // Use the preferred term in the specified display language.
                if (!designations.isEmpty() && d.hasAcceptability(Concepts.PREFERRED, designations.get(0)) && d.getTypeId().equals(Concepts.SYNONYM)) {
                    component.setDisplay(d.getTerm());
                    boolean inactive = !c.isActive();
                    if (inactive) {
                        component.setInactive(inactive);
                    }
                }
            }
        }
    }
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) Concept(org.snomed.snowstorm.core.data.domain.Concept) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) Description(org.snomed.snowstorm.core.data.domain.Description) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini)

Example 53 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project eCRNow by drajer-health.

the class ApplicationUtils method convertValueSetsToString.

public static Set<String> convertValueSetsToString(Set<ValueSet> valuesets) {
    Set<String> retVal = new HashSet<>();
    ValueSetExpansionComponent valueSetExpansionComponent;
    List<ValueSetExpansionContainsComponent> valueSetExpansionContainsComponentList;
    if (valuesets != null && !valuesets.isEmpty()) {
        for (ValueSet vs : valuesets) {
            logger.debug("Value Set Id = {}", vs.getId());
            valueSetExpansionComponent = vs.getExpansion();
            valueSetExpansionContainsComponentList = valueSetExpansionComponent.getContains();
            for (ValueSetExpansionContainsComponent vscomp : valueSetExpansionContainsComponentList) {
                if (vscomp.getSystem() != null && vscomp.getCode() != null) {
                    retVal.add(vscomp.getSystem() + "|" + vscomp.getCode());
                }
            }
        }
    }
    return retVal;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r4.model.ValueSet) HashSet(java.util.HashSet)

Example 54 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project synthea by synthetichealth.

the class ValidationSupportR4 method validateCodeUsingValueSet.

private CodeValidationResult validateCodeUsingValueSet(String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
    CodeValidationResult result = null;
    if (theValueSetUrl == null || theValueSetUrl.isEmpty()) {
        result = new CodeValidationResult();
        result.setCode(theCode);
        result.setDisplay(theDisplay);
        result.setMessage("No ValueSet!");
        result.setSeverity(IssueSeverity.FATAL);
    } else {
        ValueSet vs = (ValueSet) this.fetchValueSet(theValueSetUrl);
        if (vs.hasCompose()) {
            ValueSetComposeComponent vscc = vs.getCompose();
            if (vscc.hasInclude()) {
                for (ConceptSetComponent csc : vscc.getInclude()) {
                    if ((theCodeSystem == null || (theCodeSystem != null && theCodeSystem.equals(csc.getSystem())))) {
                        for (ConceptReferenceComponent crc : csc.getConcept()) {
                            if (crc.hasCode() && crc.getCode().equals(theCode)) {
                                result = new CodeValidationResult();
                                result.setCode(theCode);
                                result.setDisplay(theDisplay);
                                result.setMessage("Included");
                                result.setSeverity(IssueSeverity.INFORMATION);
                            }
                        }
                    }
                }
            }
            if (result == null && vscc.hasExclude()) {
                for (ConceptSetComponent csc : vscc.getExclude()) {
                    if ((theCodeSystem == null || (theCodeSystem != null && theCodeSystem.equals(csc.getSystem())))) {
                        for (ConceptReferenceComponent crc : csc.getConcept()) {
                            if (crc.hasCode() && crc.getCode().equals(theCode)) {
                                result = new CodeValidationResult();
                                result.setCode(theCode);
                                result.setDisplay(theDisplay);
                                result.setMessage("Excluded");
                                result.setSeverity(IssueSeverity.ERROR);
                            }
                        }
                    }
                }
            }
        }
        if (result == null && vs.hasExpansion()) {
            ValueSetExpansionComponent vsec = vs.getExpansion();
            if (vsec.hasContains()) {
                for (ValueSetExpansionContainsComponent vsecc : vsec.getContains()) {
                    if (theCodeSystem == null || (theCodeSystem != null && theCodeSystem.equals(vsecc.getSystem()))) {
                        if (vsecc.getCode().equals(theCode)) {
                            result = new CodeValidationResult();
                            result.setCode(theCode);
                            result.setDisplay(theDisplay);
                            result.setMessage("Included");
                            result.setSeverity(IssueSeverity.INFORMATION);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r4.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 55 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project pathling by aehrc.

the class DefaultTerminologyServiceTest method fromSimpleCoding.

ValueSetExpansionContainsComponent fromSimpleCoding(@Nonnull final SimpleCoding simpleCoding) {
    final ValueSetExpansionContainsComponent result = new ValueSetExpansionContainsComponent();
    result.setSystem(simpleCoding.getSystem());
    result.setCode(simpleCoding.getCode());
    result.setVersion(simpleCoding.getVersion());
    return result;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent)

Aggregations

ValueSetExpansionContainsComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent)32 ValueSetExpansionContainsComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent)22 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 ValueSetExpansionContainsComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent)17 ValueSet (org.hl7.fhir.r4.model.ValueSet)9 HashMap (java.util.HashMap)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 ArrayList (java.util.ArrayList)7 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent)7 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent)7 IOException (java.io.IOException)6 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent)6 ValueSetExpansionComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 ValueSet (org.hl7.fhir.dstu2016may.model.ValueSet)4 ValueSet (org.hl7.fhir.r4b.model.ValueSet)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)3