use of org.hl7.fhir.dstu3.model.Element in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(TypeDefn t) throws Exception {
genUml(t);
StructureDefinition p = new StructureDefinition();
p.setId(t.getName());
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + t.getName());
p.setKind(StructureDefinitionKind.COMPLEXTYPE);
p.setAbstract(t.isAbstractType());
p.setUserData("filename", t.getName().toLowerCase());
p.setUserData("path", definitions.getSrcFile(t.getName()) + ".html#" + t.getName());
assert !Utilities.noString(t.typeCode());
String b = (t.typeCode().equals("Type") ? "Element" : t.typeCode().equals("Structure") ? "BackboneElement" : t.typeCode());
if (!Utilities.noString(b)) {
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + b);
p.setDerivation(TypeDerivationRule.SPECIALIZATION);
}
p.setType(t.getName());
p.setFhirVersion(version);
p.setVersion(version.toCode());
ToolingExtensions.setStandardsStatus(p, t.getStandardsStatus(), t.getNormativeVersion());
ToolResourceUtilities.updateUsage(p, "core");
p.setName(t.getName());
p.setPublisher("HL7 FHIR Standard");
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
p.setDescription("Base StructureDefinition for " + t.getName() + " Type: " + t.getDefinition());
p.setPurpose(t.getRequirements());
p.setDate(genDate.getTime());
p.setStatus(t.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
Set<String> containedSlices = new HashSet<String>();
// first, the differential
p.setDifferential(new StructureDefinitionDifferentialComponent());
defineElement(null, p, p.getDifferential().getElement(), t, t.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, "Element", b, false);
p.getDifferential().getElement().get(0).setIsSummaryElement(null);
reset();
// now. the snapshot
p.setSnapshot(new StructureDefinitionSnapshotComponent());
defineElement(null, p, p.getSnapshot().getElement(), t, t.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.DataType, true, "Element", b, true);
for (ElementDefinition ed : p.getSnapshot().getElement()) if (ed.getBase().getPath().equals(ed.getPath()) && ed.getPath().contains("."))
generateElementDefinition(p, ed, getParent(ed, p.getSnapshot().getElement()));
containedSlices.clear();
addElementConstraintToSnapshot(p);
p.getDifferential().getElement().get(0).getType().clear();
p.getSnapshot().getElement().get(0).getType().clear();
p.getSnapshot().getElement().get(0).setIsSummaryElement(null);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
checkHasTypes(p);
return p;
}
use of org.hl7.fhir.dstu3.model.Element in project kindling by HL7.
the class ProfileGenerator method buildDefinitionFromElement.
private void buildDefinitionFromElement(String path, ElementDefinition ce, ElementDefn e, Profile ap, StructureDefinition p, String inheritedType, boolean isInterface) throws Exception {
if (!Utilities.noString(e.getComments()))
ce.setComment(preProcessMarkdown(e.getComments(), "Element Comments"));
if (!Utilities.noString(e.getShortDefn()))
ce.setShort(e.getShortDefn());
if (!Utilities.noString(e.getDefinition())) {
ce.setDefinition(preProcessMarkdown(e.getDefinition(), "Element Definition"));
if (!Utilities.noString(e.getShortDefn()))
ce.setShort(e.getShortDefn());
}
if (path.contains(".") && !Utilities.noString(e.getRequirements()))
ce.setRequirements(preProcessMarkdown(e.getRequirements(), "Element Requirements"));
if (e.hasMustSupport())
ce.setMustSupport(e.isMustSupport());
if (!Utilities.noString(e.getMaxLength()))
ce.setMaxLength(Integer.parseInt(e.getMaxLength()));
// no purpose here
if (e.getMinCardinality() != null)
ce.setMin(e.getMinCardinality());
if (e.getMaxCardinality() != null)
ce.setMax(e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
// we don't know mustSupport here
if (e.hasModifier())
ce.setIsModifier(e.isModifier());
if (ce.getIsModifier())
ce.setIsModifierReason(e.getModifierReason());
// ce.setConformance(getType(e.getConformance()));
for (Invariant id : e.getStatedInvariants()) {
ce.addCondition(id.getId());
}
ce.setFixed(e.getFixed());
ce.setPattern(e.getPattern());
// ce.setDefaultValue(e.getDefaultValue());
ce.setMeaningWhenMissing(e.getMeaningWhenMissing());
if (e.getExample() != null)
ce.addExample().setLabel("General").setValue(e.getExample());
for (Integer i : e.getOtherExamples().keySet()) {
Extension ex = ce.addExtension();
ex.setUrl("http://hl7.org/fhir/StructureDefinition/structuredefinition-example");
ex.addExtension().setUrl("index").setValue(new StringType(i.toString()));
ex.addExtension().setUrl("exValue").setValue(e.getOtherExamples().get(i));
}
for (String s : e.getAliases()) ce.addAlias(s);
if (e.hasSummaryItem() && ce.getPath().contains("."))
ce.setIsSummaryElement(Factory.newBoolean(e.isSummary()));
for (String n : definitions.getMapTypes().keySet()) {
addMapping(p, ce, n, e.getMapping(n), null);
}
if (ap != null) {
for (String n : ap.getMappingSpaces().keySet()) {
addMapping(p, ce, n, e.getMapping(n), ap);
}
}
ToolingExtensions.addDisplayHint(ce, e.getDisplayHint());
if (!isInterface) {
convertConstraints(e, ce, inheritedType == null ? p.getUrl() : "http://hl7.org/fhir/StructureDefinition/" + inheritedType);
}
// we don't have anything to say about constraints on resources
}
use of org.hl7.fhir.dstu3.model.Element in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(DefinedStringPattern type) throws Exception {
genUml(type);
StructureDefinition p = new StructureDefinition();
p.setId(type.getCode());
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + type.getCode());
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + type.getBase());
p.setType(type.getCode());
p.setDerivation(TypeDerivationRule.SPECIALIZATION);
p.setKind(StructureDefinitionKind.PRIMITIVETYPE);
p.setAbstract(false);
p.setUserData("filename", type.getCode().toLowerCase());
p.setUserData("path", "datatypes.html#" + type.getCode());
p.setFhirVersion(version);
p.setVersion(version.toCode());
ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
ToolResourceUtilities.updateUsage(p, "core");
p.setName(type.getCode());
p.setPublisher("HL7 FHIR Standard");
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
p.setDescription("Base StructureDefinition for " + type.getCode() + " type: " + type.getDefinition());
p.setDate(genDate.getTime());
p.setStatus(PublicationStatus.fromCode("active"));
Set<String> containedSlices = new HashSet<String>();
// first, the differential
p.setDifferential(new StructureDefinitionDifferentialComponent());
ElementDefinition ec1 = new ElementDefinition();
p.getDifferential().getElement().add(ec1);
ec1.setId(type.getCode());
ec1.setPath(type.getCode());
ec1.setShort("Primitive Type " + type.getCode());
ec1.setDefinition(type.getDefinition());
ec1.setComment(type.getComment());
ec1.setMin(0);
ec1.setMax("*");
ElementDefinition ec2 = new ElementDefinition();
p.getDifferential().getElement().add(ec2);
ec2.setId(type.getCode() + ".value");
ec2.setPath(type.getCode() + ".value");
ec2.addRepresentation(PropertyRepresentation.XMLATTR);
ec2.setShort("Primitive value for " + type.getCode());
ec2.setDefinition("Primitive value for " + type.getCode());
ec2.setMin(0);
ec2.setMax("1");
TypeRefComponent t = ec2.addType();
t.setCodeElement(new UriType());
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (g)");
t.setCode(Constants.NS_SYSTEM_TYPE + type.getFHIRPathType());
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, type.getCode());
if (!Utilities.noString(type.getRegex())) {
ToolingExtensions.addStringExtension(t, ToolingExtensions.EXT_REGEX, type.getRegex());
}
reset();
// now. the snapshot
p.setSnapshot(new StructureDefinitionSnapshotComponent());
ElementDefinition ecA = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ecA);
ecA.setId(type.getCode());
ecA.setPath(type.getCode());
ecA.setShort("Primitive Type " + type.getCode());
ecA.setDefinition(type.getDefinition());
ecA.setComment(type.getComment());
ecA.setMin(0);
ecA.setMax("*");
ecA.makeBase(type.getCode(), 0, "*");
addElementConstraints("Element", ecA);
ElementDefinition ecid = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ecid);
ecid.setId(type.getCode() + ".id");
ecid.setPath(type.getCode() + ".id");
ecid.addRepresentation(PropertyRepresentation.XMLATTR);
ecid.setDefinition("unique id for the element within a resource (for internal references)");
ecid.setMin(0);
ecid.setMax("1");
ecid.setShort("xml:id (or equivalent in JSON)");
TypeRefComponent tr = ecid.addType();
tr.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (h)");
tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "string");
ecid.makeBase("Element.id", 0, "1");
makeExtensionSlice("extension", p, p.getSnapshot(), null, type.getCode());
ElementDefinition ecB = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ecB);
ecB.setPath(type.getCode() + ".value");
ecB.setId(type.getCode() + ".value");
ecB.addRepresentation(PropertyRepresentation.XMLATTR);
ecB.setDefinition("Primitive value for " + type.getCode());
ecB.setShort("Primitive value for " + type.getCode());
ecB.setMin(0);
ecB.setMax("1");
ecB.makeBase(type.getBase() + ".value", 0, "1");
t = ecB.addType();
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (i)");
t.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
if (!Utilities.noString(type.getRegex()))
ToolingExtensions.addStringExtension(t, ToolingExtensions.EXT_REGEX, type.getRegex());
// generateElementDefinition(ecB, ecA);
containedSlices.clear();
addElementConstraintToSnapshot(p);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
checkHasTypes(p);
return p;
}
use of org.hl7.fhir.dstu3.model.Element in project kindling by HL7.
the class ProfileGenerator method generateXhtml.
public StructureDefinition generateXhtml() throws Exception {
uml.getTypes().put("html:div", new UMLPrimitive("html:div"));
StructureDefinition p = new StructureDefinition();
p.setId("xhtml");
p.setUrl("http://hl7.org/fhir/StructureDefinition/xhtml");
p.setKind(StructureDefinitionKind.PRIMITIVETYPE);
p.setAbstract(false);
p.setUserData("filename", "xhtml");
p.setUserData("path", "narrative.html#xhtml");
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
p.setType("xhtml");
p.setDerivation(TypeDerivationRule.SPECIALIZATION);
p.setFhirVersion(version);
p.setVersion(version.toCode());
ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
ToolResourceUtilities.updateUsage(p, "core");
p.setName("xhtml");
p.setPublisher("HL7 FHIR Standard");
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
p.setDescription("Base StructureDefinition for xhtml Type");
p.setDate(genDate.getTime());
p.setStatus(PublicationStatus.fromCode("active"));
Set<String> containedSlices = new HashSet<String>();
// first, the differential
p.setDifferential(new StructureDefinitionDifferentialComponent());
ElementDefinition ec = new ElementDefinition();
p.getDifferential().getElement().add(ec);
ec.setId("xhtml");
ec.setPath("xhtml");
ec.setShort("Primitive Type " + "xhtml");
ec.setDefinition("XHTML");
ec.setMin(0);
ec.setMax("*");
ec = new ElementDefinition();
p.getDifferential().getElement().add(ec);
ec.setId("xhtml" + ".extension");
ec.setPath("xhtml" + ".extension");
ec.setMax("0");
ec = new ElementDefinition();
p.getDifferential().getElement().add(ec);
ec.setId("xhtml" + ".value");
ec.setPath("xhtml" + ".value");
ec.addRepresentation(PropertyRepresentation.XHTML);
ec.setShort("Actual xhtml");
ec.setDefinition("Actual xhtml");
ec.setMin(1);
ec.setMax("1");
TypeRefComponent t = ec.addType();
t.setCodeElement(new UriType());
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (d)");
t.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
reset();
// now. the snapshot
p.setSnapshot(new StructureDefinitionSnapshotComponent());
ElementDefinition ec1 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ec1);
ec1.setId("xhtml");
ec1.setPath("xhtml");
ec1.setShort("Primitive Type " + "xhtml");
ec1.setDefinition("XHTML");
ec1.setMin(0);
ec1.setMin(0);
ec1.setMax("*");
ec1.makeBase();
generateElementDefinition(p, ec1, null);
ElementDefinition ec2 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ec2);
ec2.setId("xhtml.id");
ec2.setPath("xhtml.id");
ec2.addRepresentation(PropertyRepresentation.XMLATTR);
ec2.setDefinition("unique id for the element within a resource (for internal references)");
ec2.setMin(0);
ec2.setMax("1");
ec2.setShort("xml:id (or equivalent in JSON)");
TypeRefComponent tr = ec2.addType();
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (e)");
tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
generateElementDefinition(p, ec2, ec1);
ec2.makeBase("Element.id", 0, "1");
ElementDefinition ex = makeExtensionSlice("extension", p, p.getSnapshot(), null, "xhtml");
ex.setMax("0");
ElementDefinition ec3 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
p.getSnapshot().getElement().add(ec3);
ec3.setId("xhtml.value");
ec3.setPath("xhtml.value");
ec3.addRepresentation(PropertyRepresentation.XHTML);
ec3.setShort("Actual xhtml");
ec3.setDefinition("Actual xhtml");
ec3.setMin(1);
ec3.setMax("1");
t = ec3.addType();
t.setCodeElement(new UriType());
t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (f)");
t.setCode(Constants.NS_SYSTEM_TYPE + "String");
ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
ec3.makeBase();
generateElementDefinition(p, ec3, ec);
containedSlices.clear();
addElementConstraintToSnapshot(p);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
checkHasTypes(p);
return p;
}
use of org.hl7.fhir.dstu3.model.Element in project kindling by HL7.
the class ProfileGenerator method addElementConstraint.
/*
* // resource
// domain resource
for (ElementDefn child : definitions.getBaseResources().get("DomainResource").getRoot().getElements())
defineElement(null, p, p.getSnapshot(), child, r.getRoot().getName()+"."+child.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.Resource);
*/
/*
private String registerMapping(ConformancePackage ap, StructureDefinition p, String m) {
for (StructureDefinitionMappingComponent map : p.getMapping()) {
if (map.getUri().equals(m))
return map.getIdentity();
}
StructureDefinitionMappingComponent map = new StructureDefinitionMappingComponent();
MappingSpace space = definitions.getMapTypes().get(m);
if (space != null)
map.setIdentity(space.getId());
else
map.setIdentity("m" + Integer.toString(p.getMapping().size()+1));
map.setUri(m);
String name = ap.metadata(m+"-name");
if (Utilities.noString(name) && space != null)
name = space.getTitle();
if (!Utilities.noString(name))
map.setName(name);
String comments = ap.metadata(m+"-comments");
if (Utilities.noString(comments) && space != null)
comments = space.getPreamble();
if (!Utilities.noString(comments))
map.setComments(comments);
return map.getIdentity();
}
*/
private ElementDefinition addElementConstraint(StructureDefinition sd, ElementDefinition ed) {
if (!ed.getPath().contains(".") && sd.getKind() == StructureDefinitionKind.RESOURCE)
return ed;
if (hasSystemType(ed))
return ed;
if (isResource(ed))
return ed;
if (hasConstraint(ed, "ele-1"))
return ed;
ElementDefinitionConstraintComponent inv = ed.addConstraint();
inv.setKey("ele-1");
inv.setSeverity(ConstraintSeverity.ERROR);
inv.setHuman("All FHIR elements must have a @value or children");
inv.setExpression("hasValue() or (children().count() > id.count())");
inv.setXpath("@value|f:*|h:div");
inv.setSource("http://hl7.org/fhir/StructureDefinition/Element");
return ed;
}
Aggregations