use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class XVerPathsGenerator method execute.
public void execute() throws IOException {
// load the R4 content; can't be an extension if it already matches R4
loadR4();
// iterate all the elements, building a list
for (String s : sorted(definitions.getTypes().keySet())) {
ElementDefn ed = definitions.getTypes().get(s);
process(ed);
}
for (String s : sorted(definitions.getBaseResources().keySet())) {
ResourceDefn ed = definitions.getBaseResources().get(s);
process(ed.getRoot());
}
for (String s : sorted(definitions.getResources().keySet())) {
ResourceDefn ed = definitions.getResources().get(s);
process(ed.getRoot());
}
StringBuilder r5 = new StringBuilder();
r5.append("{\r\n");
int i = 0;
for (ElementInfo ei : r5List) {
r5.append(" \"" + ei.path + "\": { ");
if (ei.types.size() > 0) {
r5.append("\"types\": [");
boolean first = true;
for (String s : ei.types) {
if (first)
first = false;
else
r5.append(", ");
r5.append("\"" + s + "\"");
}
r5.append("]");
} else if (ei.elements.size() > 0) {
r5.append("\"elements\": [");
boolean first = true;
for (String s : ei.elements) {
if (first)
first = false;
else
r5.append(", ");
r5.append("\"" + s + "\"");
}
r5.append("]");
}
i++;
if (i == r5List.size()) {
r5.append(" }\r\n");
} else {
r5.append(" },\r\n");
}
}
r5.append("}\r\n");
TextFile.stringToFile(r5.toString(), dest);
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class MappingsGenerator method generate.
public void generate(ResourceDefn resource) throws IOException {
StringBuilder s = new StringBuilder();
List<String> maps = new ArrayList<String>();
listKnownMappings(resource.getRoot(), maps);
Collections.sort(maps, new Sorter());
StringBuilder list = new StringBuilder();
for (String m : maps) {
MappingSpace ms = definitions.getMapTypes().get(m);
list.append("|" + ms.getTitle() + "#" + ms.getId());
s.append("<a name=\"" + m + "\"> </a><a name=\"" + ms.getId() + "\"> </a>");
if (!Utilities.noString(ms.getLink()))
s.append("<h3>" + ms.getTitle() + " (<a href=\"" + ms.getLink() + "\">" + m + "</a>)</h3>");
else
s.append("<h3>" + ms.getTitle() + " (" + m + ")</h3>");
XhtmlNode pre = ms.getPreamble();
if (pre != null)
s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
s.append("<table class=\"grid\">\r\n");
genElement(s, 0, resource.getRoot(), m, ROOT_ONLY, true, ms.isSparse());
genInherited(s, resource, m);
genElement(s, 0, resource.getRoot(), m, CHILDREN_ONLY, true, ms.isSparse());
s.append("</table>\r\n");
}
mappings = s.toString();
mappingsList = list.length() == 0 ? "" : list.toString().substring(1);
}
use of org.hl7.fhir.definitions.model.ResourceDefn 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.definitions.model.ResourceDefn in project kindling by HL7.
the class ProfileGenerator method makeSearchParam.
public SearchParameter makeSearchParam(StructureDefinition p, String id, String rn, SearchParameterDefn spd, ResourceDefn rd) throws Exception {
boolean shared;
boolean created = true;
SearchParameter sp;
if (definitions.getCommonSearchParameters().containsKey(rn + "::" + spd.getCode())) {
shared = true;
CommonSearchParameter csp = definitions.getCommonSearchParameters().get(rn + "::" + spd.getCode());
if (csp.getDefinition() == null) {
sp = new SearchParameter();
csp.setDefinition(sp);
sp.setId(csp.getId());
} else {
created = false;
sp = csp.getDefinition();
}
} else {
shared = false;
sp = new SearchParameter();
sp.setId(id.replace("[", "").replace("]", ""));
}
spd.setCommonId(sp.getId());
if (created) {
sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
sp.setVersion(version.toCode());
if (context.getSearchParameter(sp.getUrl()) != null)
throw new Exception("Duplicated Search Parameter " + sp.getUrl());
context.cacheResource(sp);
spd.setResource(sp);
definitions.addNs(sp.getUrl(), "Search Parameter: " + sp.getName(), rn.toLowerCase() + ".html#search");
sp.setStatus(spd.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
StandardsStatus sst = ToolingExtensions.getStandardsStatus(sp);
if (sst == null || (spd.getStandardsStatus() == null && spd.getStandardsStatus().isLowerThan(sst)))
ToolingExtensions.setStandardsStatus(sp, spd.getStandardsStatus(), spd.getNormativeVersion());
sp.setExperimental(p.getExperimental());
sp.setName(spd.getCode());
sp.setCode(spd.getCode());
sp.setDate(genDate.getTime());
sp.setPublisher(p.getPublisher());
for (ContactDetail tc : p.getContact()) {
ContactDetail t = sp.addContact();
if (tc.hasNameElement())
t.setNameElement(tc.getNameElement().copy());
for (ContactPoint ts : tc.getTelecom()) t.getTelecom().add(ts.copy());
}
if (!definitions.hasResource(p.getType()) && !p.getType().equals("Resource") && !p.getType().equals("DomainResource"))
throw new Exception("unknown resource type " + p.getType());
sp.setType(getSearchParamType(spd.getType()));
if (sp.getType() == SearchParamType.REFERENCE && spd.isHierarchy()) {
sp.addModifier(SearchParameter.SearchModifierCode.BELOW);
sp.addModifier(SearchParameter.SearchModifierCode.ABOVE);
}
if (shared) {
sp.setDescription("Multiple Resources: \r\n\r\n* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
} else
sp.setDescription(preProcessMarkdown(spd.getDescription(), "Search Description"));
if (!Utilities.noString(spd.getExpression()))
sp.setExpression(spd.getExpression());
// addModifiers(sp);
addComparators(sp);
String xpath = Utilities.noString(spd.getXPath()) ? new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn) : spd.getXPath();
if (xpath != null) {
if (xpath.contains("[x]"))
xpath = convertToXpath(xpath);
sp.setXpath(xpath);
sp.setXpathUsage(spd.getxPathUsage());
}
if (sp.getType() == SearchParamType.COMPOSITE) {
for (CompositeDefinition cs : spd.getComposites()) {
SearchParameterDefn cspd = findSearchParameter(rd, cs.getDefinition());
if (cspd != null)
sp.addComponent().setExpression(cs.getExpression()).setDefinition(cspd.getUrl());
else
sp.addComponent().setExpression(cs.getExpression()).setDefinition("http://hl7.org/fhir/SearchParameter/" + rn + "-" + cs.getDefinition());
}
sp.setMultipleOr(false);
}
sp.addBase(p.getType());
} else {
if (sp.getType() != getSearchParamType(spd.getType()))
throw new FHIRException("Type mismatch on common parameter: expected " + sp.getType().toCode() + " but found " + getSearchParamType(spd.getType()).toCode());
if (!sp.getDescription().contains("[" + rn + "](" + rn.toLowerCase() + ".html)"))
sp.setDescription(sp.getDescription() + "* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
// ext.addExtension("description", new MarkdownType(spd.getDescription()));
if (!Utilities.noString(spd.getExpression()) && !sp.getExpression().contains(spd.getExpression()))
sp.setExpression(sp.getExpression() + " | " + spd.getExpression());
String xpath = new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn);
if (xpath != null) {
if (xpath.contains("[x]"))
xpath = convertToXpath(xpath);
if (sp.getXpath() != null && !sp.getXpath().contains(xpath))
sp.setXpath(sp.getXpath() + " | " + xpath);
if (sp.getXpathUsage() != spd.getxPathUsage())
throw new FHIRException("Usage mismatch on common parameter: expected " + sp.getXpathUsage().toCode() + " but found " + spd.getxPathUsage().toCode());
}
boolean found = false;
for (CodeType ct : sp.getBase()) found = found || p.getType().equals(ct.asStringValue());
if (!found)
sp.addBase(p.getType());
}
spd.setUrl(sp.getUrl());
for (String target : spd.getWorkingTargets()) {
if ("Any".equals(target) == true) {
for (String resourceName : definitions.sortedResourceNames()) {
boolean found = false;
for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(resourceName);
if (!found)
sp.addTarget(resourceName);
}
} else {
boolean found = false;
for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(target);
if (!found)
sp.addTarget(target);
}
}
return sp;
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class FhirTurtleGenerator method genResourceDefn.
/**
* Resource Definition generator
*
* @param rd Resource Definition to emit
* @throws Exception
*/
private void genResourceDefn(ResourceDefn rd) throws Exception {
String resourceName = rd.getName();
ElementDefn resourceType = rd.getRoot();
FHIRResource rdRes = fact.fhir_class(resourceName, resourceType.getTypes().isEmpty() ? OWL2.Thing : RDFNamespace.FHIR.resourceRef(resourceType.typeCode())).addDefinition(rd.getDefinition());
processTypes(resourceName, rdRes, resourceType, resourceName, true);
if (!Utilities.noString(resourceType.getW5()))
rdRes.addObjectProperty(RDFS.subClassOf, RDFNamespace.W5.resourceRef(resourceType.getW5()));
}
Aggregations