use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method getChildMap.
public static List<ElementDefinition> getChildMap(StructureDefinition profile, ElementDefinition element) throws DefinitionException {
if (element.getContentReference() != null) {
for (ElementDefinition e : profile.getSnapshot().getElement()) {
if (element.getContentReference().equals("#" + e.getId()))
return getChildMap(profile, e);
}
throw new DefinitionException("Unable to resolve name reference " + element.getContentReference() + " at path " + element.getPath());
} else {
List<ElementDefinition> res = new ArrayList<ElementDefinition>();
List<ElementDefinition> elements = profile.getSnapshot().getElement();
String path = element.getPath();
for (int index = elements.indexOf(element) + 1; index < elements.size(); index++) {
ElementDefinition e = elements.get(index);
if (e.getPath().startsWith(path + ".")) {
// We only want direct children, not all descendants
if (!e.getPath().substring(path.length() + 1).contains("."))
res.add(e);
} else
break;
}
return res;
}
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateSchematrons.
// generate schematrons for the rules in a structure definition
public void generateSchematrons(OutputStream dest, StructureDefinition structure) throws IOException, DefinitionException {
if (structure.getDerivation() != TypeDerivationRule.CONSTRAINT)
throw new DefinitionException("not the right kind of structure to generate schematrons for");
if (!structure.hasSnapshot())
throw new DefinitionException("needs a snapshot");
StructureDefinition base = context.fetchResource(StructureDefinition.class, structure.getBaseDefinition());
SchematronWriter sch = new SchematronWriter(dest, SchematronType.PROFILE, base.getName());
ElementDefinition ed = structure.getSnapshot().getElement().get(0);
generateForChildren(sch, "f:" + ed.getPath(), ed, structure, base);
sch.dump();
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method seeProfile.
public void seeProfile(String url, StructureDefinition p) throws FHIRException {
if (Utilities.noString(url))
url = p.getUrl();
if (!p.hasSnapshot() && p.getKind() != StructureDefinitionKind.LOGICAL) {
if (!p.hasBaseDefinition())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") has no base and no snapshot");
StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
if (sd == null)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") base " + p.getBaseDefinition() + " could not be resolved");
List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
List<String> errors = new ArrayList<String>();
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.sortDifferential(sd, p, url, errors);
for (String err : errors) msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION, p.getUserString("path"), "Error sorting Differential: " + err, ValidationMessage.IssueSeverity.ERROR));
pu.generateSnapshot(sd, p, p.getUrl(), p.getName());
for (ValidationMessage msg : msgs) {
if (msg.getLevel() == ValidationMessage.IssueSeverity.ERROR || msg.getLevel() == ValidationMessage.IssueSeverity.FATAL)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot: " + msg.getMessage());
}
if (!p.hasSnapshot())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot");
pu = null;
}
if (structures.containsKey(p.getUrl()) && !allowLoadingDuplicates)
throw new DefinitionException("Duplicate structures " + p.getUrl());
structures.put(p.getId(), p);
structures.put(p.getUrl(), p);
if (!p.getUrl().equals(url))
structures.put(url, p);
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method seeValueSet.
public void seeValueSet(String url, ValueSet vs) throws DefinitionException {
if (Utilities.noString(url))
url = vs.getUrl();
if (valueSets.containsKey(vs.getUrl()) && !allowLoadingDuplicates)
throw new DefinitionException("Duplicate Profile " + vs.getUrl());
valueSets.put(vs.getId(), vs);
valueSets.put(vs.getUrl(), vs);
if (!vs.getUrl().equals(url))
valueSets.put(url, vs);
}
use of org.hl7.fhir.exceptions.DefinitionException in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method compareChildren.
private boolean compareChildren(ElementDefinition ed, ProfileComparison outcome, String path, DefinitionNavigator left, DefinitionNavigator right) throws DefinitionException, IOException, FHIRFormatError {
List<DefinitionNavigator> lc = left.children();
List<DefinitionNavigator> rc = right.children();
// walk into it
if (lc.isEmpty() && !rc.isEmpty() && right.current().getType().size() == 1 && left.hasTypeChildren(right.current().getType().get(0)))
lc = left.childrenFromType(right.current().getType().get(0));
if (rc.isEmpty() && !lc.isEmpty() && left.current().getType().size() == 1 && right.hasTypeChildren(left.current().getType().get(0)))
rc = right.childrenFromType(left.current().getType().get(0));
if (lc.size() != rc.size()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Different number of children at " + path + " (" + Integer.toString(lc.size()) + "/" + Integer.toString(rc.size()) + ")", ValidationMessage.IssueSeverity.ERROR));
status(ed, ProfileUtilities.STATUS_ERROR);
return false;
} else {
for (int i = 0; i < lc.size(); i++) {
DefinitionNavigator l = lc.get(i);
DefinitionNavigator r = rc.get(i);
String cpath = comparePaths(l.path(), r.path(), path, l.nameTail(), r.nameTail());
if (cpath != null) {
if (!compareElements(outcome, cpath, l, r))
return false;
} else {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Different path at " + path + "[" + Integer.toString(i) + "] (" + l.path() + "/" + r.path() + ")", ValidationMessage.IssueSeverity.ERROR));
status(ed, ProfileUtilities.STATUS_ERROR);
return false;
}
}
}
return true;
}
Aggregations