Search in sources :

Example 76 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project quality-measure-and-cohort-service by Alvearie.

the class R4TranslatingLibraryLoader method load.

@Override
public Library load(VersionedIdentifier libraryIdentifier) {
    Library elmLibrary = null;
    org.hl7.fhir.r4.model.Library fhirLibrary = resolver.resolveByName(libraryIdentifier.getId(), libraryIdentifier.getVersion());
    if (fhirLibrary == null) {
        throw new IllegalArgumentException(String.format("Library %s-%s not found", libraryIdentifier.getId(), libraryIdentifier.getVersion()));
    }
    Map<String, Attachment> mimeTypeIndex = new HashMap<>();
    for (Attachment attachment : fhirLibrary.getContent()) {
        if (attachment.hasContentType()) {
            mimeTypeIndex.put(attachment.getContentType(), attachment);
        } else {
            throw new IllegalArgumentException(String.format("Library %s-%s contains an attachment with no content type", libraryIdentifier.getId(), libraryIdentifier.getVersion()));
        }
    }
    Attachment attachment = mimeTypeIndex.get("application/elm+xml");
    if (attachment != null) {
        try (InputStream is = getAttachmentDataAsStream(attachment)) {
            elmLibrary = CqlLibraryReader.read(is);
        } catch (Exception ex) {
            throw new IllegalArgumentException(String.format("Library %s-%s elm attachment failed to deserialize", libraryIdentifier.getId(), libraryIdentifier.getVersion()), ex);
        }
    }
    if (elmLibrary == null) {
        attachment = mimeTypeIndex.get("text/cql");
        if (attachment == null) {
            throw new IllegalArgumentException(String.format("Library %s-%s must contain either a application/elm+xml or text/cql attachment", libraryIdentifier.getId(), libraryIdentifier.getVersion()));
        } else {
            String content = getAttachmentDataAsString(attachment);
            try {
                elmLibrary = OptimizedCqlLibraryReader.read(translateLibrary(content, libraryIdentifier));
            } catch (Exception ex) {
                throw new IllegalArgumentException(String.format("Library %s-%s cql attachment failed to deserialize", libraryIdentifier.getId(), libraryIdentifier.getVersion()), ex);
            }
        }
    }
    return elmLibrary;
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(org.hl7.fhir.r4.model.Attachment) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library)

Example 77 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeDocumentReferenceDocumentReferenceContentComponent.

protected void composeDocumentReferenceDocumentReferenceContentComponent(Complex parent, String parentType, String name, DocumentReference.DocumentReferenceContentComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "content", name, element, index);
    if (element.hasAttachment())
        composeAttachment(t, "DocumentReference", "attachment", element.getAttachment(), -1);
    for (int i = 0; i < element.getFormat().size(); i++) composeCoding(t, "DocumentReference", "format", element.getFormat().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 78 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project org.hl7.fhir.core by hapifhir.

the class Questionnaire30_50 method convertQuestionnaireItemType.

public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> convertQuestionnaireItemType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType> src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemTypeEnumFactory());
    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
    tgt.addExtension(VersionConvertorConstants.EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL, new CodeType(src.getValueAsString()));
    switch(src.getValue()) {
        case GROUP:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.GROUP);
            break;
        case DISPLAY:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DISPLAY);
            break;
        case BOOLEAN:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.BOOLEAN);
            break;
        case DECIMAL:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DECIMAL);
            break;
        case INTEGER:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.INTEGER);
            break;
        case DATE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATE);
            break;
        case DATETIME:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
            break;
        case TIME:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TIME);
            break;
        case STRING:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.STRING);
            break;
        case TEXT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TEXT);
            break;
        case URL:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.URL);
            break;
        case CHOICE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
            break;
        case OPENCHOICE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
            break;
        case ATTACHMENT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.ATTACHMENT);
            break;
        case REFERENCE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.REFERENCE);
            break;
        case QUANTITY:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.QUANTITY);
            break;
        default:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.NULL);
            break;
    }
    return tgt;
}
Also used : QuestionnaireItemType(org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType) Questionnaire(org.hl7.fhir.r5.model.Questionnaire) CodeType(org.hl7.fhir.r5.model.CodeType)

Example 79 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method displayLeaf.

private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return false;
    Base e = ew.getBase();
    Map<String, String> displayHints = readDisplayHints(defn);
    if (name.endsWith("[x]"))
        name = name.substring(0, name.length() - 3);
    if (!showCodeDetails && e instanceof PrimitiveType && isDefault(displayHints, ((PrimitiveType) e)))
        return false;
    if (e instanceof StringType) {
        x.addText(name + ": " + ((StringType) e).getValue());
        return true;
    } else if (e instanceof CodeType) {
        x.addText(name + ": " + ((CodeType) e).getValue());
        return true;
    } else if (e instanceof IdType) {
        x.addText(name + ": " + ((IdType) e).getValue());
        return true;
    } else if (e instanceof DateTimeType) {
        x.addText(name + ": " + ((DateTimeType) e).toHumanDisplay());
        return true;
    } else if (e instanceof InstantType) {
        x.addText(name + ": " + ((InstantType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Extension) {
        x.addText("Extensions: todo");
        return true;
    } else if (e instanceof org.hl7.fhir.dstu2.model.DateType) {
        x.addText(name + ": " + ((org.hl7.fhir.dstu2.model.DateType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Enumeration) {
        // todo: look up a display name if there is one
        x.addText(((Enumeration<?>) e).getValue().toString());
        return true;
    } else if (e instanceof BooleanType) {
        if (((BooleanType) e).getValue()) {
            x.addText(name);
            return true;
        }
    } else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
        return true;
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
        return true;
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x, showCodeDetails);
        return true;
    } else if (e instanceof org.hl7.fhir.dstu2.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu2.model.IntegerType) e).getValue()));
        return true;
    } else if (e instanceof org.hl7.fhir.dstu2.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu2.model.DecimalType) e).getValue().toString());
        return true;
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
        return true;
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
        return true;
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
        return true;
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
        return true;
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
        return true;
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
        return true;
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
        return true;
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.addText("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
        return true;
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(name + ": ");
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.addText(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
        return true;
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.hasDisplayElement())
            x.addText(r.getDisplay());
        else if (r.hasReferenceElement()) {
            ResourceWithReference tr = resolveReference(res, r.getReference());
            // getDisplayForReference(tr.getReference()));
            x.addText(tr == null ? r.getReference() : "????");
        } else
            x.addText("??");
        return true;
    } else if (e instanceof Narrative) {
        return false;
    } else if (e instanceof Resource) {
        return false;
    } else if (!(e instanceof Attachment))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
    return false;
}
Also used : Address(org.hl7.fhir.dstu2.model.Address) StringType(org.hl7.fhir.dstu2.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu2.model.Attachment) HumanName(org.hl7.fhir.dstu2.model.HumanName) ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) Identifier(org.hl7.fhir.dstu2.model.Identifier) Coding(org.hl7.fhir.dstu2.model.Coding) Narrative(org.hl7.fhir.dstu2.model.Narrative) SampledData(org.hl7.fhir.dstu2.model.SampledData) PrimitiveType(org.hl7.fhir.dstu2.model.PrimitiveType) Ratio(org.hl7.fhir.dstu2.model.Ratio) InstantType(org.hl7.fhir.dstu2.model.InstantType) Enumeration(org.hl7.fhir.dstu2.model.Enumeration) Reference(org.hl7.fhir.dstu2.model.Reference) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Quantity(org.hl7.fhir.dstu2.model.Quantity) Period(org.hl7.fhir.dstu2.model.Period) Base(org.hl7.fhir.dstu2.model.Base) Annotation(org.hl7.fhir.dstu2.model.Annotation) IdType(org.hl7.fhir.dstu2.model.IdType) Extension(org.hl7.fhir.dstu2.model.Extension) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) CodeType(org.hl7.fhir.dstu2.model.CodeType) EventTiming(org.hl7.fhir.dstu2.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu2.model.Timing) CodeableConcept(org.hl7.fhir.dstu2.model.CodeableConcept)

Example 80 with Attachment

use of org.hl7.fhir.r4b.model.Attachment in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireValidator method validateQuestionnaireResponseItem.

private void validateQuestionnaireResponseItem(ValidatorHostContext hostContext, QuestionnaireWithContext qsrc, QuestionnaireItemComponent qItem, List<ValidationMessage> errors, Element element, NodeStack stack, boolean inProgress, Element questionnaireResponseRoot, QStack qstack) {
    String text = element.getNamedChildValue("text");
    rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), Utilities.noString(text) || text.equals(qItem.getText()), I18nConstants.QUESTIONNAIRE_QR_ITEM_TEXT, qItem.getLinkId());
    List<Element> answers = new ArrayList<Element>();
    element.getNamedChildren("answer", answers);
    if (inProgress)
        warning(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), isAnswerRequirementFulfilled(qItem, answers), I18nConstants.QUESTIONNAIRE_QR_ITEM_MISSING, qItem.getLinkId());
    else if (myEnableWhenEvaluator.isQuestionEnabled(hostContext, qItem, qstack, fpe)) {
        rule(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), isAnswerRequirementFulfilled(qItem, answers), I18nConstants.QUESTIONNAIRE_QR_ITEM_MISSING, qItem.getLinkId());
    } else if (!answers.isEmpty()) {
    // items without answers should be allowed, but not items with answers to questions that are disabled
    // it appears that this is always a duplicate error - it will always already have been reported, so no need to report it again?
    // GDG 2019-07-13
    // rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), !isAnswerRequirementFulfilled(qItem, answers), I18nConstants.QUESTIONNAIRE_QR_ITEM_NOTENABLED, qItem.getLinkId());
    }
    if (answers.size() > 1)
        rule(errors, IssueType.INVALID, answers.get(1).line(), answers.get(1).col(), stack.getLiteralPath(), qItem.getRepeats(), I18nConstants.QUESTIONNAIRE_QR_ITEM_ONLYONEA);
    int i = 0;
    for (Element answer : answers) {
        NodeStack ns = stack.push(answer, i, null, null);
        if (qItem.getType() != null) {
            switch(qItem.getType()) {
                case GROUP:
                    rule(errors, IssueType.STRUCTURE, answer.line(), answer.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_GROUP);
                    break;
                case // nothing
                DISPLAY:
                    break;
                case BOOLEAN:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "boolean");
                    break;
                case DECIMAL:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "decimal");
                    break;
                case INTEGER:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "integer");
                    break;
                case DATE:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "date");
                    break;
                case DATETIME:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "dateTime");
                    break;
                case TIME:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "time");
                    break;
                case STRING:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "string");
                    break;
                case TEXT:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "text");
                    break;
                case URL:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "uri");
                    break;
                case ATTACHMENT:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "Attachment");
                    break;
                case REFERENCE:
                    validateQuestionnaireResponseItemType(errors, answer, ns, "Reference");
                    break;
                case QUANTITY:
                    if ("Quantity".equals(validateQuestionnaireResponseItemType(errors, answer, ns, "Quantity")))
                        if (qItem.hasExtension("???"))
                            validateQuestionnaireResponseItemQuantity(errors, answer, ns);
                    break;
                case CODING:
                    String itemType = validateQuestionnaireResponseItemType(errors, answer, ns, "Coding", "date", "time", "integer", "string");
                    if (itemType != null) {
                        if (itemType.equals("Coding"))
                            validateAnswerCode(errors, answer, ns, qsrc, qItem, false);
                        else if (itemType.equals("date"))
                            checkOption(errors, answer, ns, qsrc, qItem, "date");
                        else if (itemType.equals("time"))
                            checkOption(errors, answer, ns, qsrc, qItem, "time");
                        else if (itemType.equals("integer"))
                            checkOption(errors, answer, ns, qsrc, qItem, "integer");
                        else if (itemType.equals("string"))
                            checkOption(errors, answer, ns, qsrc, qItem, "string");
                    }
                    break;
                // case QUESTION:
                case NULL:
                    // no validation
                    break;
                case QUESTION:
                    throw new Error("Shouldn't get here?");
            }
        }
        if (qItem.getType() != QuestionnaireItemType.GROUP) {
            // if it's a group, we already have an error before getting here, so no need to hammer away on that
            validateQuestionannaireResponseItems(hostContext, qsrc, qItem.getItem(), errors, answer, stack, inProgress, questionnaireResponseRoot, qstack);
        }
        i++;
    }
    if (qItem.getType() == null) {
        fail(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_NOTYPE, qItem.getLinkId());
    } else if (qItem.getType() == QuestionnaireItemType.DISPLAY) {
        List<Element> items = new ArrayList<Element>();
        element.getNamedChildren("item", items);
        rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), items.isEmpty(), I18nConstants.QUESTIONNAIRE_QR_ITEM_DISPLAY, qItem.getLinkId());
    } else if (qItem.getType() != QuestionnaireItemType.GROUP) {
        List<Element> items = new ArrayList<Element>();
        element.getNamedChildren("item", items);
        rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), items.isEmpty(), I18nConstants.QUESTIONNAIRE_QR_ITEM_GROUP_ANSWER, qItem.getLinkId());
    } else {
        validateQuestionannaireResponseItems(hostContext, qsrc, qItem.getItem(), errors, element, stack, inProgress, questionnaireResponseRoot, qstack);
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 Reference (org.hl7.fhir.r4.model.Reference)17 ArrayList (java.util.ArrayList)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Coding (org.hl7.fhir.r4.model.Coding)11 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 List (java.util.List)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)9 Observation (org.hl7.fhir.r4.model.Observation)9 Test (org.junit.jupiter.api.Test)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 FhirContext (ca.uhn.fhir.context.FhirContext)5 HashMap (java.util.HashMap)5 Base64 (org.apache.commons.codec.binary.Base64)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 Extension (org.hl7.fhir.r4.model.Extension)5 Library (org.hl7.fhir.r4.model.Library)5