Search in sources :

Example 66 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project MobileAccessGateway by i4mi.

the class Iti65RequestConverter method transformReferenceToIdentifiable.

/**
 * FHIR Reference -> XDS Identifiable
 * Only for References to Patients or Encounters
 * Identifier is extracted from contained resource or from Reference URL
 * @param reference
 * @param container
 * @return
 */
public Identifiable transformReferenceToIdentifiable(Reference reference, DomainResource container) {
    if (reference.hasReference()) {
        String targetRef = reference.getReference();
        List<Resource> resources = container.getContained();
        for (Resource resource : resources) {
            if (targetRef.equals(resource.getId())) {
                if (resource instanceof Patient) {
                    return transform(((Patient) resource).getIdentifierFirstRep());
                } else if (resource instanceof Encounter) {
                    return transform(((Encounter) resource).getIdentifierFirstRep());
                }
            }
        }
        Identifiable result = patientRefCreator.resolvePatientReference(reference.getReference());
        if (result != null)
            return result;
        MultiValueMap<String, String> vals = UriComponentsBuilder.fromUriString(targetRef).build().getQueryParams();
        if (vals.containsKey("identifier")) {
            String ids = vals.getFirst("identifier");
            if (ids == null)
                return null;
            String[] identifier = ids.split("\\|");
            if (identifier.length == 2) {
                return new Identifiable(identifier[1], new AssigningAuthority(noPrefix(identifier[0])));
            }
        }
    } else if (reference.hasIdentifier()) {
        return transform(reference.getIdentifier());
    }
    throw new InvalidRequestException("Cannot resolve reference to " + (reference.getReference() != null ? reference.getReference().toString() : ""));
}
Also used : Resource(org.hl7.fhir.r4.model.Resource) ListResource(org.hl7.fhir.r4.model.ListResource) DomainResource(org.hl7.fhir.r4.model.DomainResource) Patient(org.hl7.fhir.r4.model.Patient) Encounter(org.hl7.fhir.r4.model.Encounter) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) LocalizedString(org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString) AssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority) CXiAssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.CXiAssigningAuthority) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable)

Example 67 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project cqf-ruler by DBCG.

the class ExpressionEvaluationIT method testExpressionEvaluationANCIND01MeasureDomain.

@Test
public void testExpressionEvaluationANCIND01MeasureDomain() throws Exception {
    DomainResource measure = (DomainResource) measures.get("ANCIND01");
    // Patient First
    uploadTests("test/measure/ANCIND01/charity-otala-1/Patient");
    Map<String, IBaseResource> resources = uploadTests("test/measure/ANCIND01");
    IBaseResource patient = resources.get("charity-otala-1");
    Object ipResult = expressionEvaluation.evaluateInContext(measure, "ANCIND01.\"Initial Population\"", patient.getIdElement().getIdPart(), new SystemRequestDetails());
    assertTrue(ipResult instanceof Boolean);
    assertTrue(((Boolean) ipResult).booleanValue());
    Object denomResult = expressionEvaluation.evaluateInContext(measure, "ANCIND01.Denominator", patient.getIdElement().getIdPart(), new SystemRequestDetails());
    assertTrue(denomResult instanceof Boolean);
    assertTrue(((Boolean) denomResult).booleanValue());
    Object numerResult = expressionEvaluation.evaluateInContext(measure, "ANCIND01.Numerator", patient.getIdElement().getIdPart(), new SystemRequestDetails());
    assertTrue(numerResult instanceof Boolean);
    assertTrue(((Boolean) numerResult).booleanValue());
}
Also used : DomainResource(org.hl7.fhir.r4.model.DomainResource) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 68 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project cqf-ruler by DBCG.

the class ExpressionEvaluationIT method testExpressionEvaluationANCDT01PlanDefinitionDomain.

@Test
public void testExpressionEvaluationANCDT01PlanDefinitionDomain() throws Exception {
    DomainResource planDefinition = (DomainResource) planDefinitions.get("lcs-cds-patient-view");
    // Patient First
    uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker/Patient");
    Map<String, IBaseResource> resources = uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker");
    IBaseResource patient = resources.get("Former-Smoker");
    Object isFormerSmoker = expressionEvaluation.evaluateInContext(planDefinition, "Is former smoker who quit within past 15 years", patient.getIdElement().getIdPart(), true, new SystemRequestDetails());
    assertTrue(isFormerSmoker instanceof Boolean);
    assertTrue(((Boolean) isFormerSmoker).booleanValue());
    Object isCurrentSmoker = expressionEvaluation.evaluateInContext(planDefinition, "Is current smoker", patient.getIdElement().getIdPart(), true, new SystemRequestDetails());
    assertTrue(isCurrentSmoker instanceof Boolean);
    assertTrue((!(Boolean) isCurrentSmoker));
}
Also used : DomainResource(org.hl7.fhir.r4.model.DomainResource) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 69 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProviderIT method testActivityDefinitionApply.

@Test
public void testActivityDefinitionApply() throws Exception {
    DomainResource activityDefinition = (DomainResource) activityDefinitions.get("opioidcds-risk-assessment-request");
    // Patient First
    Map<String, IBaseResource> resources = uploadTests("test/activitydefinition/Patient");
    IBaseResource patient = resources.get("ExamplePatient");
    Resource applyResult = activityDefinitionApplyProvider.apply(new SystemRequestDetails(), activityDefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
    assertTrue(applyResult instanceof ServiceRequest);
    assertEquals("454281000124100", ((ServiceRequest) applyResult).getCode().getCoding().get(0).getCode());
}
Also used : DomainResource(org.hl7.fhir.r4.model.DomainResource) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 70 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project cqf-ruler by DBCG.

the class ExpressionEvaluation method getLibraryReferences.

private List<Reference> getLibraryReferences(DomainResource instance, JpaFhirDal jpaFhirDal, RequestDetails theRequest) {
    List<Reference> references = new ArrayList<>();
    if (instance.hasContained()) {
        for (Resource resource : instance.getContained()) {
            if (resource instanceof Library) {
                resource.setId(resource.getIdElement().getIdPart().replace("#", ""));
                jpaFhirDal.update((Library) resource);
            // getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(),
            // getLibraryLoader().toElmLibrary((Library) resource));
            }
        }
    }
    if (instance instanceof ActivityDefinition) {
        references.addAll(((ActivityDefinition) instance).getLibrary());
    } else if (instance instanceof PlanDefinition) {
        references.addAll(((PlanDefinition) instance).getLibrary());
    } else if (instance instanceof Measure) {
        references.addAll(((Measure) instance).getLibrary());
    }
    for (Extension extension : instance.getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/cqif-library")) {
        Type value = extension.getValue();
        if (value instanceof Reference) {
            references.add((Reference) value);
        } else {
            throw new RuntimeException("Library extension does not have a value of type reference");
        }
    }
    return cleanReferences(references);
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) Resource(org.hl7.fhir.dstu3.model.Resource) Measure(org.hl7.fhir.dstu3.model.Measure) PlanDefinition(org.hl7.fhir.dstu3.model.PlanDefinition) Library(org.hl7.fhir.dstu3.model.Library) ActivityDefinition(org.hl7.fhir.dstu3.model.ActivityDefinition)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 DomainResource (org.hl7.fhir.r4.model.DomainResource)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 IOException (java.io.IOException)15 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)15 FileOutputStream (java.io.FileOutputStream)12 ArrayList (java.util.ArrayList)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Test (org.junit.jupiter.api.Test)11 Resource (org.hl7.fhir.r4.model.Resource)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 FileNotFoundException (java.io.FileNotFoundException)8 List (java.util.List)8 NotImplementedException (org.apache.commons.lang3.NotImplementedException)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)7 File (java.io.File)7 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)7