use of org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method codeInConceptIsAFilter.
private boolean codeInConceptIsAFilter(CodeSystem cs, ConceptSetFilterComponent f, String code, boolean rootOnly) {
if (!rootOnly && code.equals(f.getProperty())) {
return true;
}
ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), f.getValue());
if (cc == null) {
return false;
}
cc = findCodeInConcept(cc, code);
return cc != null;
}
use of org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method findCodeInExpansion.
private ValidationResult findCodeInExpansion(Coding code, List<ValueSetExpansionContainsComponent> contains) {
for (ValueSetExpansionContainsComponent containsComponent : contains) {
if (containsComponent.getSystem().equals(code.getSystem()) && containsComponent.getCode().equals(code.getCode())) {
ConceptDefinitionComponent ccd = new ConceptDefinitionComponent();
ccd.setCode(containsComponent.getCode());
ccd.setDisplay(containsComponent.getDisplay());
ValidationResult res = new ValidationResult(code.getSystem(), ccd);
return res;
}
if (containsComponent.hasContains()) {
ValidationResult res = findCodeInExpansion(code, containsComponent.getContains());
if (res != null) {
return res;
}
}
}
return null;
}
use of org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method validateCode.
public ValidationResult validateCode(Coding code) throws FHIRException {
String warningMessage = null;
// first, we validate the concept itself
ValidationResult res = null;
boolean inExpansion = false;
boolean inInclude = false;
String system = code.hasSystem() ? code.getSystem() : getValueSetSystemOrNull();
if (options.getValueSetMode() != ValueSetMode.CHECK_MEMERSHIP_ONLY) {
if (system == null && !code.hasDisplay()) {
// dealing with just a plain code (enum)
system = systemForCodeInValueSet(code.getCode());
}
if (!code.hasSystem()) {
if (options.isGuessSystem() && system == null && Utilities.isAbsoluteUrl(code.getCode())) {
// this arises when using URIs bound to value sets
system = "urn:ietf:rfc:3986";
}
code.setSystem(system);
}
inExpansion = checkExpansion(code);
inInclude = checkInclude(code);
CodeSystem cs = resolveCodeSystem(system);
if (cs == null) {
warningMessage = "Unable to resolve system " + system;
if (!inExpansion) {
if (valueset != null && valueset.hasExpansion()) {
return new ValidationResult(IssueSeverity.ERROR, context.formatMessage(I18nConstants.CODESYSTEM_CS_UNK_EXPANSION, valueset.getUrl(), code.getCode().toString(), code.getSystem()));
} else {
throw new FHIRException(warningMessage);
}
}
}
if (cs != null && cs.hasSupplements()) {
return new ValidationResult(IssueSeverity.ERROR, context.formatMessage(I18nConstants.CODESYSTEM_CS_NO_SUPPLEMENT, cs.getUrl()));
}
if (cs != null && cs.getContent() != CodeSystemContentMode.COMPLETE) {
warningMessage = "Resolved system " + system + ", but the definition is not complete";
if (!inExpansion && cs.getContent() != CodeSystemContentMode.FRAGMENT) {
// we're going to give it a go if it's a fragment
throw new FHIRException(warningMessage);
}
}
if (cs != null) /*&& (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)*/
{
if (!(cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) {
// we can't validate that here.
throw new FHIRException("Unable to evaluate based on empty code system");
}
res = validateCode(code, cs);
} else if (cs == null && valueset.hasExpansion() && inExpansion) {
// we just take the value set as face value then
res = new ValidationResult(system, new ConceptDefinitionComponent().setCode(code.getCode()).setDisplay(code.getDisplay()));
} else {
// disabled waiting for discussion
throw new FHIRException("No try the server");
}
} else {
inExpansion = checkExpansion(code);
inInclude = checkInclude(code);
}
List<String> warnings = new ArrayList<>();
// then, if we have a value set, we check it's in the value set
if (valueset != null && options.getValueSetMode() != ValueSetMode.NO_MEMBERSHIP_CHECK) {
if ((res == null || res.isOk())) {
Boolean ok = codeInValueSet(system, code.getCode(), warnings);
if (ok == null || !ok) {
if (res == null) {
res = new ValidationResult((IssueSeverity) null, null);
}
if (!inExpansion && !inInclude) {
res.setMessage("Not in value set " + valueset.getUrl()).setSeverity(IssueSeverity.ERROR);
} else if (warningMessage != null) {
res = new ValidationResult(IssueSeverity.WARNING, context.formatMessage(I18nConstants.CODE_FOUND_IN_EXPANSION_HOWEVER_, warningMessage));
} else if (inExpansion) {
res.setMessage("Code found in expansion, however: " + res.getMessage());
} else if (inInclude) {
res.setMessage("Code found in include, however: " + res.getMessage());
}
}
}
}
return res;
}
use of org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method addCodeAndDescendents.
private void addCodeAndDescendents(CodeSystem cs, String system, ConceptDefinitionComponent def, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, ConceptDefinitionComponent exclusion, IConceptFilter filterFunc) throws FHIRException {
def.checkNoModifiers("Code in Code System", "expanding");
if (exclusion != null) {
if (exclusion.getCode().equals(def.getCode()))
// excluded.
return;
}
if (!CodeSystemUtilities.isDeprecated(cs, def, false)) {
ValueSetExpansionContainsComponent np = null;
boolean abs = CodeSystemUtilities.isNotSelectable(cs, def);
boolean inc = CodeSystemUtilities.isInactive(cs, def);
if ((includeAbstract || !abs) && filterFunc.includeConcept(cs, def)) {
np = addCode(system, def.getCode(), def.getDisplay(), parent, def.getDesignation(), expParams, abs, inc, filters);
}
for (ConceptDefinitionComponent c : def.getConcept()) {
addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc);
}
if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
for (ConceptDefinitionComponent c : children) addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc);
}
} else {
for (ConceptDefinitionComponent c : def.getConcept()) {
addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion, filterFunc);
}
if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
for (ConceptDefinitionComponent c : children) addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion, filterFunc);
}
}
}
use of org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method getConceptForCodeFromExpansion.
private ConceptDefinitionComponent getConceptForCodeFromExpansion(List<ValueSetExpansionContainsComponent> list, String code) {
for (ValueSetExpansionContainsComponent c : list) {
if (code.equals(c.getCode())) {
ConceptDefinitionComponent res = new ConceptDefinitionComponent();
res.setCode(c.getCode());
res.setDisplay(c.getDisplay());
return res;
}
ConceptDefinitionComponent v = getConceptForCodeFromExpansion(c.getContains(), code);
if (v != null)
return v;
}
return null;
}
Aggregations