aktin/dwh-import

Return meaningful error response instead of Internal Server Error on patient ID mismatch

Open

#30 opened on Mar 6, 2026

 (0 comments) (0 reactions) (0 assignees)XSLT (0 forks)auto 404
enhancementgood first issue

Repository metrics

Stars
 (0 stars)
PR merge metrics
 (PR metrics pending)

Description

Description When a CDA document is imported for an existing encounter (same encounter ID) but with a different patient ID, the importer throws an unhandled AssertionError, resulting in an HTTP 500 Internal Server Error. The error should instead be caught and returned as a meaningful, human-readable rejection message (e.g., HTTP 409 Conflict or 422 Unprocessable Entity).

Steps to Reproduce Import a CDA document with patient ID 1234567890 and encounter ID 987654321-01 Import a second CDA document with a different patient ID 3412567890 but the same encounter ID 987654321-01

Current Behavior The server responds with HTTP 500 and the following unhandled exception:

java.lang.AssertionError: Patient_num mismatch between observation and visit
    at de.sekmi.histream.i2b2.PostgresVisitStore.getOrCreateInstance(PostgresVisitStore.java:459)
    at de.sekmi.histream.i2b2.PostgresVisitStore.createInstance(PostgresVisitStore.java:527)
    ...

Expected Behavior The importer should catch the patient ID mismatch condition and return an appropriate HTTP error status (e.g., 409 or 422) with a clear message indicating that the submitted CDA was rejected because the patient ID is inconsistent with the existing visit metadata.

Context The rejection itself is correct behavior asa retroactive update of the patient ID for an existing visit is not supported.

Contributor guide