use of org.hl7.fhir.r4.model.CodeType in project org.hl7.fhir.core by hapifhir.
the class Base method castToCodeableConcept.
public CodeableConcept castToCodeableConcept(Base b) throws FHIRException {
if (b instanceof CodeableConcept)
return (CodeableConcept) b;
else if (b instanceof Element) {
return ObjectConverter.readAsCodeableConcept((Element) b);
} else if (b instanceof CodeType) {
CodeableConcept cc = new CodeableConcept();
cc.addCoding().setCode(((CodeType) b).asStringValue());
return cc;
} else
throw new FHIRException("Unable to convert a " + b.getClass().getName() + " to a CodeableConcept");
}
use of org.hl7.fhir.r4.model.CodeType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method translate.
public Base translate(TransformContext context, StructureMap map, Base source, String conceptMapUrl, String fieldToReturn) throws FHIRException {
Coding src = new Coding();
if (source.isPrimitive()) {
src.setCode(source.primitiveValue());
} else if ("Coding".equals(source.fhirType())) {
Base[] b = source.getProperty("system".hashCode(), "system", true);
if (b.length == 1)
src.setSystem(b[0].primitiveValue());
b = source.getProperty("code".hashCode(), "code", true);
if (b.length == 1)
src.setCode(b[0].primitiveValue());
} else if ("CE".equals(source.fhirType())) {
Base[] b = source.getProperty("codeSystem".hashCode(), "codeSystem", true);
if (b.length == 1)
src.setSystem(b[0].primitiveValue());
b = source.getProperty("code".hashCode(), "code", true);
if (b.length == 1)
src.setCode(b[0].primitiveValue());
} else
throw new FHIRException("Unable to translate source " + source.fhirType());
String su = conceptMapUrl;
if (conceptMapUrl.equals("http://hl7.org/fhir/ConceptMap/special-oid2uri")) {
String uri = worker.oid2Uri(src.getCode());
if (uri == null)
uri = "urn:oid:" + src.getCode();
if ("uri".equals(fieldToReturn))
return new UriType(uri);
else
throw new FHIRException("Error in return code");
} else {
ConceptMap cmap = null;
if (conceptMapUrl.startsWith("#")) {
for (Resource r : map.getContained()) {
if (r instanceof ConceptMap && ((ConceptMap) r).getId().equals(conceptMapUrl.substring(1))) {
cmap = (ConceptMap) r;
su = map.getUrl() + "#" + conceptMapUrl;
}
}
if (cmap == null)
throw new FHIRException("Unable to translate - cannot find map " + conceptMapUrl);
} else {
if (conceptMapUrl.contains("#")) {
String[] p = conceptMapUrl.split("\\#");
StructureMap mapU = worker.fetchResource(StructureMap.class, p[0]);
for (Resource r : mapU.getContained()) {
if (r instanceof ConceptMap && ((ConceptMap) r).getId().equals(p[1])) {
cmap = (ConceptMap) r;
su = conceptMapUrl;
}
}
}
if (cmap == null)
cmap = worker.fetchResource(ConceptMap.class, conceptMapUrl);
}
Coding outcome = null;
boolean done = false;
String message = null;
if (cmap == null) {
if (services == null)
message = "No map found for " + conceptMapUrl;
else {
outcome = services.translate(context.appInfo, src, conceptMapUrl);
done = true;
}
} else {
List<SourceElementComponentWrapper> list = new ArrayList<SourceElementComponentWrapper>();
for (ConceptMapGroupComponent g : cmap.getGroup()) {
for (SourceElementComponent e : g.getElement()) {
if (!src.hasSystem() && src.getCode().equals(e.getCode()))
list.add(new SourceElementComponentWrapper(g, e));
else if (src.hasSystem() && src.getSystem().equals(g.getSource()) && src.getCode().equals(e.getCode()))
list.add(new SourceElementComponentWrapper(g, e));
}
}
if (list.size() == 0)
done = true;
else if (list.get(0).comp.getTarget().size() == 0)
message = "Concept map " + su + " found no translation for " + src.getCode();
else {
for (TargetElementComponent tgt : list.get(0).comp.getTarget()) {
if (tgt.getEquivalence() == null || EnumSet.of(ConceptMapEquivalence.EQUAL, ConceptMapEquivalence.RELATEDTO, ConceptMapEquivalence.EQUIVALENT, ConceptMapEquivalence.WIDER).contains(tgt.getEquivalence())) {
if (done) {
message = "Concept map " + su + " found multiple matches for " + src.getCode();
done = false;
} else {
done = true;
outcome = new Coding().setCode(tgt.getCode()).setSystem(list.get(0).group.getTarget());
}
} else if (tgt.getEquivalence() == ConceptMapEquivalence.UNMATCHED) {
done = true;
}
}
if (!done)
message = "Concept map " + su + " found no usable translation for " + src.getCode();
}
}
if (!done)
throw new FHIRException(message);
if (outcome == null)
return null;
if ("code".equals(fieldToReturn))
return new CodeType(outcome.getCode());
else
return outcome;
}
}
use of org.hl7.fhir.r4.model.CodeType in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generate.
public boolean generate(ResourceContext rcontext, OperationDefinition opd) throws EOperationOutcome, FHIRException, IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.h2().addText(opd.getName());
x.para().addText(Utilities.capitalize(opd.getKind().toString()) + ": " + opd.getName());
x.para().tx("The official URL for this operation definition is: ");
x.pre().tx(opd.getUrl());
addMarkdown(x, opd.getDescription());
if (opd.getSystem())
x.para().tx("URL: [base]/$" + opd.getCode());
for (CodeType c : opd.getResource()) {
if (opd.getType())
x.para().tx("URL: [base]/" + c.getValue() + "/$" + opd.getCode());
if (opd.getInstance())
x.para().tx("URL: [base]/" + c.getValue() + "/[id]/$" + opd.getCode());
}
x.para().tx("Parameters");
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Use");
tr.td().b().tx("Name");
tr.td().b().tx("Cardinality");
tr.td().b().tx("Type");
tr.td().b().tx("Binding");
tr.td().b().tx("Documentation");
for (OperationDefinitionParameterComponent p : opd.getParameter()) {
genOpParam(rcontext, tbl, "", p);
}
addMarkdown(x, opd.getComment());
inject(opd, x, NarrativeStatus.GENERATED);
return true;
}
use of org.hl7.fhir.r4.model.CodeType in project org.hl7.fhir.core by hapifhir.
the class CodeTypeNullTest method equalsDeep.
@Test
@DisplayName("Test null value equalsDeep()")
void equalsDeep() {
CodeType nullCode = new CodeType();
CodeType validCode = new CodeType("theValue");
Assertions.assertFalse(nullCode.equalsDeep(validCode));
}
use of org.hl7.fhir.r4.model.CodeType in project org.hl7.fhir.core by hapifhir.
the class CodeTypeNullTest method typedCopy.
@Test
@DisplayName("Test null value typedCopy()")
void typedCopy() {
CodeType nullCode = new CodeType();
CodeType copyCode = (CodeType) nullCode.typedCopy();
Assertions.assertNull(copyCode.getValue());
}
Aggregations