hapifhir / hapi-fhir

đŸ”¥ HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.03k stars 1.33k forks source link

CQL: $evaluate-measure leads to HAPI-0389 error if the server contains more than 20 resources #4065

Closed wetret closed 1 year ago

wetret commented 2 years ago

Describe the bug:

Executing CQL on a server containing more then 20 resources using a Library and a Measure resource as well as the $evalutate-measure operation leads to the error:

HAPI-0389: Failed to call access method: ca.uhn.fhir.context.ConfigurationException: HAPI-0464: Attempt to request all resources from an asynchronous search result.  The SearchParameterMap for this search probably should have been synchronous.

To Reproduce:

  1. Start HAPI FHIR server using the following docker-compose:
    
    version: '3.8'
    services:
    app:
    image: hapiproject/hapi:v6.1.0
    ports:
      - 8080:8080
    environment:
      TZ: Europe/Berlin
      HAPI_FHIR_CQL_ENABLED: "true"
      SPRING_DATASOURCE_URL: jdbc:postgresql://db/fhir
      SPRING_DATASOURCE_USERNAME: hapi
      SPRING_DATASOURCE_PASSWORD: password
      SPRING_DATASOURCE_DRIVERCLASSNAME: org.postgresql.Driver
      spring.jpa.properties.hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect
    networks:
      backend:
    depends_on:
      - db
    db:
    image: postgres:14
    restart: on-failure
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U hapi -d fhir"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - type: volume
        source: db-hapi
        target: /var/lib/postgresql/data
    environment:
      TZ: Europe/Berlin
      POSTGRES_DB: fhir
      POSTGRES_USER: hapi
      POSTGRES_PASSWORD: password
    networks:
      backend:

volumes: db-hapi: name: db-hapi

networks: backend:


2. Load 20 Patient resources like:
```xml
<Patient xmlns="http://hl7.org/fhir">
    <active value="true"/>
    <name>
        <use value="official"/>
        <family value="Chalmers"/>
        <given value="Peter"/>
        <given value="James"/>
    </name>
    <gender value="male"/>
    <birthDate value="1974-12-25"/>
    <deceasedBoolean value="false"/>
</Patient>
  1. Store Library and Measure resources using the following Transaction-Bundle:

    <Bundle xmlns="http://hl7.org/fhir">
    <type value="transaction"/>
    <entry>
        <fullUrl value="urn:uuid:00000000-0000-0000-0000-library00001"/>
        <resource>
            <Library xmlns="http://hl7.org/fhir">
                <url value="urn:uuid:00000000-0000-0000-0000-library00001"/>
                <name value="Retrieve"/>
                <version value="1.0.0"/>
                <status value="active"/>
                <type>
                    <coding>
                        <system value="http://terminology.hl7.org/CodeSystem/library-type"/>
                        <code value="logic-library"/>
                    </coding>
                </type>
                <content>
                    <contentType value="text/cql"/>
                    <data value="bGlicmFyeSBSZXRyaWV2ZSB2ZXJzaW9uICcxLjAuMCcKdXNpbmcgRkhJUiB2ZXJzaW9uICc0LjAuMCcKaW5jbHVkZSBGSElSSGVscGVycyB2ZXJzaW9uICc0LjAuMCcKCmNvbnRleHQgUGF0aWVudAoKZGVmaW5lIEluSW5pdGlhbFBvcHVsYXRpb246CiAgUGF0aWVudC5nZW5kZXIgPSAnbWFsZSc="/>
                </content>
            </Library>
        </resource>
        <request>
            <method value="POST"/>
            <url value="Library"/>
        </request>
    </entry>
    <entry>
        <fullUrl value="urn:uuid:00000000-0000-0000-0000-measure00001"/>
        <resource>
            <Measure xmlns="http://hl7.org/fhir">
                <status value="active"/>
                <library value="urn:uuid:00000000-0000-0000-0000-library00001"/>
                <scoring>
                    <coding>
                        <system value="http://terminology.hl7.org/CodeSystem/measure-scoring"/>
                        <code value="cohort"/>
                    </coding>
                </scoring>
                <group>
                    <population>
                        <code>
                            <coding>
                                <system value="http://terminology.hl7.org/CodeSystem/measure-population"/>
                                <code value="initial-population"/>
                            </coding>
                        </code>
                        <criteria>
                            <language value="text/cql"/>
                            <expression value="InInitialPopulation"/>
                        </criteria>
                    </population>
                </group>
            </Measure>
        </resource>
        <request>
            <method value="POST"/>
            <url value="Measure"/>
        </request>
    </entry>
    </Bundle>
  2. Evaluate the Measure resource using http://localhost:8080/fhir/Measure/{id}/$evaluate-measure.

Expected behavior:

The Result should be a MeasureReport resource like (depending on the number of male patients on the server):

{
    "resourceType": "MeasureReport",
    "status": "complete",
    "type": "summary",
    "measure": "Measure/3",
    "group": [
        {
            "population": [
                {
                    "code": {
                        "coding": [
                            {
                                "system": "http://terminology.hl7.org/CodeSystem/measure-population",
                                "code": "initial-population"
                            }
                        ]
                    },
                    "count": 1
                }
            ]
        }
    ],
    "evaluatedResource": [
        {
            "reference": "#Patient/1"
        }
    ]
}

Environment:

JohannesOehm commented 2 years ago

This issue is probably related: https://github.com/hapifhir/hapi-fhir/issues/4025

DWay17 commented 1 year ago

+1

tonyashm commented 1 year ago

+1

JPercival commented 1 year ago

Should be resolved with #4347. Feel free to reopen if the issue re-occurs.

wetret commented 1 year ago

I tried running CQL on the new Docker image hapiproject/hapi:v6.4.0. I added the new HAPI_FHIR_CR_ENABLED: "true" environment variable to the docker-compose file. But it seems that CQL is not enabled, because I get the following response evaluating a Measure resource with http://localhost:8080/fhir/Measure/3/$evaluate-measure:

{
  "resourceType": "OperationOutcome",
  "issue": [ {
    "severity": "error",
    "code": "not-supported",
    "diagnostics": "Invalid request: The FHIR endpoint on this server does not know how to handle GET operation[Measure/3/$evaluate-measure] with parameters [[]]"
  } ]
}

What am I missing?

Unfortunately I do not have the privileges to reopen the issue. Could you do that for me @JPercival ?

alackerbauer commented 1 year ago

This seems like a problem that has been reported here: https://github.com/hapifhir/hapi-fhir-jpaserver-starter/issues/501

Likely, when you run a request to inspect the server's metadata, the CQL operations are unknown to the server and therefore none of them can be used, including $evaluate-measure.

wilson-tyler commented 1 year ago

Is there any movement on this? We are experiencing the same responses as @wetret when attempting to evaluate a measure with $evaluate-measure. We are on hapi:v6.4.4 with cr_enabled = true. Also successfully seeing the service log of Registering CQL Provider.

jadeite1000 commented 11 months ago

Hi All, I am using smilecdr202308r02, I am getting the following error in postman when I submit a bundle transaction questionnaire request but get the below error:

{ "resourceType": "OperationOutcome", "issue": [ { "severity": "error", "code": "processing", "diagnostics": "HAPI-0389: Failed to call access method: java.lang.RuntimeException: java.net.ConnectException: Connection refused" } ] }