Search in sources :

Example 61 with CodeType

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");
}
Also used : IElement(ca.uhn.fhir.model.api.IElement) Element(org.hl7.fhir.r4.elementmodel.Element) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 62 with CodeType

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;
    }
}
Also used : Resource(org.hl7.fhir.r4.model.Resource) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r4.model.Base) UriType(org.hl7.fhir.r4.model.UriType) StructureMap(org.hl7.fhir.r4.model.StructureMap) Coding(org.hl7.fhir.r4.model.Coding) TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) CodeType(org.hl7.fhir.r4.model.CodeType) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)

Example 63 with CodeType

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;
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) OperationDefinitionParameterComponent(org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 64 with CodeType

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));
}
Also used : CodeType(org.hl7.fhir.r4b.model.CodeType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 65 with CodeType

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());
}
Also used : CodeType(org.hl7.fhir.r4b.model.CodeType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CodeType (org.hl7.fhir.r5.model.CodeType)52 ArrayList (java.util.ArrayList)31 CodeType (org.hl7.fhir.r4.model.CodeType)28 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 CodeType (org.hl7.fhir.r4b.model.CodeType)17 Date (java.util.Date)15 CodeType (org.hl7.fhir.dstu3.model.CodeType)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 File (java.io.File)11 Extension (org.hl7.fhir.dstu3.model.Extension)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)10 StringType (org.hl7.fhir.r5.model.StringType)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 Coding (org.hl7.fhir.r4.model.Coding)9 Coding (org.hl7.fhir.dstu3.model.Coding)8 FileOutputStream (java.io.FileOutputStream)7 List (java.util.List)7 Parameters (org.hl7.fhir.r4.model.Parameters)7 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)7