use of org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class NUCCConvertor method processLine.
private void processLine(CodeSystem cs, String[] values) throws FHIRFormatError {
ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
cs.getConcept().add(cc);
cc.setCode(values[0]);
cc.setDisplay(values[4]);
if (!Utilities.noString(values[1])) {
cc.addProperty().setCode("grouping").setValue(new StringType(values[1]));
}
if (!Utilities.noString(values[2])) {
cc.addProperty().setCode("classification").setValue(new StringType(values[2]));
}
if (!Utilities.noString(values[3])) {
cc.addProperty().setCode("specialization").setValue(new StringType(values[3]));
}
if (values.length > 5 && !Utilities.noString(values[5]))
cc.setDefinition(values[5]);
}
use of org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class CountryCodesConverter method execute.
private void execute() throws ParserConfigurationException, SAXException, IOException {
Document src = load();
CodeSystem cs1 = new CodeSystem();
CodeSystem cs2 = new CodeSystem();
CodeSystem cs3 = new CodeSystem();
setMetadata(src, cs1, "iso3166", "urn:iso:std:iso:3166", "", "");
setMetadata(src, cs2, "iso3166-2", "urn:iso:std:iso:3166:-2", "Part2", " Part 2");
cs1.addProperty().setCode("canonical").setDescription("The 2 letter code that identifies the same country (so 2/3/numeric codes can be aligned)").setType(PropertyType.CODE);
cs2.addProperty().setCode("country").setDescription("The 2 letter code that identifies the country for the subdivision").setType(PropertyType.CODE);
for (Element e : XMLUtil.getNamedChildren(src.getDocumentElement(), "country")) {
System.out.println(e.getAttribute("id"));
String c2 = XMLUtil.getNamedChildText(e, "alpha-2-code");
String c3 = XMLUtil.getNamedChildText(e, "alpha-3-code");
String cN = XMLUtil.getNamedChildText(e, "numeric-code");
Element n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
if (n == null)
continue;
String name = n.getTextContent();
n = XMLUtil.getNamedChildByAttribute(e, "full-name", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "full-name-upper-case", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
String desc = n.getTextContent();
ConceptDefinitionComponent cc = cs1.addConcept();
cc.setCode(c2);
cc.setDisplay(name);
cc.setDefinition(desc);
poplang(e, cc);
if (c3 != null) {
cc = cs1.addConcept();
cc.setCode(c3);
cc.setDisplay(name);
cc.setDefinition(desc);
cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
poplang(e, cc);
}
if (cN != null) {
cc = cs1.addConcept();
cc.setCode(cN);
cc.setDisplay(name);
cc.setDefinition(desc);
cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
poplang(e, cc);
}
for (Element sd : XMLUtil.getNamedChildren(e, "subdivision")) {
cc = cs2.addConcept();
cc.setCode(XMLUtil.getNamedChildText(sd, "subdivision-code"));
Element l = XMLUtil.getNamedChild(sd, "subdivision-locale");
cc.setDisplay(XMLUtil.getNamedChildText(l, "subdivision-locale-name"));
cc.addProperty().setCode("country").setValue(new CodeType(c2));
}
}
cs1.setCount(cs1.getConcept().size());
cs2.setCount(cs2.getConcept().size());
throw new Error("Needs revisiting");
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166.json")), cs1);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166.json")), cs1); // format hasn't changed
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166-2.json")), cs2);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166-2.json")), cs2); // format hasn't changed
}
use of org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method addDefineRowToTable.
private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int i, boolean hasHierarchy, boolean hasDisplay, boolean comment, boolean deprecated, Map<ConceptMap, String> maps, String system) {
boolean hasExtensions = false;
XhtmlNode tr = t.addTag("tr");
XhtmlNode td = tr.addTag("td");
if (hasHierarchy) {
td.addText(Integer.toString(i + 1));
td = tr.addTag("td");
String s = Utilities.padLeft("", '\u00A0', i * 2);
td.addText(s);
}
td.addText(c.getCode());
XhtmlNode a;
if (c.hasCodeElement()) {
a = td.addTag("a");
a.setAttribute("name", Utilities.nmtokenize(c.getCode()));
a.addText(" ");
}
if (hasDisplay) {
td = tr.addTag("td");
if (c.hasDisplayElement())
td.addText(c.getDisplay());
}
td = tr.addTag("td");
if (c != null)
smartAddText(td, c.getDefinition());
if (deprecated) {
td = tr.addTag("td");
Boolean b = ToolingExtensions.getDeprecated(c);
if (b != null && b) {
smartAddText(td, "Deprecated");
hasExtensions = true;
if (ToolingExtensions.hasExtension(c, ToolingExtensions.EXT_REPLACED_BY)) {
Coding cc = (Coding) ToolingExtensions.getExtension(c, ToolingExtensions.EXT_REPLACED_BY).getValue();
td.addText(" (replaced by ");
String url = getCodingReference(cc, system);
if (url != null) {
td.addTag("a").setAttribute("href", url).addText(cc.getCode());
td.addText(": " + cc.getDisplay() + ")");
} else
td.addText(cc.getCode() + " '" + cc.getDisplay() + "' in " + cc.getSystem() + ")");
}
}
}
if (comment) {
td = tr.addTag("td");
String s = ToolingExtensions.getComment(c);
if (s != null) {
smartAddText(td, s);
hasExtensions = true;
}
}
for (ConceptMap m : maps.keySet()) {
td = tr.addTag("td");
List<TargetElementComponent> mappings = findMappingsForCode(c.getCode(), m);
boolean first = true;
for (TargetElementComponent mapping : mappings) {
if (!first)
td.addTag("br");
first = false;
XhtmlNode span = td.addTag("span");
span.setAttribute("title", mapping.hasEquivalence() ? mapping.getEquivalence().toCode() : "");
span.addText(getCharForEquivalence(mapping));
a = td.addTag("a");
a.setAttribute("href", prefix + maps.get(m) + "#" + makeAnchor(mapping.getCodeSystem(), mapping.getCode()));
a.addText(mapping.getCode());
if (!Utilities.noString(mapping.getComments()))
td.addTag("i").addText("(" + mapping.getComments() + ")");
}
}
for (CodeType e : ToolingExtensions.getSubsumes(c)) {
hasExtensions = true;
tr = t.addTag("tr");
td = tr.addTag("td");
String s = Utilities.padLeft("", '.', i * 2);
td.addText(s);
a = td.addTag("a");
a.setAttribute("href", "#" + Utilities.nmtokenize(e.getValue()));
a.addText(c.getCode());
}
for (ConceptDefinitionComponent cc : c.getConcept()) {
hasExtensions = addDefineRowToTable(t, cc, i + 1, hasHierarchy, hasDisplay, comment, deprecated, maps, system) || hasExtensions;
}
return hasExtensions;
}
use of org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method includeCodes.
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
if (context.supportsSystem(inc.getSystem())) {
addCodes(context.expandVS(inc), params);
return;
}
ValueSet cs = context.fetchCodeSystem(inc.getSystem());
if (cs == null)
throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
if (cs.hasVersion())
if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
// special case - add all the code system
for (ConceptDefinitionComponent def : cs.getCodeSystem().getConcept()) {
addCodeAndDescendents(inc.getSystem(), def);
}
}
for (ConceptReferenceComponent c : inc.getConcept()) {
addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
}
if (inc.getFilter().size() > 1)
// need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
throw new TerminologyServiceException("Multiple filters not handled yet");
if (inc.getFilter().size() == 1) {
ConceptSetFilterComponent fc = inc.getFilter().get(0);
if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
// special: all non-abstract codes in the target code system under the value
ConceptDefinitionComponent def = getConceptForCode(cs.getCodeSystem().getConcept(), fc.getValue());
if (def == null)
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
addCodeAndDescendents(inc.getSystem(), def);
} else
throw new NotImplementedException("not done yet");
}
}
use of org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method includeCodes.
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
if (context.supportsSystem(inc.getSystem())) {
try {
int i = codes.size();
addCodes(context.expandVS(inc), params);
if (codes.size() > i)
return;
} catch (Exception e) {
// ok, we'll try locally
}
}
CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
if (cs == null)
throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
if (cs.hasVersion())
if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
// special case - add all the code system
for (ConceptDefinitionComponent def : cs.getConcept()) {
addCodeAndDescendents(cs, inc.getSystem(), def);
}
}
for (ConceptReferenceComponent c : inc.getConcept()) {
addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
}
if (inc.getFilter().size() > 1)
// need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
throw new TerminologyServiceException("Multiple filters not handled yet");
if (inc.getFilter().size() == 1) {
ConceptSetFilterComponent fc = inc.getFilter().get(0);
if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
// special: all non-abstract codes in the target code system under the value
ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
if (def == null)
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
addCodeAndDescendents(cs, inc.getSystem(), def);
} else
throw new NotImplementedException("not done yet");
}
}
Aggregations