use of org.hl7.fhir.utilities.xml.SchematronWriter.Rule 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;
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Rule in project kindling by HL7.
the class SchematronGenerator method genChildren.
private void genChildren(Section section, String path, String typeCode, ElementDefn ed, Definitions definitions, List<String> parents) throws Exception {
if (!path.contains("//")) {
ArrayList<String> l = new ArrayList<String>(parents);
l.add(typeCode);
for (ElementDefn cd : ed.getElements()) {
if (!Utilities.noString(cd.typeCode()) && l.contains(cd.typeCode())) {
// well, we've recursed. What's going to happen now is that we're going to write this as // because we're going to keep recursing.
// the next call will write this rule, and then terminate
generateInvariants(section, path + "/", cd, definitions, l, cd.getName());
} else
generateInvariants(section, path, cd, definitions, l, cd.getName());
}
}
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Rule in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeTestScript.
protected void composeTestScript(Complex parent, String parentType, String name, TestScript element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeDomainResource(t, "TestScript", name, element, index);
if (element.hasUrlElement())
composeUri(t, "TestScript", "url", element.getUrlElement(), -1);
if (element.hasIdentifier())
composeIdentifier(t, "TestScript", "identifier", element.getIdentifier(), -1);
if (element.hasVersionElement())
composeString(t, "TestScript", "version", element.getVersionElement(), -1);
if (element.hasNameElement())
composeString(t, "TestScript", "name", element.getNameElement(), -1);
if (element.hasTitleElement())
composeString(t, "TestScript", "title", element.getTitleElement(), -1);
if (element.hasStatusElement())
composeEnum(t, "TestScript", "status", element.getStatusElement(), -1);
if (element.hasExperimentalElement())
composeBoolean(t, "TestScript", "experimental", element.getExperimentalElement(), -1);
if (element.hasDateElement())
composeDateTime(t, "TestScript", "date", element.getDateElement(), -1);
if (element.hasPublisherElement())
composeString(t, "TestScript", "publisher", element.getPublisherElement(), -1);
for (int i = 0; i < element.getContact().size(); i++) composeContactDetail(t, "TestScript", "contact", element.getContact().get(i), i);
if (element.hasDescriptionElement())
composeMarkdown(t, "TestScript", "description", element.getDescriptionElement(), -1);
for (int i = 0; i < element.getUseContext().size(); i++) composeUsageContext(t, "TestScript", "useContext", element.getUseContext().get(i), i);
for (int i = 0; i < element.getJurisdiction().size(); i++) composeCodeableConcept(t, "TestScript", "jurisdiction", element.getJurisdiction().get(i), i);
if (element.hasPurposeElement())
composeMarkdown(t, "TestScript", "purpose", element.getPurposeElement(), -1);
if (element.hasCopyrightElement())
composeMarkdown(t, "TestScript", "copyright", element.getCopyrightElement(), -1);
for (int i = 0; i < element.getOrigin().size(); i++) composeTestScriptTestScriptOriginComponent(t, "TestScript", "origin", element.getOrigin().get(i), i);
for (int i = 0; i < element.getDestination().size(); i++) composeTestScriptTestScriptDestinationComponent(t, "TestScript", "destination", element.getDestination().get(i), i);
if (element.hasMetadata())
composeTestScriptTestScriptMetadataComponent(t, "TestScript", "metadata", element.getMetadata(), -1);
for (int i = 0; i < element.getFixture().size(); i++) composeTestScriptTestScriptFixtureComponent(t, "TestScript", "fixture", element.getFixture().get(i), i);
for (int i = 0; i < element.getProfile().size(); i++) composeReference(t, "TestScript", "profile", element.getProfile().get(i), i);
for (int i = 0; i < element.getVariable().size(); i++) composeTestScriptTestScriptVariableComponent(t, "TestScript", "variable", element.getVariable().get(i), i);
for (int i = 0; i < element.getRule().size(); i++) composeTestScriptTestScriptRuleComponent(t, "TestScript", "rule", element.getRule().get(i), i);
for (int i = 0; i < element.getRuleset().size(); i++) composeTestScriptTestScriptRulesetComponent(t, "TestScript", "ruleset", element.getRuleset().get(i), i);
if (element.hasSetup())
composeTestScriptTestScriptSetupComponent(t, "TestScript", "setup", element.getSetup(), -1);
for (int i = 0; i < element.getTest().size(); i++) composeTestScriptTestScriptTestComponent(t, "TestScript", "test", element.getTest().get(i), i);
if (element.hasTeardown())
composeTestScriptTestScriptTeardownComponent(t, "TestScript", "teardown", element.getTeardown(), -1);
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Rule in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeTestScriptActionAssertRuleComponent.
protected void composeTestScriptActionAssertRuleComponent(Complex parent, String parentType, String name, TestScript.ActionAssertRuleComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "rule", name, element, index);
if (element.hasRuleIdElement())
composeId(t, "TestScript", "ruleId", element.getRuleIdElement(), -1);
for (int i = 0; i < element.getParam().size(); i++) composeTestScriptActionAssertRuleParamComponent(t, "TestScript", "param", element.getParam().get(i), i);
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Rule in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeTestScriptTestScriptRuleComponent.
protected void composeTestScriptTestScriptRuleComponent(Complex parent, String parentType, String name, TestScript.TestScriptRuleComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "rule", name, element, index);
if (element.hasResource())
composeReference(t, "TestScript", "resource", element.getResource(), -1);
for (int i = 0; i < element.getParam().size(); i++) composeTestScriptRuleParamComponent(t, "TestScript", "param", element.getParam().get(i), i);
}
Aggregations