Skip to content

fix(fhir search): skip untranslatable MPI patients so one bad record doesn't fail the whole search - #73

Merged
mherman22 merged 1 commit into
mainfrom
fix/mpi-search-resilient-translation
Jul 20, 2026
Merged

mherman22 merged 1 commit into
mainfrom
fix/mpi-search-resilient-translation

Conversation

@mherman22

Copy link
Copy Markdown

Problem

FHIR-mode MPI search (searchPatient → getMpiPatientMatches) fails wholesale whenever a single linked source patient can't be translated. In production, searchMpi from the EMR returned mpiError: true even though both OpenCR requests succeeded (verified via the OpenHIM transaction log):

GET /CR/fhir/Patient?family:contains=Pierre&_format=json                      -> 200
GET /CR/fhir/Patient?_id=<golden uuids>&_include=Patient:link&_format=json     -> 200

Auth, endpoints and queries are all fine — the exception is thrown in Java, while translating a linked source patient via patientTranslator.toOpenmrsType(...) (e.g. a cross-facility record whose identifier type/system isn't resolvable locally). Because the translation loop had no per-record guard, one bad patient aborted the entire result set.

Fix

Wrap each linked source patient's translation in its own try/catch. A record that fails to translate is now logged (with its reference) and skipped, so the search returns every patient that does translate instead of failing completely. The log line also surfaces the exact translation defect for follow-up.

Testing

  • mvn clean package builds green.
  • Reproduced the two OpenCR requests directly (both 200) to confirm the failure is in translation, not transport/auth.

@mherman22
mherman22 merged commit 980d77c into main Jul 20, 2026
1 check passed
@mherman22
mherman22 deleted the fix/mpi-search-resilient-translation branch July 20, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant