Search in sources :

Example 36 with CodeableReference

use of org.hl7.fhir.r5.model.CodeableReference in project kindling by HL7.

the class ExampleAdorner method getState.

@Override
public XhtmlGeneratorAdornerState getState(XhtmlGenerator ref, XhtmlGeneratorAdornerState state, Element node) throws Exception {
    if (state == null) {
        if (node == null)
            return new ExampleAdornerState(State.Unknown, "", null, "", "");
        else if (definitions.hasResource(node.getLocalName()))
            return new ExampleAdornerState(State.Element, node.getLocalName(), definitions.getResourceByName(node.getLocalName()).getRoot(), "", "");
        else
            return new ExampleAdornerState(State.Unknown, "", null, "", "");
    } else {
        ExampleAdornerState s = (ExampleAdornerState) state;
        if (s.getState() == State.Element) {
            if (s.definition == null) {
                System.out.println("??");
            }
            if (// account for extra element
            s.definition != null && "Resource".equals(s.definition.typeCode()) && (s.getPath().endsWith(".entry.resource") || s.getPath().endsWith(".contained")) && definitions.isResource(node.getNodeName()))
                return new ExampleAdornerState(State.Element, s.getPath(), definitions.getResourceByName(node.getNodeName()).getRoot(), "", "");
            String p = s.getPath() + "." + node.getNodeName();
            ElementDefn e = s.getDefinition().getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
            if (e == null && definitions.hasElementDefn(s.getDefinition().typeCodeNoParams())) {
                // well, we see if it's inherited...
                ElementDefn t = definitions.getElementDefn(s.getDefinition().typeCodeNoParams());
                while (t != null && e == null) {
                    e = t.getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
                    if (e != null)
                        p = t.getName() + "." + e.getName();
                    else if (definitions.hasElementDefn(t.typeCodeNoParams()))
                        t = definitions.getElementDefn(t.typeCodeNoParams());
                    else
                        t = null;
                }
            } else if (e != null)
                p = s.getPath() + "." + e.getName();
            if (e == null)
                return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
            if (!e.isBaseResourceElement() && e.typeCode().contains("Reference") && !e.typeCode().contains("CodeableReference"))
                return new ExampleAdornerState(State.Reference, p, e, "", "");
            else if (!e.isBaseResourceElement() && e.typeCode().contains("canonical"))
                return new ExampleAdornerState(State.Reference, p, e, "", "");
            else if (!e.isBaseResourceElement() && e.typeCode().equals("uri"))
                return new ExampleAdornerState(State.Reference, p, e, "", "");
            else
                return new ExampleAdornerState(State.Element, p, e, "", "");
        } else if (s.getState() == State.Reference) {
            if (node.getLocalName().equals("reference")) {
                String type = extractType(node.getAttribute("value"));
                String id = extractId(node.getAttribute("value"), type);
                if (id == null)
                    return new ExampleAdornerState(State.Element, s.getPath() + ".reference", null, "", "");
                ResourceDefn r = definitions.getResourceByName(type);
                if (r == null)
                    throw new Exception("unable to find type " + type);
                for (Example e : r.getExamples()) {
                    if (id.equals(e.getId()))
                        if (Utilities.noString(e.getIg())) {
                            return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html\">", "</a>");
                        } else {
                            ImplementationGuideDefn ig = definitions.getIgs().get(e.getIg());
                            return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + ig.getPrefix() + e.getTitle() + ".xml.html\">", "</a>");
                        }
                    if (e.getXml() != null && e.getXml().getDocumentElement().getLocalName().equals("feed")) {
                        List<Element> entries = new ArrayList<Element>();
                        XMLUtil.getNamedChildren(e.getXml().getDocumentElement(), "entry", entries);
                        String url = "http://hl7.org/fhir/" + type + "/" + id;
                        for (Element c : entries) {
                            String t = XMLUtil.getNamedChild(c, "id").getAttribute("value");
                            if (url.equals(t))
                                return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html#" + id + "\">", "</a>");
                        }
                    }
                }
                return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<font color=\"red\">", "</font>");
            } else
                return new ExampleAdornerState(State.Reference, s.getPath(), s.getDefinition(), "", "");
        } else
            // else
            return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
    }
}
Also used : Example(org.hl7.fhir.definitions.model.Example) Element(org.w3c.dom.Element) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) List(java.util.List) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 37 with CodeableReference

use of org.hl7.fhir.r5.model.CodeableReference in project org.hl7.fhir.core by hapifhir.

the class CodeableConcept10_50 method convertCodeableConceptToCodableReference.

public static CodeableReference convertCodeableConceptToCodableReference(CodeableConcept src) {
    CodeableReference tgt = new CodeableReference();
    tgt.setConcept(convertCodeableConcept(src));
    return tgt;
}
Also used : CodeableReference(org.hl7.fhir.r5.model.CodeableReference)

Example 38 with CodeableReference

use of org.hl7.fhir.r5.model.CodeableReference in project org.hl7.fhir.core by hapifhir.

the class SupplyRequest40_50 method convertSupplyRequest.

public static org.hl7.fhir.r4.model.SupplyRequest convertSupplyRequest(org.hl7.fhir.r5.model.SupplyRequest src) throws FHIRException {
    if (src == null)
        return null;
    org.hl7.fhir.r4.model.SupplyRequest tgt = new org.hl7.fhir.r4.model.SupplyRequest();
    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
    if (src.hasStatus())
        tgt.setStatusElement(convertSupplyRequestStatus(src.getStatusElement()));
    if (src.hasCategory())
        tgt.setCategory(CodeableConcept40_50.convertCodeableConcept(src.getCategory()));
    if (src.hasPriority())
        tgt.setPriorityElement(convertRequestPriority(src.getPriorityElement()));
    if (src.hasItem()) {
        if (src.getItem().hasReference()) {
            tgt.setItem(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getItem().getReference()));
        } else {
            tgt.setItem(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getItem().getConcept()));
        }
    }
    if (src.hasQuantity())
        tgt.setQuantity(Quantity40_50.convertQuantity(src.getQuantity()));
    for (org.hl7.fhir.r5.model.SupplyRequest.SupplyRequestParameterComponent t : src.getParameter()) tgt.addParameter(convertSupplyRequestParameterComponent(t));
    if (src.hasOccurrence())
        tgt.setOccurrence(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getOccurrence()));
    if (src.hasAuthoredOn())
        tgt.setAuthoredOnElement(DateTime40_50.convertDateTime(src.getAuthoredOnElement()));
    if (src.hasRequester())
        tgt.setRequester(Reference40_50.convertReference(src.getRequester()));
    for (org.hl7.fhir.r5.model.Reference t : src.getSupplier()) tgt.addSupplier(Reference40_50.convertReference(t));
    for (CodeableReference t : src.getReason()) if (t.hasConcept())
        tgt.addReasonCode(CodeableConcept40_50.convertCodeableConcept(t.getConcept()));
    for (CodeableReference t : src.getReason()) if (t.hasReference())
        tgt.addReasonReference(Reference40_50.convertReference(t.getReference()));
    if (src.hasDeliverFrom())
        tgt.setDeliverFrom(Reference40_50.convertReference(src.getDeliverFrom()));
    if (src.hasDeliverTo())
        tgt.setDeliverTo(Reference40_50.convertReference(src.getDeliverTo()));
    return tgt;
}
Also used : CodeableReference(org.hl7.fhir.r5.model.CodeableReference)

Example 39 with CodeableReference

use of org.hl7.fhir.r5.model.CodeableReference in project org.hl7.fhir.core by hapifhir.

the class Provenance30_50 method convertProvenance.

public static org.hl7.fhir.dstu3.model.Provenance convertProvenance(org.hl7.fhir.r5.model.Provenance src) throws FHIRException {
    if (src == null)
        return null;
    org.hl7.fhir.dstu3.model.Provenance tgt = new org.hl7.fhir.dstu3.model.Provenance();
    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
    for (org.hl7.fhir.r5.model.Reference t : src.getTarget()) tgt.addTarget(Reference30_50.convertReference(t));
    if (src.hasOccurredPeriod())
        tgt.setPeriod(Period30_50.convertPeriod(src.getOccurredPeriod()));
    if (src.hasRecorded())
        tgt.setRecordedElement(Instant30_50.convertInstant(src.getRecordedElement()));
    for (org.hl7.fhir.r5.model.UriType t : src.getPolicy()) tgt.getPolicy().add(Uri30_50.convertUri(t));
    if (src.hasLocation())
        tgt.setLocation(Reference30_50.convertReference(src.getLocation()));
    for (CodeableReference t : src.getAuthorization()) if (t.hasConcept())
        for (org.hl7.fhir.r5.model.Coding t2 : t.getConcept().getCoding()) tgt.addReason(Coding30_50.convertCoding(t2));
    if (src.hasActivity())
        tgt.setActivity(Coding30_50.convertCoding(src.getActivity().getCodingFirstRep()));
    for (org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent t : src.getAgent()) tgt.addAgent(convertProvenanceAgentComponent(t));
    for (org.hl7.fhir.r5.model.Provenance.ProvenanceEntityComponent t : src.getEntity()) tgt.addEntity(convertProvenanceEntityComponent(t));
    for (org.hl7.fhir.r5.model.Signature t : src.getSignature()) tgt.addSignature(Signature30_50.convertSignature(t));
    return tgt;
}
Also used : CodeableReference(org.hl7.fhir.r5.model.CodeableReference)

Example 40 with CodeableReference

use of org.hl7.fhir.r5.model.CodeableReference in project org.hl7.fhir.core by hapifhir.

the class CommunicationRequest40_50 method convertCommunicationRequest.

public static org.hl7.fhir.r4.model.CommunicationRequest convertCommunicationRequest(org.hl7.fhir.r5.model.CommunicationRequest src) throws FHIRException {
    if (src == null)
        return null;
    org.hl7.fhir.r4.model.CommunicationRequest tgt = new org.hl7.fhir.r4.model.CommunicationRequest();
    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
    for (org.hl7.fhir.r5.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference40_50.convertReference(t));
    for (org.hl7.fhir.r5.model.Reference t : src.getReplaces()) tgt.addReplaces(Reference40_50.convertReference(t));
    if (src.hasGroupIdentifier())
        tgt.setGroupIdentifier(Identifier40_50.convertIdentifier(src.getGroupIdentifier()));
    if (src.hasStatus())
        tgt.setStatusElement(convertCommunicationRequestStatus(src.getStatusElement()));
    if (src.hasStatusReason())
        tgt.setStatusReason(CodeableConcept40_50.convertCodeableConcept(src.getStatusReason()));
    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getCategory()) tgt.addCategory(CodeableConcept40_50.convertCodeableConcept(t));
    if (src.hasPriority())
        tgt.setPriorityElement(convertCommunicationPriority(src.getPriorityElement()));
    if (src.hasDoNotPerform())
        tgt.setDoNotPerformElement(Boolean40_50.convertBoolean(src.getDoNotPerformElement()));
    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getMedium()) tgt.addMedium(CodeableConcept40_50.convertCodeableConcept(t));
    if (src.hasSubject())
        tgt.setSubject(Reference40_50.convertReference(src.getSubject()));
    for (org.hl7.fhir.r5.model.Reference t : src.getAbout()) tgt.addAbout(Reference40_50.convertReference(t));
    if (src.hasEncounter())
        tgt.setEncounter(Reference40_50.convertReference(src.getEncounter()));
    for (org.hl7.fhir.r5.model.CommunicationRequest.CommunicationRequestPayloadComponent t : src.getPayload()) tgt.addPayload(convertCommunicationRequestPayloadComponent(t));
    if (src.hasOccurrence())
        tgt.setOccurrence(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getOccurrence()));
    if (src.hasAuthoredOn())
        tgt.setAuthoredOnElement(DateTime40_50.convertDateTime(src.getAuthoredOnElement()));
    if (src.hasRequester())
        tgt.setRequester(Reference40_50.convertReference(src.getRequester()));
    for (org.hl7.fhir.r5.model.Reference t : src.getRecipient()) tgt.addRecipient(Reference40_50.convertReference(t));
    if (src.hasInformationProvider())
        tgt.setSender(Reference40_50.convertReference(src.getInformationProviderFirstRep()));
    for (CodeableReference t : src.getReason()) if (t.hasConcept())
        tgt.addReasonCode(CodeableConcept40_50.convertCodeableConcept(t.getConcept()));
    for (CodeableReference t : src.getReason()) if (t.hasReference())
        tgt.addReasonReference(Reference40_50.convertReference(t.getReference()));
    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation40_50.convertAnnotation(t));
    return tgt;
}
Also used : CodeableReference(org.hl7.fhir.r5.model.CodeableReference)

Aggregations

CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 CodeableConcept (org.hl7.fhir.r5.model.CodeableConcept)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)3 Annotation (org.hl7.fhir.r5.model.Annotation)3 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Base64 (org.apache.commons.codec.binary.Base64)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)2 Address (org.hl7.fhir.r4b.model.Address)2 Annotation (org.hl7.fhir.r4b.model.Annotation)2 Attachment (org.hl7.fhir.r4b.model.Attachment)2 Base (org.hl7.fhir.r4b.model.Base)2 Base64BinaryType (org.hl7.fhir.r4b.model.Base64BinaryType)2 BooleanType (org.hl7.fhir.r4b.model.BooleanType)2 CodeType (org.hl7.fhir.r4b.model.CodeType)2 CodeableConcept (org.hl7.fhir.r4b.model.CodeableConcept)2 CodeableReference (org.hl7.fhir.r4b.model.CodeableReference)2 Coding (org.hl7.fhir.r4b.model.Coding)2