use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opMemberOf.
private List<Base> opMemberOf(ExecutionContext context, List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
boolean ans = false;
String url = right.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) : worker.fetchResource(ValueSet.class, url);
if (vs != null) {
for (Base l : left) {
if (Utilities.existsInList(l.fhirType(), "code", "string", "uri")) {
if (worker.validateCode(terminologyServiceOptions.guessSystem(), TypeConvertor.castToCoding(l), vs).isOk()) {
ans = true;
}
} else if (l.fhirType().equals("Coding")) {
if (worker.validateCode(terminologyServiceOptions, TypeConvertor.castToCoding(l), vs).isOk()) {
ans = true;
}
} else if (l.fhirType().equals("CodeableConcept")) {
CodeableConcept cc = TypeConvertor.castToCodeableConcept(l);
ValidationResult vr = worker.validateCode(terminologyServiceOptions, cc, vs);
// System.out.println("~~~ "+DataRenderer.display(worker, cc)+ " memberOf "+url+": "+vr.toString());
if (vr.isOk()) {
ans = true;
}
} else {
// System.out.println("unknown type in opMemberOf: "+l.fhirType());
}
}
}
return makeBoolean(ans);
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult 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.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method inComponent.
private Boolean inComponent(ConceptSetComponent vsi, int vsiIndex, String system, String code, boolean only, List<String> warnings) throws FHIRException {
if (isValueSetUnionImports()) {
for (UriType uri : vsi.getValueSet()) {
if (inImport(uri.getValue(), system, code)) {
return true;
}
}
} else {
for (UriType uri : vsi.getValueSet()) {
if (!inImport(uri.getValue(), system, code)) {
return false;
}
}
}
if (!vsi.hasSystem()) {
return false;
}
if (only && system == null) {
// whether we know the system or not, we'll accept the stated codes at face value
for (ConceptReferenceComponent cc : vsi.getConcept()) {
if (cc.getCode().equals(code)) {
return true;
}
}
}
if (!system.equals(vsi.getSystem()))
return false;
// ok, we need the code system
CodeSystem cs = resolveCodeSystem(system);
if (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT)) {
// make up a transient value set with
ValueSet vs = new ValueSet();
vs.setStatus(PublicationStatus.ACTIVE);
vs.setUrl(valueset.getUrl() + "--" + vsiIndex);
vs.setVersion(valueset.getVersion());
vs.getCompose().addInclude(vsi);
ValidationResult res = context.validateCode(options.noClient(), new Coding(system, code, null), vs);
if (res.getErrorClass() == TerminologyServiceErrorClass.UNKNOWN || res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED || res.getErrorClass() == TerminologyServiceErrorClass.VALUESET_UNSUPPORTED) {
if (warnings != null && res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
warnings.add(context.formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, system));
}
return null;
}
if (res.getErrorClass() == TerminologyServiceErrorClass.NOSERVICE) {
throw new NoTerminologyServiceException();
}
return res.isOk();
} else {
if (vsi.hasFilter()) {
boolean ok = true;
for (ConceptSetFilterComponent f : vsi.getFilter()) {
if (!codeInFilter(cs, system, f, code)) {
ok = false;
break;
}
}
return ok;
}
List<ConceptDefinitionComponent> list = cs.getConcept();
boolean ok = validateCodeInConceptList(code, cs, list);
if (ok && vsi.hasConcept()) {
for (ConceptReferenceComponent cc : vsi.getConcept()) {
if (cc.getCode().equals(code)) {
return true;
}
}
return false;
} else {
return ok;
}
}
}
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 verifyCodeExternal.
private ValidationResult verifyCodeExternal(ValueSet vs, CodeableConcept cc, boolean tryCache) {
ValidationResult res = handleByCache(vs, cc, tryCache);
if (res != null)
return res;
Parameters pin = new Parameters();
pin.addParameter().setName("codeableConcept").setValue(cc);
pin.addParameter().setName("valueSet").setResource(vs);
res = serverValidateCode(pin);
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
cache.put(cacheId(cc), res);
return res;
}
Aggregations