protected void codedTriple( Section section, String subject, String predicate, CodeableConcept cc) { for (Coding c : cc.getCoding()) { String s = getLinkedForm(c); if (s != null) section.triple(subject, predicate, s, c.hasDisplay() ? c.getDisplay() : cc.getText()); } }
protected void codedTriple(Subject subject, String predicate, CodeableConcept cc) { for (Coding c : cc.getCoding()) { String s = getLinkedForm(c); if (s != null) subject.predicate( predicate, new StringType(s), c.hasDisplay() ? c.getDisplay() : cc.getText()); } }
private ValidationResult verifyCodeInternal(ValueSet vs, CodeableConcept code) throws Exception { for (Coding c : code.getCoding()) { ValidationResult res = verifyCodeInternal(vs, c.getSystem(), c.getCode(), c.getDisplay()); if (res.isOk()) return res; } if (code.getCoding().isEmpty()) return new ValidationResult(IssueSeverity.ERROR, "None code provided"); else return new ValidationResult( IssueSeverity.ERROR, "None of the codes are in the specified value set"); }
private String cacheId(CodeableConcept cc) { StringBuilder b = new StringBuilder(); for (Coding c : cc.getCoding()) { b.append("#"); b.append(cacheId(c)); } return b.toString(); }
private ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCodeIsInContains( List<ValueSetExpansionContainsComponent> contains, String theSystem, String theCode, Coding theCoding, CodeableConcept theCodeableConcept) { for (ValueSetExpansionContainsComponent nextCode : contains) { ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult result = validateCodeIsInContains( nextCode.getContains(), theSystem, theCode, theCoding, theCodeableConcept); if (result != null) { return result; } String system = nextCode.getSystem(); String code = nextCode.getCode(); if (isNotBlank(theCode)) { if (theCode.equals(code) && (isBlank(theSystem) || theSystem.equals(system))) { return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay()); } } else if (theCoding != null) { if (StringUtils.equals(system, theCoding.getSystem()) && StringUtils.equals(code, theCoding.getCode())) { return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay()); } } else { for (Coding next : theCodeableConcept.getCoding()) { if (StringUtils.equals(system, next.getSystem()) && StringUtils.equals(code, next.getCode())) { return new ValidateCodeResult(true, "Validation succeeded", nextCode.getDisplay()); } } } } return null; }
@Override public ValidationResult validateCode(CodeableConcept code, ValueSet vs) { try { if (vs.hasExpansion()) return verifyCodeInternal(vs, code); else { // we'll try expanding first; if that doesn't work, then we'll just pass it to the server to // validate // ... could be a problem if the server doesn't have the code systems we have locally, so we // try not to depend on the server try { ValueSetExpansionOutcome vse = expandVS(vs, true, false); if (vse.getValueset() != null) return verifyCodeInternal(vse.getValueset(), code); } catch (Exception e) { // failed? we'll just try the server } return verifyCodeExternal(vs, code, true); } } catch (Exception e) { return new ValidationResult( IssueSeverity.FATAL, "Error validating code \"" + code.toString() + "\": " + e.getMessage(), TerminologyServiceErrorClass.SERVER_ERROR); } }
@Override public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode( IPrimitiveType<String> theValueSetIdentifier, IIdType theId, IPrimitiveType<String> theCode, IPrimitiveType<String> theSystem, IPrimitiveType<String> theDisplay, Coding theCoding, CodeableConcept theCodeableConcept, RequestDetails theRequestDetails) { List<IIdType> valueSetIds = Collections.emptyList(); boolean haveCodeableConcept = theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0; boolean haveCoding = theCoding != null && theCoding.isEmpty() == false; boolean haveCode = theCode != null && theCode.isEmpty() == false; if (!haveCodeableConcept && !haveCoding && !haveCode) { throw new InvalidRequestException("No code, coding, or codeableConcept provided to validate"); } if (!LogicUtil.multiXor(haveCodeableConcept, haveCoding, haveCode)) { throw new InvalidRequestException( "$validate-code can only validate (system AND code) OR (coding) OR (codeableConcept)"); } boolean haveIdentifierParam = theValueSetIdentifier != null && theValueSetIdentifier.isEmpty() == false; if (theId != null) { valueSetIds = Collections.singletonList(theId); } else if (haveIdentifierParam) { Set<Long> ids = searchForIds( ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue())); valueSetIds = new ArrayList<IIdType>(); for (Long next : ids) { valueSetIds.add(new IdType("ValueSet", next)); } } else { if (theCode == null || theCode.isEmpty()) { throw new InvalidRequestException( "Either ValueSet ID or ValueSet identifier or system and code must be provided. Unable to validate."); } // String code = theCode.getValue(); // String system = toStringOrNull(theSystem); LookupCodeResult result = myCodeSystemDao.lookupCode(theCode, theSystem, null, null); if (result.isFound()) { ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult retVal = new ValidateCodeResult(true, "Found code", result.getCodeDisplay()); return retVal; } } // if (valueSetIds.isEmpty()) { // if (haveIdentifierParam) { // myValidationSupport.expandValueSet(getContext(), include); // if (myValidationSupport.isCodeSystemSupported(getContext(), // theValueSetIdentifier.getValue())) { // String system = toStringOrNull(theSystem); // String code = toStringOrNull(theCode); // String display = toStringOrNull(theDisplay); // CodeValidationResult result = myValidationSupport.validateCode(getContext(), system, // code, display); // if (result != null) { // if (theDisplay != null && isNotBlank(theDisplay.getValue()) && // isNotBlank(result.getDisplay())) { // if (!theDisplay.getValue().equals(result.getDisplay())) { // return new ValidateCodeResult(false, "Display for code does not match", // result.getDisplay()); // } // } // return new ValidateCodeResult(true, "Code validates", result.getDisplay()); // } // } // } // } for (IIdType nextId : valueSetIds) { ValueSet expansion = expand(nextId, null, theRequestDetails); List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains(); ValidateCodeResult result = validateCodeIsInContains( contains, toStringOrNull(theSystem), toStringOrNull(theCode), theCoding, theCodeableConcept); if (result != null) { if (theDisplay != null && isNotBlank(theDisplay.getValue()) && isNotBlank(result.getDisplay())) { if (!theDisplay.getValue().equals(result.getDisplay())) { return new ValidateCodeResult( false, "Display for code does not match", result.getDisplay()); } } return result; } } return new ValidateCodeResult(false, "Code not found", null); }