hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.01k stars 1.32k forks source link

Observation cannot be filtered by subject anymore (After upgrade to 5.7.0) #3407

Open ZuSe opened 2 years ago

ZuSe commented 2 years ago

After upgrading to 5.7.0 (latest jpa), the Observation resources can not be filtered by the subject param.

e.g. https://fhir.myserver.com/fhir/Observation?subject=Patient/82cd5a7a-002c-11ec-939e-b516e27a5512

returns 0 entries (even though the patient has some)

same goes for: https://fhir.myserver.com/fhir/Observation?patient=82cd5a7a-002c-11ec-939e-b516e27a5512

FHIR Version: R5 HAPI: 5.7.0 OS: Kubernetes (JPA Starter)

ZuSe commented 2 years ago

Steps to reproduce:

  1. Get latest jpa-starter (https://github.com/hapifhir/hapi-fhir-jpaserver-starter)

  2. Configure it to use a postgresql database, R5 version and leave the rest on default

  3. Set ID mode to support UUIDs/Alphanumeric. put this in JpaRestfulServer:

        this.daoConfig.setResourceClientIdStrategy(DaoConfig.ClientIdStrategyEnum.ANY);
        this.daoConfig.setResourceServerIdStrategy(DaoConfig.IdStrategyEnum.UUID);
        this.daoConfig.setHistoryCountMode(HistoryCountModeEnum.COUNT_ACCURATE);
  4. Create a new observation resource e.g. { "resourceType": "Observation", "identifier": [ { "use": "secondary", "system": "https://dcmgsmh3hc.hub.doc-cirrus.com/meddata/", "value": "6141dd3fd1c1c1098bb3b2c7" }, { "use": "usual", "value": "iatros-fhir-connector" } ], "status": "registered", "category": [ { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "vital-signs" } ] } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "41950-7" } ] }, "subject": { "reference": "Patient/82cd5a7a-002c-11ec-939e-b516e27a5512" }, "effectiveDateTime": "2021-09-13T22:00:00.000Z", "performer": [ { "reference": "Practitioner/2ce4a60e-713b-4bb9-a61c-d27b08180914" } ], "valueQuantity": { "value": 5309, "unit": "count", "system": "http://unitsofmeasure.org", "code": "[count]" } }

  5. Kill the server

  6. Try to filter it: http://localhost:8080/fhir/Observation?subject=Patient/82cd5a7a-002c-11ec-939e-b516e27a5512

  7. Returns 0

ZuSe commented 2 years ago

I tested it with R4 context and jetty. Same behavior. Running out of ideas what might cause it. Appreciate any help @jamesagnew @jkiddo @tadgh

tadgh commented 2 years ago

Heya, I cannot replicate this on current master. Just did the following:

  1. Pulled hapi-fhir-jpaserver-starter master (currently pointing to 5.7.0)
  2. Setup with local postgres
  3. create a patient with the above id,
  4. Create an observation with that patient as the subject
  5. execute: http://localhost:8080/fhir/Observation?subject=Patient/82cd5a7a-002c-11ec-939e-b516e27a5512
  6. Results are returned for me (1 result, specifically).

If you can write a failling unit test showing the replication, happy to look at it.

ZuSe commented 2 years ago

Hi @tadgh

thanks for investigating. Unfortunately I forgot to add sth. to my steps. I just double checked the issue on a Mac of a colleague. You need to add this to settings:

enforce_referential_integrity_on_delete: false enforce_referential_integrity_on_write: false

so basically create the Observation I posted WITHOUT the patient entry existing on the system. I guess you just followed my flow but by instinct created the patient beforehand, right?

Observations with existing Patient or Prac. references do work, that's what I can confirm. However, filtering for non existent one worked before as well and is crucial if the objects aren't managed within FHIR.