use of org.hl7.v3.CD in project kindling by HL7.
the class CodeListToValueSetParser method processV2Map.
private void processV2Map(ConceptMap cm, String url, String code, String v2map) throws Exception {
if (Utilities.noString(v2map))
return;
for (String m : v2map.split(",")) {
// analyse m
String[] n = m.split("\\(");
String comm = (n.length > 1) ? n[1].substring(0, n[1].length() - 1) : null;
n = n[0].split("\\.");
if (n.length != 2)
throw new Exception("Error processing v2 map value for " + cm.getName() + "." + code + " '" + m + "' - format should be CodeSystem.code (comment) - the comment bit is optional");
String rel = n[0].substring(0, 1);
String tbl = n[0].substring(1);
String cd = n[1];
ConceptMapGroupComponent grp = getGroup(cm, url, "http://terminology.hl7.org/CodeSystem/v2-" + tbl);
SourceElementComponent src = getSource(grp, code);
TargetElementComponent tgt = src.addTarget();
tgt.setCode(cd.trim());
tgt.setComment(comm);
if (rel.equals("="))
tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
else if (rel.equals("~"))
tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
else if (rel.equals(">"))
tgt.setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
else if (rel.equals("<")) {
tgt.setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
if (!tgt.hasComment())
throw new Exception("Missing comment for narrower match on " + cm.getName() + "/" + code);
} else
throw new Exception("Unable to understand relationship character " + rel);
}
}
use of org.hl7.v3.CD in project kindling by HL7.
the class BindingsParser method processLine.
private void processLine(List<BindingSpecification> results, Sheet sheet, int row) throws Exception {
BindingSpecification cd = new BindingSpecification("core", sheet.getColumn(row, "Binding Name"), true);
if (!cd.getName().startsWith("!")) {
if (Character.isLowerCase(cd.getName().charAt(0)))
throw new Exception("binding name " + cd.getName() + " is illegal - must start with a capital letter");
cd.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
cd.setBindingMethod(readBinding(sheet.getColumn(row, "Binding"), cd.getName() + " in " + filename));
boolean utg = "y".equals(sheet.getColumn(row, "UTG"));
String ref = sheet.getColumn(row, "Reference");
if (!cd.getBinding().equals(BindingMethod.Unbound) && Utilities.noString(ref))
throw new Exception("binding " + cd.getName() + " is missing a reference");
if (cd.getBinding() == BindingMethod.CodeList) {
cd.setValueSet(new ValueSet());
cd.getValueSet().setId(ref.substring(1));
cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(1));
cd.getValueSet().setVersion(version);
if (!Utilities.noString(sheet.getColumn(row, "Committee"))) {
cd.getValueSet().addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(sheet.getColumn(row, "Committee").toLowerCase()));
}
cd.getValueSet().setUserData("filename", "valueset-" + cd.getValueSet().getId());
cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
cd.getValueSet().setName(cd.getName());
cd.getValueSet().setTitle(cd.getName());
cd.getValueSet().setDateElement(new DateTimeType(genDate));
cd.getValueSet().setStatus(PublicationStatus.DRAFT);
cd.getValueSet().setDescription(sheet.getColumn(row, "Description"));
if (!cd.getValueSet().hasDescription())
cd.getValueSet().setDescription(cd.getDefinition());
if (!ref.startsWith("#"))
throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' must started with '#'");
Sheet cs = xls.getSheets().get(ref.substring(1));
if (cs == null)
throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' not resolved");
new CodeListToValueSetParser(cs, ref.substring(1), cd.getValueSet(), version, codeSystems, maps, packageInfo).execute(sheet.getColumn(row, "v2"), sheet.getColumn(row, "v3"), utg);
} else if (cd.getBinding() == BindingMethod.ValueSet) {
if (ref.startsWith("http:")) {
// will sort this out later
cd.setReference(sheet.getColumn(row, "Reference"));
} else
cd.setValueSet(loadValueSet(ref, sheet.getColumn(row, "Committee").toLowerCase()));
String max = sheet.getColumn(row, "Max");
if (!Utilities.noString(max))
if (max.startsWith("http:")) {
// will sort this out later
cd.setMaxReference(max);
} else
cd.setMaxValueSet(loadValueSet(max, sheet.getColumn(row, "Committee").toLowerCase()));
} else if (cd.getBinding() == BindingMethod.Special) {
cd.setValueSet(new ValueSet());
cd.getValueSet().setId(ref.substring(1));
cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(1));
cd.getValueSet().setVersion(version);
cd.getValueSet().setName(cd.getName());
// do nothing more: this will get filled out once all the resources are loaded
}
// do this anyway in the short term
cd.setReference(sheet.getColumn(row, "Reference"));
if (cd.getValueSet() != null) {
touchVS(cd.getValueSet());
ValueSetUtilities.markStatus(cd.getValueSet(), Utilities.noString(sheet.getColumn(row, "Committee")) ? "vocab" : sheet.getColumn(row, "Committee").toLowerCase(), null, null, Utilities.noString(sheet.getColumn(row, "FMM")) ? null : sheet.getColumn(row, "FMM"), null, Utilities.noString(sheet.getColumn(row, "Normative-Version")) ? null : sheet.getColumn(row, "Normative-Version"));
}
if (cd.getMaxValueSet() != null) {
touchVS(cd.getMaxValueSet());
ValueSetUtilities.markStatus(cd.getMaxValueSet(), Utilities.noString(sheet.getColumn(row, "Committee")) ? "vocab" : sheet.getColumn(row, "Committee").toLowerCase(), null, null, Utilities.noString(sheet.getColumn(row, "FMM")) ? null : sheet.getColumn(row, "FMM"), null, Utilities.noString(sheet.getColumn(row, "Max-Normative-Version")) ? null : sheet.getColumn(row, "Max-Normative-Version"));
}
cd.setDescription(sheet.getColumn(row, "Description"));
cd.setSource(filename);
cd.setUri(sheet.getColumn(row, "Uri"));
cd.setStrength(readBindingStrength(sheet.getColumn(row, "Conformance")));
String oid = sheet.getColumn(row, "Oid");
if (!Utilities.noString(oid))
// no cs oid in this case
cd.setVsOid(oid);
cd.setWebSite(sheet.getColumn(row, "Website"));
cd.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
cd.setEmail(sheet.getColumn(row, "Email"));
cd.setV2Map(sheet.getColumn(row, "v2"));
cd.setV3Map(sheet.getColumn(row, "v3"));
if (cd.getBinding() == BindingMethod.Unbound) {
cd.setStrength(BindingStrength.EXAMPLE);
}
results.add(cd);
}
}
use of org.hl7.v3.CD in project kindling by HL7.
the class Publisher method addToResourceFeed.
private void addToResourceFeed(CompartmentDefinition cd, Bundle dest) throws Exception {
if (cd.getId() == null)
throw new Exception("Resource has no id");
if (ResourceUtilities.getById(dest, ResourceType.CompartmentDefinition, cd.getId()) != null)
throw new Exception("Attempt to add duplicate Compartment Definition " + cd.getId());
if (!cd.hasText() || !cd.getText().hasDiv()) {
RendererFactory.factory(cd, page.getRc().copy()).render(cd);
}
if (cd.getText() == null || cd.getText().getDiv() == null)
throw new Exception("Example Compartment Definition " + cd.getId() + " does not have any narrative");
ResourceUtilities.meta(cd).setLastUpdated(page.getGenDate().getTime());
if (!cd.getUrl().equals("http://hl7.org/fhir/" + cd.getResourceType().toString() + "/" + cd.getId()))
throw new Exception("URL mismatch on concept map");
dest.getEntry().add(new BundleEntryComponent().setResource(cd).setFullUrl("http://hl7.org/fhir/" + cd.fhirType() + "/" + cd.getId()));
}
use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.
the class CodeSystemRenderer method addDefineRowToTable.
private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int level, boolean hasHierarchy, boolean hasDisplay, boolean hasDefinitions, boolean comment, boolean version, boolean deprecated, List<UsedConceptMap> maps, String system, CodeSystem cs, List<PropertyComponent> properties, CodeSystemNavigator csNav, List<String> langs, boolean isSupplement) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
if (hasHierarchy) {
td.addText(Integer.toString(level + 1));
td = tr.td();
String s = Utilities.padLeft("", '\u00A0', level * 2);
td.addText(s);
}
String link = isSupplement ? getLinkForCode(cs.getSupplements(), null, c.getCode()) : null;
if (link != null) {
td.ah(link).attribute("style", "white-space:nowrap").addText(c.getCode());
} else {
td.attribute("style", "white-space:nowrap").addText(c.getCode());
}
XhtmlNode a;
if (c.hasCodeElement()) {
td.an(cs.getId() + "-" + Utilities.nmtokenize(c.getCode()));
}
for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) {
if (cd.hasLanguage() && !langs.contains(cd.getLanguage()) && (!cs.hasLanguage() || !cs.getLanguage().equals(cd.getLanguage()))) {
langs.add(cd.getLanguage());
}
}
if (hasDisplay) {
td = tr.td();
renderDisplayName(c, cs, td);
}
if (hasDefinitions) {
td = tr.td();
if (c != null && c.hasDefinitionElement()) {
if (getContext().getLang() == null) {
if (hasMarkdownInDefinitions(cs))
addMarkdown(td, c.getDefinition());
else
td.addText(c.getDefinition());
} else if (getContext().getLang().equals("*")) {
boolean sl = false;
for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) if (cd.getUse().is("http://terminology.hl7.org/CodeSystem/designation-usage", "definition") && cd.hasLanguage() && !c.getDefinition().equalsIgnoreCase(cd.getValue()))
sl = true;
td.addText((sl ? cs.getLanguage("en") + ": " : "") + c.getDefinition());
for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) {
if (cd.getUse().is("http://terminology.hl7.org/CodeSystem/designation-usage", "definition") && cd.hasLanguage() && !c.getDefinition().equalsIgnoreCase(cd.getValue())) {
td.br();
td.addText(cd.getLanguage() + ": " + cd.getValue());
}
}
} else if (getContext().getLang().equals(cs.getLanguage()) || (getContext().getLang().equals("en") && !cs.hasLanguage())) {
td.addText(c.getDefinition());
} else {
for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) {
if (cd.getUse().is("http://terminology.hl7.org/CodeSystem/designation-usage", "definition") && cd.hasLanguage() && cd.getLanguage().equals(getContext().getLang())) {
td.addText(cd.getValue());
}
}
}
}
}
if (deprecated) {
td = tr.td();
Boolean b = CodeSystemUtilities.isDeprecated(cs, c, false);
if (b != null && b) {
smartAddText(td, getContext().getWorker().translator().translate("xhtml-gen-cs", "Deprecated", getContext().getLang()));
hasExtensions = true;
if (ToolingExtensions.hasExtension(c, ToolingExtensions.EXT_REPLACED_BY)) {
Coding cc = (Coding) ToolingExtensions.getExtension(c, ToolingExtensions.EXT_REPLACED_BY).getValue();
td.tx(" (replaced by ");
String url = getCodingReference(cc, system);
if (url != null) {
td.ah(url).addText(cc.getCode());
td.tx(": " + cc.getDisplay() + ")");
} else
td.addText(cc.getCode() + " '" + cc.getDisplay() + "' in " + cc.getSystem() + ")");
}
}
}
if (comment) {
td = tr.td();
Extension ext = c.getExtensionByUrl(ToolingExtensions.EXT_CS_COMMENT);
if (ext != null) {
hasExtensions = true;
String bc = ext.hasValue() ? ext.getValue().primitiveValue() : null;
Map<String, String> translations = ToolingExtensions.getLanguageTranslations(ext.getValue());
if (getContext().getLang() == null) {
if (bc != null)
td.addText(bc);
} else if (getContext().getLang().equals("*")) {
boolean sl = false;
for (String l : translations.keySet()) if (bc == null || !bc.equalsIgnoreCase(translations.get(l)))
sl = true;
if (bc != null) {
td.addText((sl ? cs.getLanguage("en") + ": " : "") + bc);
}
for (String l : translations.keySet()) {
if (bc == null || !bc.equalsIgnoreCase(translations.get(l))) {
if (!td.getChildNodes().isEmpty())
td.br();
td.addText(l + ": " + translations.get(l));
}
}
} else if (getContext().getLang().equals(cs.getLanguage()) || (getContext().getLang().equals("en") && !cs.hasLanguage())) {
if (bc != null)
td.addText(bc);
} else {
if (bc != null)
translations.put(cs.getLanguage("en"), bc);
for (String l : translations.keySet()) {
if (l.equals(getContext().getLang())) {
td.addText(translations.get(l));
}
}
}
}
}
if (version) {
td = tr.td();
if (c.hasUserData("cs.version.notes"))
td.addText(c.getUserString("cs.version.notes"));
}
if (properties != null) {
for (PropertyComponent pc : properties) {
td = tr.td();
boolean first = true;
List<ConceptPropertyComponent> pcvl = CodeSystemUtilities.getPropertyValues(c, pc.getCode());
for (ConceptPropertyComponent pcv : pcvl) {
if (pcv.hasValue()) {
if (first)
first = false;
else
td.addText(", ");
if (pcv.hasValueCoding()) {
td.addText(pcv.getValueCoding().getCode());
} else if (pcv.hasValueStringType() && Utilities.isAbsoluteUrlLinkable(pcv.getValue().primitiveValue())) {
td.ah(pcv.getValue().primitiveValue()).tx(pcv.getValue().primitiveValue());
} else {
td.addText(pcv.getValue().primitiveValue());
}
}
}
}
}
for (UsedConceptMap m : maps) {
td = tr.td();
List<TargetElementComponentWrapper> mappings = findMappingsForCode(c.getCode(), m.getMap());
boolean first = true;
for (TargetElementComponentWrapper mapping : mappings) {
if (!first)
td.br();
first = false;
XhtmlNode span = td.span(null, mapping.comp.hasEquivalence() ? mapping.comp.getEquivalence().toCode() : "");
span.addText(getCharForRelationship(mapping.comp));
a = td.ah(getContext().getSpecificationLink() + m.getLink() + "#" + makeAnchor(mapping.group.getTarget(), mapping.comp.getCode()));
a.addText(mapping.comp.getCode());
if (!Utilities.noString(mapping.comp.getComment()))
td.i().tx("(" + mapping.comp.getComment() + ")");
}
}
List<ConceptDefinitionComponent> ocl = csNav.getOtherChildren(c);
for (ConceptDefinitionComponent cc : csNav.getConcepts(c)) {
hasExtensions = addDefineRowToTable(t, cc, level + 1, hasHierarchy, hasDisplay, hasDefinitions, comment, version, deprecated, maps, system, cs, properties, csNav, langs, isSupplement) || hasExtensions;
}
for (ConceptDefinitionComponent cc : ocl) {
tr = t.tr();
td = tr.td();
td.addText(Integer.toString(level + 2));
td = tr.td();
String s = Utilities.padLeft("", '\u00A0', (level + 1) * 2);
td.addText(s);
td.attribute("style", "white-space:nowrap");
a = td.ah("#" + cs.getId() + "-" + Utilities.nmtokenize(cc.getCode()));
a.addText(cc.getCode());
if (hasDisplay) {
td = tr.td();
renderDisplayName(cc, cs, td);
}
int w = 1 + (deprecated ? 1 : 0) + (comment ? 1 : 0) + (version ? 1 : 0) + maps.size();
if (properties != null) {
w = w + properties.size();
}
td = tr.td().colspan(Integer.toString(w));
}
return hasExtensions;
}
use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.
the class OpenApiGenerator method generate.
public void generate(String license, String url) {
dest.info().title(source.present()).description(source.getDescription()).license(license, url).version(source.getVersion());
for (ContactDetail cd : source.getContact()) {
dest.info().contact(cd.getName(), email(cd.getTelecom()), url(cd.getTelecom()));
}
if (source.hasPublisher())
dest.info().contact(source.getPublisher(), null, null);
if (source.hasImplementation()) {
dest.server(source.getImplementation().getUrl()).description(source.getImplementation().getDescription());
}
dest.externalDocs().url(source.getUrl()).description("FHIR CapabilityStatement");
for (CapabilityStatementRestComponent csr : source.getRest()) {
if (csr.getMode() == org.hl7.fhir.r4b.model.CapabilityStatement.RestfulCapabilityMode.SERVER) {
generatePaths(csr);
}
}
writeBaseParameters(dest.components());
}
Aggregations