use of org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionSnapshotComponent in project kindling by HL7.
the class ProfileGenerator method generateLogicalModel.
public StructureDefinition generateLogicalModel(ImplementationGuideDefn igd, ResourceDefn r) throws Exception {
StructureDefinition p = new StructureDefinition();
p.setId(r.getRoot().getName());
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + r.getRoot().getName());
p.setKind(StructureDefinitionKind.LOGICAL);
p.setAbstract(false);
p.setUserData("filename", r.getName().toLowerCase());
p.setUserData("path", igd.getPrefix() + r.getName().toLowerCase() + ".html");
p.setTitle(r.getName());
p.setFhirVersion(version);
p.setVersion(version.toCode());
p.setType(r.getRoot().getName());
ToolingExtensions.setStandardsStatus(p, r.getStatus(), null);
ToolResourceUtilities.updateUsage(p, igd.getCode());
p.setName(r.getRoot().getName());
p.setPublisher("Health Level Seven International" + (r.getWg() == null ? " " + igd.getCommittee() : " (" + r.getWg().getName() + ")"));
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
if (r.getWg() != null) {
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, r.getWg().getUrl()));
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, r.getWg().getCode());
}
p.setDescription("Logical Model: " + r.getDefinition());
p.setPurpose(r.getRoot().getRequirements());
if (!p.hasPurpose())
p.setPurpose(r.getRoot().getRequirements());
p.setDate(genDate.getTime());
// DSTU
p.setStatus(PublicationStatus.fromCode("draft"));
Set<String> containedSlices = new HashSet<String>();
// first, the differential
p.setSnapshot(new StructureDefinitionSnapshotComponent());
defineElement(null, p, p.getSnapshot().getElement(), r.getRoot(), r.getRoot().getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, "Element", "Element", true);
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);
return p;
}
use of org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionSnapshotComponent 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.StructureDefinition.StructureDefinitionSnapshotComponent 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.StructureDefinition.StructureDefinitionSnapshotComponent 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.StructureDefinition.StructureDefinitionSnapshotComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateSnapshot.
/**
* Given a base (snapshot) profile structure, and a differential profile, generate a new snapshot profile
*
* @param base - the base structure on which the differential will be applied
* @param differential - the differential to apply to the base
* @param url - where the base has relative urls for profile references, these need to be converted to absolutes by prepending this URL
* @param trimDifferential - if this is true, then the snap short generator will remove any material in the element definitions that is not different to the base
* @return
* @throws FHIRException
* @throws DefinitionException
* @throws Exception
*/
public void generateSnapshot(StructureDefinition base, StructureDefinition derived, String url, String profileName) throws DefinitionException, FHIRException {
if (base == null)
throw new DefinitionException("no base profile provided");
if (derived == null)
throw new DefinitionException("no derived structure provided");
if (snapshotStack.contains(derived.getUrl()))
throw new DefinitionException("Circular snapshot references detected; cannot generate snapshot (stack = " + snapshotStack.toString() + ")");
snapshotStack.add(derived.getUrl());
// System.out.println("Generate Snapshot for "+derived.getUrl());
derived.setSnapshot(new StructureDefinitionSnapshotComponent());
// so we have two lists - the base list, and the differential list
// the differential list is only allowed to include things that are in the base list, but
// is allowed to include them multiple times - thereby slicing them
// our approach is to walk through the base list, and see whether the differential
// says anything about them.
int baseCursor = 0;
// we need a diff cursor because we can only look ahead, in the bound scoped by longer paths
int diffCursor = 0;
// we actually delegate the work to a subroutine so we can re-enter it with a different cursors
processPaths(derived.getSnapshot(), base.getSnapshot(), derived.getDifferential(), baseCursor, diffCursor, base.getSnapshot().getElement().size() - 1, derived.getDifferential().getElement().size() - 1, url, derived.getId(), null, false, base.getUrl(), null, false);
}
Aggregations