@Override public List<StructureDefinition> fetchAllStructureDefinitions(FhirContext theContext) { ArrayList<StructureDefinition> retVal = new ArrayList<StructureDefinition>(); Set<String> urls = new HashSet<String>(); for (IValidationSupport nextSupport : myChain) { for (StructureDefinition next : nextSupport.fetchAllStructureDefinitions(theContext)) { if (isBlank(next.getUrl()) || urls.add(next.getUrl())) { retVal.add(next); } } } return retVal; }
/** * Add a new StructureDefinition resource which will be available to the validator. Note that * {@link StructureDefinition#getUrl() the URL field) in this resource must contain a value as this * value will be used as the logical URL. * <p> * Note that if the URL is a canonical FHIR URL (e.g. http://hl7.org/StructureDefinition/Extension), * it will be stored in three ways: * <ul> * <li>Extension</li> * <li>StructureDefinition/Extension</li> * <li>http://hl7.org/StructureDefinition/Extension</li> * </ul> * </p> */ public void addStructureDefinition(StructureDefinition theStructureDefinition) { Validate.notBlank(theStructureDefinition.getUrl(), "theStructureDefinition.getUrl() must not return a value"); addToMap(theStructureDefinition, myStructureDefinitions, theStructureDefinition.getUrl()); }
public void checkProfile(StructureDefinition profile) { ProfileUsage profileUsage = profiles.get(profile); if (profileUsage==null) throw new Error("Can't check profile that hasn't been added: " + profile.getUrl()); else profileUsage.setChecked(); } }
if (theClass.isAssignableFrom(next.getValue().getClass())) { StructureDefinition sd = ((StructureDefinition) next.getValue()); if (sd.getUrl().equals(theUri)) { return (T) sd;
private void loadStructureDefinitions(FhirContext theContext, Map<String, StructureDefinition> theCodeSystems, String theClasspath) { ourLog.info("Loading structure definitions from classpath: {}", theClasspath); InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath); if (valuesetText != null) { InputStreamReader reader = new InputStreamReader(valuesetText, Charsets.UTF_8); Bundle bundle = theContext.newXmlParser().parseResource(Bundle.class, reader); for (BundleEntryComponent next : bundle.getEntry()) { if (next.getResource() instanceof StructureDefinition) { StructureDefinition nextSd = (StructureDefinition) next.getResource(); nextSd.getText().setDivAsString(""); String system = nextSd.getUrl(); if (isNotBlank(system)) { theCodeSystems.put(system, nextSd); } } } } else { ourLog.warn("Unable to load resource: {}", theClasspath); } }
private void checkExtensions(StructureDefinition profile, List<ValidationMessage> errors, String kind, ElementDefinition ec) { if (!ec.getType().isEmpty() && "Extension".equals(ec.getType().get(0).getCode()) && ec.getType().get(0).hasProfile()) { String url = ec.getType().get(0).getProfile(); StructureDefinition defn = context.fetchResource(StructureDefinition.class, url); rule(errors, IssueType.BUSINESSRULE, profile.getId(), defn != null, "Unable to find Extension '"+url+"' referenced at "+profile.getUrl()+" "+kind+" "+ec.getPath()+" ("+ec.getSliceName()+")"); } }
public boolean addProfile(List<ValidationMessage> errors, String profile, boolean error, String path, Element element) { String effectiveProfile = profile; String version = null; if (profile.contains("|")) { effectiveProfile = profile.substring(0, profile.indexOf('|')); version = profile.substring(profile.indexOf('|')+1); } StructureDefinition sd = context.fetchResource(StructureDefinition.class, effectiveProfile); if (warningOrError(error, errors, IssueType.INVALID, element.line(), element.col(), path, sd != null, "StructureDefinition reference \"{0}\" could not be resolved", profile)) { if (rule(errors, IssueType.STRUCTURE, element.line(), element.col(), path, version==null || (sd.getVersion()!=null && sd.getVersion().equals(version)), "Referenced version " + version + " does not match found version " + sd.getVersion() + " for profile " + sd.getUrl(), profile)) { if (rule(errors, IssueType.STRUCTURE, element.line(), element.col(), path, sd.hasSnapshot(), "StructureDefinition has no snapshot - validation is against the snapshot, so it must be provided")) { if (!profiles.containsKey(sd)) { profiles.put(sd, new ProfileUsage(sd)); addAncestorProfiles(sd); return true; } } } } return false; }
private void checkMaxValueSet(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, Reference maxVSUrl, CodeableConcept cc) { // TODO Auto-generated method stub ValueSet valueset = resolveBindingReference(profile, maxVSUrl, profile.getUrl()); if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, "ValueSet " + describeReference(maxVSUrl) + " not found")) { try { long t = System.nanoTime(); ValidationResult vr = context.validateCode(cc, valueset); txTime = txTime + (System.nanoTime() - t); if (!vr.isOk()) { rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "None of the codes provided are in the maximum value set " + describeReference(maxVSUrl) + " (" + valueset.getUrl()+", and a code from this value set is required) (codes = "+ccSummary(cc)+")"); } } catch (Exception e) { warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "Error "+e.getMessage()+" validating CodeableConcept using maxValueSet"); } } }
private void checkMaxValueSet(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, Reference maxVSUrl, Coding c) { // TODO Auto-generated method stub ValueSet valueset = resolveBindingReference(profile, maxVSUrl, profile.getUrl()); if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, "ValueSet " + describeReference(maxVSUrl) + " not found")) { try { long t = System.nanoTime(); ValidationResult vr = context.validateCode(c, valueset); txTime = txTime + (System.nanoTime() - t); if (!vr.isOk()) { rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "The code provided is not in the maximum value set " + describeReference(maxVSUrl) + " (" + valueset.getUrl()+", and a code from this value set is required) (code = "+c.getSystem()+"#"+c.getCode()+")"); } } catch (Exception e) { warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "Error "+e.getMessage()+" validating CodeableConcept using maxValueSet"); } } }
n = fpe.parse(expression); } catch (FHIRLexerException e) { throw new FHIRException("Problem processing expression "+expression +" in profile " + profile.getUrl() + " path " + path + ": " + e.getMessage()); msg = fpe.forLog(); } catch (Exception ex) { throw new FHIRException("Problem evaluating slicing expression for element in profile " + profile.getUrl() + " path " + path + ": " + ex.getMessage());
private boolean checkExtensionContext(List<ValidationMessage> errors, Element element, StructureDefinition definition, NodeStack stack, String extensionParent) { String extUrl = definition.getUrl(); CommaSeparatedStringBuilder p = new CommaSeparatedStringBuilder(); for (String lp : stack.getLogicalPaths())
n = fpe.parse(inv.getExpression()); } catch (FHIRLexerException e) { throw new FHIRException("Problem processing expression "+inv.getExpression() +" in profile " + profile.getUrl() + " path " + path + ": " + e.getMessage()); ok = fpe.evaluateToBoolean(resource, element, n); } catch (PathEngineException e) { throw new FHIRException("Problem processing expression "+inv.getExpression() +" in profile " + profile.getUrl() + " path " + path + ": " + e.getMessage());
checkExtensionContext(errors, element, /* path+"[url='"+url+"']", */ ex, stack, ex.getUrl());
private void checkMaxValueSet(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, Reference maxVSUrl, String value) { // TODO Auto-generated method stub ValueSet valueset = resolveBindingReference(profile, maxVSUrl, profile.getUrl()); if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, "ValueSet " + describeReference(maxVSUrl) + " not found")) { try { long t = System.nanoTime(); ValidationResult vr = context.validateCode(null, value, null, valueset); txTime = txTime + (System.nanoTime() - t); if (!vr.isOk()) { if (vr.getErrorClass() != null && vr.getErrorClass().isInfrastructure()) warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "The code provided could not be validated against the maximum value set " + describeReference(maxVSUrl) + " (" + valueset.getUrl()+"), (error = "+vr.getMessage()+")"); else rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "The code provided is not in the maximum value set " + describeReference(maxVSUrl) + " (" + valueset.getUrl()+"), and a code from this value set is required) (code = "+value+"), (error = "+vr.getMessage()+")"); } } catch (Exception e) { warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "Error "+e.getMessage()+" validating CodeableConcept using maxValueSet"); } } }
ValueSet vs = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl()); if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, vs != null, "ValueSet {0} not found", describeReference(binding.getValueSet()))) { long t = System.nanoTime();
if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, binding != null, "Binding for " + path + " missing (cc)")) { if (binding.hasValueSet() && binding.getValueSet() instanceof Reference) { ValueSet valueset = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl()); if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, "ValueSet " + describeReference(binding.getValueSet()) + " not found")) { try {
if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, binding != null, "Binding for " + path + " missing")) { if (binding.hasValueSet() && binding.getValueSet() instanceof Reference) { ValueSet valueset = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl()); if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, "ValueSet " + describeReference(binding.getValueSet()) + " not found")) { try {
org.hl7.fhir.instance.model.StructureDefinition tgt = new org.hl7.fhir.instance.model.StructureDefinition(); copyDomainResource(src, tgt); tgt.setUrl(src.getUrl()); for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
copyDomainResource(src, tgt); if (src.hasUrl()) tgt.setUrl(src.getUrl()); for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));