-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[7269] bulk export history fails with client-assigned string IDs #7300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[7269] bulk export history fails with client-assigned string IDs #7300
Conversation
Formatting check succeeded! |
...ources/ca/uhn/hapi/fhir/changelog/8_6_0/7296-bulk-export-fails-with-string-resource-ids.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a suggestion on the changelog. Other than that, looks good to me!
Requires a senior+ approval
…_6_0/7296-bulk-export-fails-with-string-resource-ids.yaml Co-authored-by: jdar8 <69840459+jdar8@users.noreply.github.com>
// Create version 2 | ||
patient2.getNameFirstRep().setFamily("SmithV2"); | ||
myClient.update().resource(patient2).execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem: I don't trust this test. Can you show some Observations with a client assigned id connected to the Patient, and test this with Group export?
List<String> idList = | ||
typePidJsonList.stream().map(TypedPidJson::getPid).toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem: this looks wrong. pids are our internal primary key which is a Long. Flattening these to a string will work for numeric ids, but not for client-assigned ids.
I think this call chain is broken. We do bulk-export in PID space, not FHIR-id space, for performance reasons. But the main IFhirResourceDao interface is all FHIR-id space. We can't use it unless we make a database round-trip to resolve pids back to FHIR-ids. see IIdHelperService.translatePidsToFhirResourceIds.
Alternatively, you could bypass IFhirResourceDao and talk to the PID-based layer. See this call in the history path -
hapi-fhir/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java
Lines 1387 to 1396 in 2d5d092
return myPersistedJpaBundleProviderFactory.history( | |
theRequest, | |
myResourceName, | |
entity.getResourceId(), | |
theHistorySearchDateRangeParam.getLowerBoundAsInstant(), | |
theHistorySearchDateRangeParam.getUpperBoundAsInstant(), | |
theHistorySearchDateRangeParam.getOffset(), | |
theHistorySearchDateRangeParam.getHistorySearchType(), | |
requestPartitionId); | |
}); |
The downside of that is you'll need to introduce a Mongo abstraction, and implement both sides.
@@ -0,0 +1,5 @@ | |||
--- | |||
type: fix | |||
issue: 7296 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have an upstream JIRA, we add that here.
issue: 7296 | |
issue: 7296 | |
jira: SMILE-blah-blah | |
Issue
Bulk export with
_includeHistory=true
fails to export history records for resources that have client-assigned string IDs (forced IDs). The exportcompletes successfully but history versions are missing from the output for any resources with client-assigned IDs.
Cause
When performing a bulk export with history enabled, the
processHistoryResources()
method was converting resource PIDs to their forced ID strings viaconvertToStringIds()
before querying for history. However, history records in the database are indexed by numeric PIDs, not forced IDs. This causesthe history query (
IBulkDataExportHistoryHelper.fetchHistoryForResourceIds()
) to return no results for resources with client-assigned IDs.Fix
Modified
ExpandResourceAndWriteBinaryStep.processHistoryResources()
(line 225) to use numeric PIDs directly by callingtypePidJsonList.stream().map(TypedPidJson::getPid).toList()
instead ofconvertToStringIds()
. The bulk export history helper can work with PIDsnatively, making the forced ID conversion unnecessary and incorrect for history queries.
Added test
testSystemBulkExportWithHistory_WithClientAssignedIds()
that validates all history versions are exported for resources with forced IDs.Closes #7296