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);
}
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);
}
}
}
}
}
}
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;
}
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;
}
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;
}
Aggregations