use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class CDAGenerator method processDataType.
private void processDataType(Element dt, String n, String p) throws FileNotFoundException, IOException, FHIRFormatError, DefinitionException {
if (!Utilities.existsInList(n, "TYPE", "BN", "BIN", "CO", "UID", "OID", "UUID", "RUID", "URL", "ADXP", "ENXP", "PN", "TN", "ON", "RTO", "CAL", "CLCY", "SET", "LIST", "GLIST", "SLIST", "BAG", "HXIT", "HIST", "UVP", "NPPD", "PPD")) {
if (n.equals("GTS"))
n = "SXCM_TS";
System.out.print(" " + n);
StructureDefinition sd = new StructureDefinition();
sd.setId(fix(n));
sd.setUrl("http://hl7.org/fhir/cda/StructureDefinition/" + fix(n));
library.put(sd.getUrl(), sd);
sd.setName("V3 Data type " + n + " (" + dt.getAttribute("title") + ")");
sd.setTitle(sd.getName());
sd.setStatus(PublicationStatus.ACTIVE);
sd.setExperimental(false);
sd.setPublisher("HL7");
sd.setDescription(getDefinition(dt));
sd.setType(sd.getUrl());
sd.setKind(StructureDefinitionKind.LOGICAL);
sd.setAbstract("true".equals(dt.getAttribute("isAbstract")));
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:v3"));
Element derived = XMLUtil.getNamedChild(dt, "mif:derivedFrom");
if (Utilities.existsInList(n, "ST", "ED", "TEL", "AD", "EN", "IVL_PQ", "IVL_INT", "TS")) {
sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/ANY");
} else if (Utilities.existsInList(n, "SXCM_TS")) {
sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/TS");
} else if (n.equals("PIVL_TS") || n.equals("EIVL_TS") || n.equals("IVL_TS")) {
sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/SXCM_TS");
} else if (derived != null) {
sd.setBaseDefinition("http://hl7.org/fhir/cda/StructureDefinition/" + XMLUtil.getNamedChildAttribute(derived, "mif:targetDatatype", "name"));
} else
sd.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
sd.setDerivation(TypeDerivationRule.SPECIALIZATION);
ElementDefinition edb = new ElementDefinition();
edb.setPath(sd.getId());
seePath(edb);
edb.setMin(1);
edb.setMax("*");
edb.addType().setCode("Element");
sd.getDifferential().getElement().add(edb);
if (n.equals("ED"))
addEDElements(sd.getDifferential().getElement());
if (n.equals("SC"))
copyAttributes(sd, getDefinition("CV"), "code", "codeSystem", "codeSystemVersion", "displayName");
if (primitiveTypes.containsKey(n))
addValueAttribute(sd.getDifferential().getElement(), n, primitiveTypes.get(n));
if (n.equals("TS"))
edb.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-timeformat", new CodeType("YYYYMMDDHHMMSS.UUUU[+|-ZZzz]"));
if (n.equals("TEL"))
addValueAttribute(sd.getDifferential().getElement(), n, "uri");
if (n.equals("SXCM_TS")) {
addOperatorAttribute(sd.getDifferential().getElement(), "SXCM_TS");
sd.setAbstract(true);
}
if (n.equals("AD")) {
addParts(sd.getDifferential().getElement(), n, "delimiter", "country", "state", "county", "city", "postalCode", "streetAddressLine", "houseNumber", "houseNumberNumeric", "direction", "streetName", "streetNameBase", "streetNameType", "additionalLocator", "unitID", "unitType", "careOf", "censusTract", "deliveryAddressLine", "deliveryInstallationType", "deliveryInstallationArea", "deliveryInstallationQualifier", "deliveryMode", "deliveryModeIdentifier", "buildingNumberSuffix", "postBox", "precinct");
addTextItem(sd.getDifferential().getElement(), n);
}
if (n.equals("EN")) {
addParts(sd.getDifferential().getElement(), n, "delimiter", "family", "given", "prefix", "suffix");
addTextItem(sd.getDifferential().getElement(), n);
}
List<Element> props = new ArrayList<Element>();
XMLUtil.getNamedChildren(dt, "mif:property", props);
for (Element prop : props) {
processProperty(sd.getDifferential().getElement(), n, prop, p);
}
if (n.equals("TS") || n.equals("PQ"))
addInclusiveAttribute(sd.getDifferential().getElement(), n);
if (n.equals("CE") || n.equals("CV") || n.equals("CD"))
addCDExtensions(sd.getDifferential().getElement(), n);
new ProfileUtilities(null, null, null).setIds(sd, true);
structures.add(sd);
}
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class LogicalModelProcessor method genLogicalModelTable.
private String genLogicalModelTable(StructureDefinition sd, String prefix) throws Exception {
ProfileUtilities pu = new ProfileUtilities(page.getWorkerContext(), null, this);
XhtmlNode x = pu.generateTable(sd.getId() + "-definitions.html", sd, sd.hasSnapshot() ? false : true, page.getFolders().dstDir, false, sd.getId(), true, prefix, prefix, true, false, null, true, false);
return new XhtmlComposer(XhtmlComposer.HTML).compose(x);
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class SourceParser method loadConformancePackage.
private void loadConformancePackage(Profile ap, List<ValidationMessage> issues, WorkGroup wg) throws FileNotFoundException, IOException, Exception {
if (ap.getSourceType() == ConformancePackageSourceType.Spreadsheet) {
OldSpreadsheetParser sparser = new OldSpreadsheetParser(ap.getCategory(), new CSFileInputStream(ap.getSource()), Utilities.noString(ap.getId()) ? ap.getSource() : ap.getId(), ap.getSource(), definitions, srcDir, logger, registry, version, context, genDate, false, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
sparser.setFolder(Utilities.getDirectoryForFile(ap.getSource()));
sparser.parseConformancePackage(ap, definitions, Utilities.getDirectoryForFile(ap.getSource()), ap.getCategory(), issues, wg);
errors.addAll(sparser.getErrors());
} else if (ap.getSourceType() == ConformancePackageSourceType.StructureDefinition) {
Resource rf;
try {
rf = new XmlParser().parse(new CSFileInputStream(ap.getSource()));
} catch (Exception e) {
throw new Exception("Error parsing " + ap.getSource() + ": " + e.getMessage(), e);
}
if (!(rf instanceof StructureDefinition))
throw new Exception("Error parsing Profile: not a structure definition");
StructureDefinition sd = (StructureDefinition) rf;
sd.setVersion(version.toCode());
ap.putMetadata("id", sd.getId() + "-pack");
ap.putMetadata("date", sd.getDateElement().asStringValue());
ap.putMetadata("title", sd.getTitle());
ap.putMetadata("status", sd.getStatus().toCode());
ap.putMetadata("description", new XhtmlComposer(XhtmlComposer.HTML).compose(sd.getText().getDiv()));
if (ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg")) {
wg = definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"));
ap.putMetadata("workgroup", wg.getCode());
}
ap.setTitle(sd.getTitle());
new ProfileUtilities(page.getWorkerContext(), null, null).setIds(sd, false);
ap.getProfiles().add(new ConstraintStructure(sd, definitions.getUsageIG(ap.getCategory(), "Parsing " + ap.getSource()), wg == null ? wg(sd) : wg, fmm(sd), sd.getExperimental()));
} else if (ap.getSource() != null) {
parseConformanceDocument(ap, ap.getId(), new CSFile(ap.getSource()), ap.getCategory(), wg);
}
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class ResourceParser method parseResource.
private ResourceDefn parseResource(String t) throws FHIRFormatError, FileNotFoundException, IOException {
StructureDefinition sd = (StructureDefinition) parseXml("structuredefinition-" + t + ".xml");
sdList.put(sd.getUrl(), sd);
sd.setVersion(version);
ResourceDefn r = new ResourceDefn();
r.setName(sd.getName());
r.setEnteredInErrorStatus(ToolingExtensions.readStringExtension(sd, BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS));
r.setStatus(StandardsStatus.fromCode(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_STANDARDS_STATUS)));
r.setAbstract(sd.getAbstract());
r.setInterface(ToolingExtensions.readBoolExtension(sd, BuildExtensions.EXT_RESOURCE_INTERFACE));
r.setWg(definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_WORKGROUP)));
r.setFmmLevel(ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_FMM_LEVEL));
r.setProposedOrder(ToolingExtensions.readStringExtension(sd, BuildExtensions.EXT_PROPOSED_ORDER));
r.setSecurityCategorization(SecurityCategorization.fromCode(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category")));
r.setRequirements(sd.getPurpose());
r.setDefinition(sd.getDescription());
if (sd.hasExtension(BuildExtensions.EXT_TEMPLATE)) {
String tname = BuildExtensions.readStringExtension(sd, BuildExtensions.EXT_TEMPLATE);
ResourceDefn template = definitions.getResourceByName(tname);
r.setTemplate(template.getRoot());
}
// private long timestamp; only set in regenerator...?
// todo:
// private List<InheritedMapping> inheritedMappings = new ArrayList<InheritedMapping>();
// private ElementDefn template;
// private Map<String, PointSpec> layout = new HashMap<String, PointSpec>();
ProfileUtilities pu = new ProfileUtilities(context, null, null);
r.setRoot(parseTypeDefinition(pu, sd.getDifferential().getElementFirstRep(), sd));
r.getRoot().setFmmLevel(r.getFmmLevel());
r.getRoot().setRequirements(r.getRequirements());
if (r.isAbstract()) {
r.getRoot().setAbstractType(true);
}
if (sd.hasBaseDefinition()) {
r.getRoot().getTypes().add(new TypeRef(sd.getBaseDefinition().replace("http://hl7.org/fhir/StructureDefinition/", "")));
}
return r;
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project kindling by HL7.
the class ResourceParser method parseED.
private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
ed.setMinCardinality(focus.getMin());
ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
ed.setIsModifier(focus.getIsModifier());
ed.setModifierReason(focus.getIsModifierReason());
ed.setMustSupport(focus.getMustSupport());
ed.setSummaryItem(focus.getIsSummary());
ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
}
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
if (svg.contains("w=")) {
ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
svg = svg.substring(0, svg.indexOf(";"));
}
ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
}
ed.setName(tail(focus.getPath()));
ed.setShortDefn(focus.getShort());
ed.setDefinition(focus.getDefinition());
ed.setRequirements(focus.getRequirements());
ed.setComments(focus.getComment());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
}
if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
}
for (StringType t : focus.getAlias()) {
ed.getAliases().add(t.getValue());
}
if (focus.hasMaxLength()) {
ed.setMaxLength(Integer.toString(focus.getMaxLength()));
}
ed.setExample(focus.getExampleFirstRep().getValue());
ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
}
ed.setOrderMeaning(focus.getOrderMeaning());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
}
for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
Invariant inv = new Invariant();
inv.setContext(focus.getPath());
inv.setEnglish(cst.getHuman());
if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
}
inv.setXpath(cst.getXpath());
inv.setId(cst.getKey());
if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
}
inv.setSeverity(cst.getSeverity().toCode());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
inv.setSeverity("best-practice");
}
if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
}
inv.setRequirements(cst.getRequirements());
inv.setExpression(cst.getExpression());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
}
ed.getInvariants().put(inv.getId(), inv);
invariants.put(inv.getId(), inv);
}
for (IdType cnd : focus.getCondition()) {
Invariant inv = invariants.get(cnd.primitiveValue());
if (inv == null) {
System.out.println("Unable to find invariant " + cnd.primitiveValue());
} else {
ed.getStatedInvariants().add(inv);
}
}
for (ElementDefinitionMappingComponent map : focus.getMapping()) {
String uri = getMappingUri(sd, map.getIdentity());
if ("http://hl7.org/fhir/fivews".equals(uri)) {
ed.setW5(reverseW5(map.getMap()));
} else {
ed.getMappings().put(uri, map.getMap());
}
}
if (focus.hasContentReference()) {
ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
} else {
for (TypeRefComponent tr : focus.getType()) {
if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
TypeRef t = new TypeRef();
ed.getTypes().add(t);
if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
} else {
t.setName(tr.getCode());
}
if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
}
for (CanonicalType u : tr.getProfile()) {
t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
}
for (CanonicalType u : tr.getTargetProfile()) {
String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
if ("Resource".equals(s)) {
t.getParams().add("Any");
} else {
t.getParams().add(s);
}
}
if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
t.setName("SimpleQuantity");
t.setProfile(null);
}
if ("Resource".equals(t.getProfile())) {
t.setProfile("Any");
}
if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
t.getParams().clear();
t.getParams().add("Definition");
}
}
}
if (ed.getTypes().size() == STAR_TYPES_COUNT) {
ed.getTypes().clear();
ed.getTypes().add(new TypeRef("*"));
}
}
String name = parentName + Utilities.capitalize(ed.getName());
if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
ed.setDeclaredTypeName(ed.getStatedType());
} else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
ed.setDeclaredTypeName(name + "Component");
}
if (focus.hasBinding()) {
ed.setBinding(parseBinding(focus.getBinding()));
}
for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
ElementDefn c = new ElementDefn();
ed.getElements().add(c);
parseED(pu, c, child, sd, name);
}
// todo:
// private ElementDefinition derivation;
}
Aggregations