All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.hl7.fhir.r4.validation.ProfileValidator Maven / Gradle / Ivy
package org.hl7.fhir.r4.validation;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.r4.context.IWorkerContext;
import org.hl7.fhir.r4.model.ElementDefinition;
import org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
public class ProfileValidator extends BaseValidator {
IWorkerContext context;
public void setContext(IWorkerContext context) {
this.context = context;
}
protected boolean rule(List errors, IssueType type, String path, boolean b, String msg) {
String rn = path.contains(".") ? path.substring(0, path.indexOf(".")) : path;
return super.rule(errors, type, path, b, msg, ""+rn+" : "+Utilities.escapeXml(msg));
}
public List validate(StructureDefinition profile, boolean forBuild) {
List errors = new ArrayList();
// first check: extensions must exist
for (ElementDefinition ec : profile.getDifferential().getElement())
checkExtensions(profile, errors, "differential", ec);
rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at "+profile.getName()+"."+profile.getName());
for (ElementDefinition ec : profile.getSnapshot().getElement())
checkExtensions(profile, errors, "snapshot", ec);
if (rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "A snapshot is required")) {
for (ElementDefinition ed : profile.getSnapshot().getElement()) {
checkExtensions(profile, errors, "snapshot", ed);
for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) {
if (forBuild) {
if (!inExemptList(inv.getKey())) {
if (rule(errors, IssueType.BUSINESSRULE, profile.getId()+"::"+ed.getPath()+"::"+inv.getKey(), inv.hasExpression(), "The invariant has no FHIR Path expression ("+inv.getXpath()+")")) {
try {
new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression()); // , inv.hasXpath() && inv.getXpath().startsWith("@value")
} catch (Exception e) {
// rule(errors, IssueType.STRUCTURE, profile.getId()+"::"+ed.getPath()+"::"+inv.getId(), exprExt != null, e.getMessage());
}
}
}
}
}
}
}
return errors;
}
// these are special cases
private boolean inExemptList(String key) {
return key.startsWith("txt-");
}
private void checkExtensions(StructureDefinition profile, List 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()+")");
}
}
}