use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method checkPrimitiveBinding.
private void checkPrimitiveBinding(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, String type, ElementDefinition elementContext, Element element, StructureDefinition profile, NodeStack stack) {
// We ignore bindings that aren't on string, uri or code
if (!element.hasPrimitiveValue() || !("code".equals(type) || "string".equals(type) || "uri".equals(type) || "url".equals(type) || "canonical".equals(type))) {
return;
}
if (noTerminologyChecks)
return;
String value = element.primitiveValue();
// System.out.println("check "+value+" in "+path);
// firstly, resolve the value set
ElementDefinitionBindingComponent binding = elementContext.getBinding();
if (binding.hasValueSet()) {
ValueSet vs = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl());
if (vs == null) {
CodeSystem cs = context.fetchCodeSystem(binding.getValueSet());
if (rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, cs == null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND_CS, describeReference(binding.getValueSet()))) {
warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, vs != null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND, describeReference(binding.getValueSet()));
}
} else {
CodedContentValidationPolicy validationPolicy = getPolicyAdvisor() == null ? CodedContentValidationPolicy.VALUESET : getPolicyAdvisor().policyForCodedContent(this, hostContext, stack.getLiteralPath(), elementContext, profile, BindingKind.PRIMARY, vs, new ArrayList<>());
if (validationPolicy != CodedContentValidationPolicy.IGNORE) {
long t = System.nanoTime();
ValidationResult vr = null;
if (binding.getStrength() != BindingStrength.EXAMPLE) {
ValidationOptions options = baseOptions.setLanguage(stack.getWorkingLang()).guessSystem();
if (validationPolicy == CodedContentValidationPolicy.CODE) {
options = options.noCheckValueSetMembership();
}
vr = checkCodeOnServer(stack, vs, value, options);
}
timeTracker.tx(t, "vc " + value + "");
if (binding.getStrength() == BindingStrength.REQUIRED) {
removeTrackedMessagesForLocation(errors, element, path);
}
if (vr != null && !vr.isOk()) {
if (vr.IsNoService())
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_15, value);
else if (binding.getStrength() == BindingStrength.REQUIRED)
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_16, value, describeValueSet(binding.getValueSet()), getErrorMessage(vr.getMessage()));
else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), value, stack);
else if (!noExtensibleWarnings && !isOkExtension(value, vs))
txWarningForLaterRemoval(element, errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_17, value, describeValueSet(binding.getValueSet()), getErrorMessage(vr.getMessage()));
} else if (binding.getStrength() == BindingStrength.PREFERRED) {
if (baseOnly) {
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_18, value, describeValueSet(binding.getValueSet()), getErrorMessage(vr.getMessage()));
}
}
}
}
}
} else if (!noBindingMsgSuppressed)
hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, !type.equals("code"), I18nConstants.TERMINOLOGY_TX_BINDING_NOSOURCE2);
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method verifyCodeInCodeSystem.
private ValidationResult verifyCodeInCodeSystem(ValueSet vs, String system, String code, String display) {
ConceptDefinitionComponent cc = findCodeInConcept(vs.getCodeSystem().getConcept(), code);
if (cc == null)
return new ValidationResult(IssueSeverity.ERROR, "Unknown Code " + code + " in " + vs.getCodeSystem().getSystem());
if (display == null)
return new ValidationResult(cc);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (cc.hasDisplay()) {
b.append(cc.getDisplay());
if (display.equalsIgnoreCase(cc.getDisplay()))
return new ValidationResult(cc);
}
for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
b.append(ds.getValue());
if (display.equalsIgnoreCase(ds.getValue()))
return new ValidationResult(cc);
}
return new ValidationResult(IssueSeverity.ERROR, "Display Name for " + code + " must be one of '" + b.toString() + "'");
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method serverValidateCode.
private ValidationResult serverValidateCode(Parameters pin) {
Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
boolean ok = false;
String message = "No Message returned";
String display = null;
for (ParametersParameterComponent p : pout.getParameter()) {
if (p.getName().equals("result"))
ok = ((BooleanType) p.getValue()).getValue().booleanValue();
else if (p.getName().equals("message"))
message = ((StringType) p.getValue()).getValue();
else if (p.getName().equals("display"))
display = ((StringType) p.getValue()).getValue();
}
if (!ok)
return new ValidationResult(IssueSeverity.ERROR, message);
else if (display != null)
return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
else
return new ValidationResult(null);
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method handleByCache.
private ValidationResult handleByCache(ValueSet vs, Coding coding, boolean tryCache) {
String cacheId = cacheId(coding);
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
if (cache == null) {
cache = new HashMap<String, IWorkerContext.ValidationResult>();
validationCache.put(vs.getUrl(), cache);
}
if (cache.containsKey(cacheId))
return cache.get(cacheId);
if (!tryCache)
return null;
if (!cacheValidation)
return null;
if (failed.contains(vs.getUrl()))
return null;
ValueSetExpansionOutcome vse = expandVS(vs, true);
if (vse.getValueset() == null || notcomplete(vse.getValueset())) {
failed.add(vs.getUrl());
return null;
}
ValidationResult res = validateCode(coding, vse.getValueset());
cache.put(cacheId, res);
return res;
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method processValidationResult.
public ValidationResult processValidationResult(Parameters pOut) {
boolean ok = false;
String message = "No Message returned";
String display = null;
String system = null;
String code = null;
TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
for (ParametersParameterComponent p : pOut.getParameter()) {
if (p.hasValue()) {
if (p.getName().equals("result")) {
ok = ((BooleanType) p.getValue()).getValue().booleanValue();
} else if (p.getName().equals("message")) {
message = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("display")) {
display = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("system")) {
system = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("code")) {
code = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("cause")) {
try {
IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
if (it == IssueType.UNKNOWN) {
err = TerminologyServiceErrorClass.UNKNOWN;
} else if (it == IssueType.NOTFOUND) {
err = TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED;
} else if (it == IssueType.NOTSUPPORTED) {
err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
} else {
err = null;
}
} catch (FHIRException e) {
}
}
}
}
if (!ok) {
return new ValidationResult(IssueSeverity.ERROR, message + " (from " + txClient.getAddress() + ")", err).setTxLink(txLog.getLastId());
} else if (message != null && !message.equals("No Message returned")) {
return new ValidationResult(IssueSeverity.WARNING, message + " (from " + txClient.getAddress() + ")", system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
} else if (display != null) {
return new ValidationResult(system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
} else {
return new ValidationResult(system, new ConceptDefinitionComponent().setCode(code)).setTxLink(txLog.getLastId());
}
}
Aggregations