Search in sources :

Example 56 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project CRD by HL7-DaVinci.

the class SubQuestionnaireProcessor method processItem.

/**
 * Determines if this item is a sub-questionnaire reference and returns the items to replace it with. Returns the same list
 * otherwise. Also recursively continues scanning if this is just a grouping item.
 *
 * @param item The item to check for sub-questionnaire referece.
 * @param fileStore The FileStore to be used for fetching sub-questionnaires.
 * @param baseUrl The base url from the server.
 * @param containedList List of contained resources to put in the assembled Questionnaire. This will be filled while iterating.
 * @param extensionList List of extensions to put in the assembled Questionnaire. This will be filled while iterating.
 * @return New list of items to replace this item with.
 */
private List<QuestionnaireItemComponent> processItem(QuestionnaireItemComponent item, FileStore fileStore, String baseUrl, Hashtable<String, org.hl7.fhir.r4.model.Resource> containedList, List<Extension> extensionList) {
    // find if item has an extension is sub-questionnaire
    Extension e = item.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/sub-questionnaire");
    if (e != null) {
        // read sub questionnaire from file store
        CanonicalType value = e.castToCanonical(e.getValue());
        logger.info("SubQuestionnaireProcessor::parseItem(): Looking for SubQuestionnaire " + value);
        // strip the type off of the id if it is there
        String id = value.asStringValue();
        String[] parts = id.split("/");
        if (parts.length > 1) {
            id = parts[1];
        }
        boolean expandRootItem = false;
        Extension expand = item.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/sub-questionnaire-expand");
        if (expand != null) {
            expandRootItem = expand.castToBoolean(expand.getValue()).booleanValue();
        }
        FileResource subFileResource = fileStore.getFhirResourceById("R4", "questionnaire", id, baseUrl, false);
        if (subFileResource != null) {
            Questionnaire subQuestionnaire = (Questionnaire) this.parseFhirFileResource(subFileResource);
            if (subQuestionnaire != null) {
                // merge extensions
                for (Extension subExtension : subQuestionnaire.getExtension()) {
                    if (extensionList.stream().noneMatch(ext -> ext.equalsDeep(subExtension))) {
                        extensionList.add(subExtension);
                    }
                }
                // merge contained resources
                for (org.hl7.fhir.r4.model.Resource r : subQuestionnaire.getContained()) {
                    containedList.put(r.getId(), r);
                }
                List<QuestionnaireItemComponent> rootItems = subQuestionnaire.getItem();
                // there are more than one root items in sub questionnaire, don't expand
                if (!expandRootItem || rootItems.size() > 1) {
                    return rootItems;
                } else {
                    return rootItems.get(0).getItem();
                }
            } else {
                // SubQuestionnaire could not be loaded
                logger.warn("SubQuestionnaireProcessor::parseItem(): Could not load SubQuestionnaire " + value.asStringValue());
                return Arrays.asList(item);
            }
        } else {
            // SubQuestionnaire could not be found
            logger.warn("SubQuestionnaireProcessor::parseItem(): Could not find SubQuestionnaire " + value.asStringValue());
            return Arrays.asList(item);
        }
    }
    // parse sub-items
    this.processItemList(item.getItem(), fileStore, baseUrl, containedList, extensionList);
    return Arrays.asList(item);
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Extension(org.hl7.fhir.r4.model.Extension)

Example 57 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project cqf-ruler by DBCG.

the class ExpressionEvaluation method buildIncludes.

private String buildIncludes(LibraryLoader libraryLoader, JpaFhirDal jpaFhirDal, Iterable<CanonicalType> references, RequestDetails theRequest) {
    StringBuilder builder = new StringBuilder();
    for (CanonicalType reference : references) {
        VersionedIdentifier vi = getVersionedIdentifierFromCanonical(reference);
        // Still not the best way to build include, but at least checks dal for an
        // existing library
        // Check if id works for LibraryRetrieval
        org.cqframework.cql.elm.execution.Library executionLibrary = null;
        try {
            executionLibrary = libraryLoader.load(vi);
        } catch (Exception e) {
        // log error
        }
        if (executionLibrary != null) {
            // log not found so looking in local data
            builder.append(buildLibraryIncludeString(vi));
        } else // else check local data for Library to get name and version from
        {
            Library library = (Library) jpaFhirDal.read(new IdType("Library", Canonicals.getIdPart(reference)));
            builder.append(buildLibraryIncludeString(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion())));
        }
    }
    return builder.toString();
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Library(org.hl7.fhir.r4.model.Library) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) IdType(org.hl7.fhir.r4.model.IdType)

Example 58 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveTask.

private Task resolveTask(ActivityDefinition activityDefinition, String patientId) {
    Task task = new Task();
    task.setStatus(Task.TaskStatus.DRAFT);
    task.setIntent(Task.TaskIntent.PROPOSAL);
    task.setFor(new Reference(patientId));
    Task.ParameterComponent input = new Task.ParameterComponent();
    if (activityDefinition.hasCode()) {
        task.setCode(activityDefinition.getCode());
        input.setType(activityDefinition.getCode());
    }
    // Extension defined by CPG-on-FHIR for Questionnaire canonical URI
    Extension collectsWith = activityDefinition.getExtensionByUrl("http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-collectWith");
    if (collectsWith != null && collectsWith.getValueAsPrimitive().toString() != null) {
        CanonicalType uri = new CanonicalType(collectsWith.getValueAsPrimitive().toString());
        input.setValue(uri);
    }
    if (activityDefinition.hasRelatedArtifact()) {
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            if (artifact.hasUrl()) {
                Attachment attachment = new Attachment().setUrl(artifact.getUrl());
                if (artifact.hasDisplay()) {
                    attachment.setTitle(artifact.getDisplay());
                }
                input.setValue(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
            }
        // TODO - other relatedArtifact types
        }
    }
    // If input has been populated, then add it to the Task.
    if (input.getType() != null || input.getValue() != null) {
        task.addInput(input);
    }
    return task;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Task(org.hl7.fhir.r4.model.Task) Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) CanonicalType(org.hl7.fhir.r4.model.CanonicalType)

Example 59 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project cqf-ruler by DBCG.

the class CareGapsProvider method careGapsReport.

/**
 * Implements the <a href=
 * "http://build.fhir.org/ig/HL7/davinci-deqm/OperationDefinition-care-gaps.html">$care-gaps</a>
 * operation found in the
 * <a href="http://build.fhir.org/ig/HL7/davinci-deqm/index.html">Da Vinci DEQM
 * FHIR Implementation Guide</a> that overrides the <a href=
 * "http://build.fhir.org/operation-measure-care-gaps.html">$care-gaps</a>
 * operation found in the
 * <a href="http://hl7.org/fhir/R4/clinicalreasoning-module.html">FHIR Clinical
 * Reasoning Module</a>.
 *
 * The operation calculates measures describing gaps in care. For more details,
 * reference the <a href=
 * "http://build.fhir.org/ig/HL7/davinci-deqm/gaps-in-care-reporting.html">Gaps
 * in Care Reporting</a> section of the
 * <a href="http://build.fhir.org/ig/HL7/davinci-deqm/index.html">Da Vinci DEQM
 * FHIR Implementation Guide</a>.
 *
 * A Parameters resource that includes zero to many document bundles that
 * include Care Gap Measure Reports will be returned.
 *
 * Usage:
 * URL: [base]/Measure/$care-gaps
 *
 * @param theRequestDetails generally auto-populated by the HAPI server
 *                          framework.
 * @param periodStart       the start of the gaps through period
 * @param periodEnd         the end of the gaps through period
 * @param topic             the category of the measures that is of interest for
 *                          the care gaps report
 * @param subject           a reference to either a Patient or Group for which
 *                          the gaps in care report(s) will be generated
 * @param practitioner      a reference to a Practitioner for which the gaps in
 *                          care report(s) will be generated
 * @param organization      a reference to an Organization for which the gaps in
 *                          care report(s) will be generated
 * @param status            the status code of gaps in care reports that will be
 *                          included in the result
 * @param measureId         the id of Measure(s) for which the gaps in care
 *                          report(s) will be calculated
 * @param measureIdentifier the identifier of Measure(s) for which the gaps in
 *                          care report(s) will be calculated
 * @param measureUrl        the canonical URL of Measure(s) for which the gaps
 *                          in care report(s) will be calculated
 * @param program           the program that a provider (either clinician or
 *                          clinical organization) participates in
 * @return Parameters of bundles of Care Gap Measure Reports
 */
// warning for greater than 7 parameters
@SuppressWarnings("squid:S00107")
@Description(shortDefinition = "$care-gaps", value = "Implements the <a href=\"http://build.fhir.org/ig/HL7/davinci-deqm/OperationDefinition-care-gaps.html\">$care-gaps</a> operation found in the <a href=\"http://build.fhir.org/ig/HL7/davinci-deqm/index.html\">Da Vinci DEQM FHIR Implementation Guide</a> which is an extension of the <a href=\"http://build.fhir.org/operation-measure-care-gaps.html\">$care-gaps</a> operation found in the <a href=\"http://hl7.org/fhir/R4/clinicalreasoning-module.html\">FHIR Clinical Reasoning Module</a>.")
@Operation(name = "$care-gaps", idempotent = true, type = Measure.class)
public Parameters careGapsReport(RequestDetails theRequestDetails, @OperationParam(name = "periodStart") String periodStart, @OperationParam(name = "periodEnd") String periodEnd, @OperationParam(name = "topic") List<String> topic, @OperationParam(name = "subject") String subject, @OperationParam(name = "practitioner") String practitioner, @OperationParam(name = "organization") String organization, @OperationParam(name = "status") List<String> status, @OperationParam(name = "measureId") List<String> measureId, @OperationParam(name = "measureIdentifier") List<String> measureIdentifier, @OperationParam(name = "measureUrl") List<CanonicalType> measureUrl, @OperationParam(name = "program") List<String> program) {
    validateConfiguration(theRequestDetails);
    validateParameters(theRequestDetails);
    // TODO: filter by topic.
    // TODO: filter by program.
    List<Measure> measures = ensureMeasures(getMeasures(measureId, measureIdentifier, measureUrl, theRequestDetails));
    List<Patient> patients;
    if (!Strings.isNullOrEmpty(subject)) {
        patients = getPatientListFromSubject(subject);
    } else {
        // TODO: implement non subject parameters (practitioner and organization)
        throw new NotImplementedException("Non subject parameters have not been implemented.");
    }
    Parameters result = initializeResult();
    (patients).forEach(patient -> {
        Parameters.ParametersParameterComponent patientParameter = patientReports(theRequestDetails, periodStart, periodEnd, patient, status, measures, organization);
        if (patientParameter != null) {
            result.addParameter(patientParameter);
        }
    });
    return result;
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 60 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project cqf-ruler by DBCG.

the class DataOperationsProvider method getLibraryFromMeasure.

public Library getLibraryFromMeasure(Measure measure, RequestDetails theRequestDetails) {
    Iterator<CanonicalType> var6 = measure.getLibrary().iterator();
    String libraryIdOrCanonical = null;
    // use the first library
    while (var6.hasNext() && libraryIdOrCanonical == null) {
        CanonicalType ref = var6.next();
        if (ref != null) {
            libraryIdOrCanonical = ref.getValue();
        }
    }
    Library library = read(new IdType(libraryIdOrCanonical), theRequestDetails);
    if (library == null) {
        library = search(Library.class, Searches.byCanonical(libraryIdOrCanonical), theRequestDetails).firstOrNull();
    }
    return library;
}
Also used : Library(org.hl7.fhir.r4.model.Library) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) IdType(org.hl7.fhir.r4.model.IdType)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)45 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)27 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Extension (org.hl7.fhir.r4.model.Extension)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 IdType (org.hl7.fhir.r4.model.IdType)5