use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent 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);
}
}
}
}
}
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent 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;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent 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;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method importValueSet.
private ValueSet importValueSet(String value, ValueSetExpansionComponent exp, Parameters expParams, boolean noInactive, ValueSet valueSet) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException, FHIRFormatError {
if (value == null)
throw fail("unable to find value set with no identity");
ValueSet vs = context.fetchResource(ValueSet.class, value);
if (vs == null) {
if (context.fetchResource(CodeSystem.class, value) != null) {
throw fail("Cannot include value set " + value + " because it's actually a code system");
} else {
throw fail("Unable to find imported value set " + value);
}
}
if (noInactive) {
expParams = expParams.copy();
expParams.addParameter("activeOnly", true);
}
ValueSetExpansionOutcome vso = new ValueSetExpanderSimple(context, allErrors).expand(vs, expParams);
if (vso.getError() != null) {
addErrors(vso.getAllErrors());
throw fail("Unable to expand imported value set " + vs.getUrl() + ": " + vso.getError());
}
if (vs.hasVersion())
if (!existsInParams(exp.getParameter(), "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
exp.getParameter().add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
for (Extension ex : vso.getValueset().getExpansion().getExtension()) {
if (ex.getUrl().equals(ToolingExtensions.EXT_EXP_TOOCOSTLY)) {
if (ex.getValue() instanceof BooleanType) {
exp.getExtension().add(new Extension(ToolingExtensions.EXT_EXP_TOOCOSTLY).setValue(new UriType(value)));
} else {
exp.getExtension().add(ex);
}
}
}
for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
if (!existsInParams(exp.getParameter(), p.getName(), p.getValue()))
exp.getParameter().add(p);
}
if (isValueSetUnionImports(valueSet)) {
copyExpansion(vso.getValueset().getExpansion().getContains());
}
// if we're importing a value set, we have to be combining, so we won't try for a heirarchy
canBeHeirarchy = false;
return vso.getValueset();
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method doServerIncludeCodes.
private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, ValueSetExpansionComponent exp, List<ValueSet> imports, Parameters expParams, List<Extension> extensions, boolean noInactive) throws FHIRException {
ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical, noInactive);
if (vso.getError() != null) {
throw failTSE("Unable to expand imported value set: " + vso.getError());
}
ValueSet vs = vso.getValueset();
if (vs.hasVersion()) {
if (!existsInParams(exp.getParameter(), "version", new UriType(vs.getUrl() + "|" + vs.getVersion()))) {
exp.getParameter().add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
}
}
for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
if (!existsInParams(exp.getParameter(), p.getName(), p.getValue())) {
exp.getParameter().add(p);
}
}
for (Extension ex : vs.getExpansion().getExtension()) {
if (Utilities.existsInList(ex.getUrl(), ToolingExtensions.EXT_EXP_TOOCOSTLY, "http://hl7.org/fhir/StructureDefinition/valueset-unclosed")) {
if (!hasExtension(extensions, ex.getUrl())) {
extensions.add(ex);
}
}
}
for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
addCodeAndDescendents(cc, null, expParams, imports, noInactive);
}
}
Aggregations