use of org.hl7.fhir.definitions.validation.FHIRPathUsage in project kindling by HL7.
the class Publisher method processProfiles.
@SuppressWarnings("unchecked")
private void processProfiles() throws Exception {
page.log(" ...process profiles (base)", LogMessageType.Process);
// first, for each type and resource, we build it's master profile
for (DefinedCode t : page.getDefinitions().getPrimitives().values()) {
if (t instanceof PrimitiveType)
genPrimitiveTypeProfile((PrimitiveType) t);
else
genPrimitiveTypeProfile((DefinedStringPattern) t);
}
genXhtmlProfile();
for (TypeDefn t : page.getDefinitions().getTypes().values()) genTypeProfile(t);
for (TypeDefn t : page.getDefinitions().getInfrastructure().values()) genTypeProfile(t);
page.log(" ...process profiles (resources)", LogMessageType.Process);
for (ResourceDefn r : page.getDefinitions().getBaseResources().values()) {
r.setConformancePack(makeConformancePack(r));
r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
if (page.getProfiles().has(r.getProfile().getUrl()))
throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
page.getProfiles().see(r.getProfile(), page.packageInfo());
ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
}
for (String rn : page.getDefinitions().sortedResourceNames()) {
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
r.setConformancePack(makeConformancePack(r));
r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
if (page.getProfiles().has(r.getProfile().getUrl()))
throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
page.getProfiles().see(r.getProfile(), page.packageInfo());
ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
}
for (ResourceDefn r : page.getDefinitions().getResourceTemplates().values()) {
r.setConformancePack(makeConformancePack(r));
r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", true));
ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", true));
if (page.getProfiles().has(r.getProfile().getUrl()))
throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
page.getProfiles().see(r.getProfile(), page.packageInfo());
}
for (ProfiledType pt : page.getDefinitions().getConstraints().values()) {
genProfiledTypeProfile(pt);
}
page.log(" ...process profiles (extensions)", LogMessageType.Process);
for (StructureDefinition ex : page.getWorkerContext().getExtensionDefinitions()) processExtension(ex);
for (ResourceDefn r : page.getDefinitions().getResources().values()) {
// boolean logged = false;
for (Profile ap : r.getConformancePackages()) {
// logged = true;
for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), r);
}
}
page.log(" ...process profiles (packs)", LogMessageType.Process);
// we have profiles scoped by resources, and stand alone profiles
for (Profile ap : page.getDefinitions().getPackList()) {
// page.log(" ... pack "+ap.getId(), LogMessageType.Process);
for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), null);
}
page.log(" ...process logical models", LogMessageType.Process);
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
for (LogicalModel lm : ig.getLogicalModels()) {
page.log(" ...process logical model " + lm.getId(), LogMessageType.Process);
if (lm.getDefinition() == null)
lm.setDefinition(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generateLogicalModel(ig, lm.getResource()));
}
}
// now, validate the profiles
for (Profile ap : page.getDefinitions().getPackList()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
for (ResourceDefn r : page.getDefinitions().getResources().values()) for (Profile ap : r.getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
page.log(" ...Check FHIR Path Expressions", LogMessageType.Process);
StringBuilder b = new StringBuilder();
FHIRPathEngine fp = new FHIRPathEngine(page.getWorkerContext());
fp.setHostServices(page.getExpressionResolver());
for (FHIRPathUsage p : fpUsages) {
checkExpression(b, fp, p);
}
TextFile.stringToFile(b.toString(), Utilities.path(page.getFolders().dstDir, "fhirpaths.txt"));
checkAllOk();
}
use of org.hl7.fhir.definitions.validation.FHIRPathUsage in project kindling by HL7.
the class OldSpreadsheetParser method parseCommonTypeColumns.
private ResourceDefn parseCommonTypeColumns(boolean isResource, boolean isTemplate) throws Exception {
ResourceDefn resource = new ResourceDefn();
resource.setInterface(isTemplate);
Sheet sheet = loadSheet("Bindings");
if (sheet != null)
readBindings(sheet);
sheet = loadSheet("Invariants");
Map<String, Invariant> invariants = null;
if (sheet != null)
invariants = readInvariants(sheet, title, "Invariants");
sheet = loadSheet("Data Elements");
if (sheet == null)
throw new Exception("No Sheet found for Data Elements");
for (int row = 0; row < sheet.rows.size(); row++) {
processLine(resource, sheet, row, invariants, false, null, row == 0);
}
// default...
StandardsStatus ss = StandardsStatus.TRIAL_USE;
String s = ini.getStringProperty("normative", resource.getName());
if (!Utilities.noString(s))
ss = StandardsStatus.NORMATIVE;
resource.setStatus(ss);
resource.setRequirements(resource.getRoot().getRequirements());
resource.addHints(checkIgnoredColumns(sheet));
if (template != null) {
resource.setTemplate(template.getRoot());
copySearchParameters(resource);
copyInvariants(resource);
template = null;
}
parseMetadata(resource);
if (invariants != null) {
for (Invariant inv : invariants.values()) {
if (Utilities.noString(inv.getContext()))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " has no context");
else {
ElementDefn ed = findContext(resource.getRoot(), inv.getContext(), "Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " Context");
if (ed.getName().endsWith("[x]") && !inv.getContext().endsWith("[x]"))
inv.setFixedName(inv.getContext().substring(inv.getContext().lastIndexOf(".") + 1));
ed.getInvariants().put(inv.getId(), inv);
if (Utilities.noString(inv.getXpath())) {
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") has no XPath statement");
} else if (inv.getXpath().contains("\""))
throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") contains a \" character");
if (Utilities.noString(inv.getExpression())) {
// This has been disabled for now, per Lloyd McKenzie's request via Skype - jamesagnew
// throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
} else {
fpUsages.add(new FHIRPathUsage(inv.getContext(), isResource ? resource.getName() : "DomainResource", inv.getContext(), null, inv.getExpression(), inv.getXpath()));
}
}
}
}
// EK: Future types. But those won't get there.
if (bindings != null)
resource.getRoot().getNestedBindings().putAll(bindings);
scanNestedTypes(resource, resource.getRoot(), resource.getName());
resolveElementReferences(resource, resource.getRoot());
resource.getRoot().setAbstractType(isAbstract);
return resource;
}
use of org.hl7.fhir.definitions.validation.FHIRPathUsage in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(ProfiledType pt, List<ValidationMessage> issues) throws Exception {
StructureDefinition p = new StructureDefinition();
p.setId(pt.getName());
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType());
p.setKind(StructureDefinitionKind.COMPLEXTYPE);
p.setType(pt.getBaseType());
p.setDerivation(TypeDerivationRule.CONSTRAINT);
p.setAbstract(false);
p.setUserData("filename", pt.getName().toLowerCase());
p.setUserData("path", "datatypes.html#" + pt.getName());
p.setFhirVersion(version);
p.setVersion(version.toCode());
ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
p.setStatus(PublicationStatus.fromCode("active"));
ToolResourceUtilities.updateUsage(p, "core");
p.setName(pt.getName());
p.setPublisher("HL7 FHIR Standard");
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
p.setDescription("Base StructureDefinition for Type " + pt.getName() + ": " + pt.getDefinition());
p.setDescription(pt.getDefinition());
p.setDate(genDate.getTime());
// first, the differential
p.setName(pt.getName());
ElementDefinition e = new ElementDefinition();
String idroot = e.getId();
e.setPath(pt.getBaseType());
// e.setSliceName(pt.getName());
e.setShort(pt.getDefinition());
e.setDefinition(preProcessMarkdown(pt.getDescription(), "??"));
e.setMin(0);
e.setMax("*");
e.setIsModifier(false);
String s = definitions.getTLAs().get(pt.getName().toLowerCase());
if (s == null)
throw new Exception("There is no TLA for '" + pt.getName() + "' in fhir.ini");
ElementDefinitionConstraintComponent inv = new ElementDefinitionConstraintComponent();
inv.setKey(s + "-1");
inv.setRequirements(pt.getInvariant().getRequirements());
inv.setSeverity(ConstraintSeverity.ERROR);
inv.setHuman(pt.getInvariant().getEnglish());
if (!"n/a".equals(pt.getInvariant().getExpression())) {
fpUsages.add(new FHIRPathUsage(pt.getName(), pt.getName(), pt.getName(), null, pt.getInvariant().getExpression()));
inv.setExpression(pt.getInvariant().getExpression());
}
inv.setXpath(pt.getInvariant().getXpath());
e.getConstraint().add(inv);
p.setDifferential(new StructureDefinitionDifferentialComponent());
p.getDifferential().getElement().add(e);
StructureDefinition base = getTypeSnapshot(pt.getBaseType());
if (!pt.getRules().isEmpty()) {
// throw new Exception("todo");
for (String rule : pt.getRules().keySet()) {
String[] parts = rule.split("\\.");
String value = pt.getRules().get(rule);
ElementDefinition er = findElement(p.getDifferential(), pt.getBaseType() + '.' + parts[0]);
if (er == null) {
er = new ElementDefinition();
er.setId(pt.getBaseType() + ':' + p.getId() + '.' + parts[0]);
er.setPath(pt.getBaseType() + '.' + parts[0]);
p.getDifferential().getElement().add(er);
}
if (parts[1].equals("min"))
er.setMin(Integer.parseInt(value));
else if (parts[1].equals("max"))
er.setMax(value);
else if (parts[1].equals("defn"))
er.setDefinition(preProcessMarkdown(value, "er"));
}
List<String> errors = new ArrayList<String>();
new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, true);
for (String se : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), se, IssueSeverity.WARNING));
}
reset();
// now, the snapshot
new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType(), "http://hl7.org/fhir", p.getName());
// for (ElementDefinition ed : p.getSnapshot().getElement())
// generateElementDefinition(ed, getParent(ed, p.getSnapshot().getElement()));
p.getDifferential().getElement().get(0).getType().clear();
p.getSnapshot().getElement().get(0).getType().clear();
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addTag("h2").addText("Data type " + pt.getName());
div.addTag("p").addText(pt.getDefinition());
div.addTag("h3").addText("Rule");
div.addTag("p").addText(pt.getInvariant().getEnglish());
div.addTag("p").addText("XPath:");
div.addTag("blockquote").addTag("pre").addText(pt.getInvariant().getXpath());
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
addElementConstraintToSnapshot(p);
new ProfileUtilities(context, issues, pkp).setIds(p, false);
checkHasTypes(p);
return p;
}
Aggregations