@@ -482,7 +482,7 @@ constructor(
482
482
.toRequestBody(NetworkModule .JSON_MEDIA_TYPE ),
483
483
)
484
484
485
- processResultBundleEntries(resultBundle, patientRelatedResourceTypes)
485
+ processResultBundleEntries(resultBundle.entry , patientRelatedResourceTypes)
486
486
487
487
return resultBundle
488
488
}
@@ -492,23 +492,36 @@ constructor(
492
492
searchPath : String ,
493
493
patientRelatedResourceTypes : MutableList <ResourceType >,
494
494
) {
495
- val resultBundle =
496
- if (gatewayModeHeaderValue.isNullOrEmpty()) {
497
- fhirResourceDataSource.getResource(searchPath)
498
- } else
499
- fhirResourceDataSource.getResourceWithGatewayModeHeader(
500
- gatewayModeHeaderValue,
501
- searchPath,
502
- )
495
+ val resultBundle = fetchResourceBundle(gatewayModeHeaderValue, searchPath)
496
+ val nextPageUrl = resultBundle.getLink(PAGINATION_NEXT )?.url ? : " "
497
+
498
+ processResultBundleEntries(resultBundle.entry, patientRelatedResourceTypes)
499
+
500
+ if (nextPageUrl.isNotEmpty()) {
501
+ processCompositionManifestResources(
502
+ gatewayModeHeaderValue,
503
+ nextPageUrl,
504
+ patientRelatedResourceTypes,
505
+ )
506
+ }
507
+ }
503
508
504
- processResultBundleEntries(resultBundle, patientRelatedResourceTypes)
509
+ private suspend fun fetchResourceBundle (
510
+ gatewayModeHeaderValue : String? ,
511
+ searchPath : String ,
512
+ ): Bundle {
513
+ return if (gatewayModeHeaderValue.isNullOrEmpty()) {
514
+ fhirResourceDataSource.getResource(searchPath)
515
+ } else {
516
+ fhirResourceDataSource.getResourceWithGatewayModeHeader(gatewayModeHeaderValue, searchPath)
517
+ }
505
518
}
506
519
507
520
private suspend fun processResultBundleEntries (
508
- resultBundle : Bundle ,
521
+ resultBundleEntries : List < Bundle . BundleEntryComponent > ,
509
522
patientRelatedResourceTypes : MutableList <ResourceType >,
510
523
) {
511
- resultBundle.entry? .forEach { bundleEntryComponent ->
524
+ resultBundleEntries .forEach { bundleEntryComponent ->
512
525
when (bundleEntryComponent.resource) {
513
526
is Bundle -> {
514
527
val bundle = bundleEntryComponent.resource as Bundle
@@ -711,7 +724,8 @@ constructor(
711
724
resourceGroup.value.forEach {
712
725
processCompositionManifestResources(
713
726
gatewayModeHeaderValue = FHIR_GATEWAY_MODE_HEADER_VALUE ,
714
- searchPath = " ${resourceGroup.key} /${it.focus.extractId()} " ,
727
+ searchPath =
728
+ " ${resourceGroup.key} ?$ID =${it.focus.extractId()} &_page=1&_count=$DEFAULT_COUNT " ,
715
729
patientRelatedResourceTypes = patientRelatedResourceTypes,
716
730
)
717
731
}
@@ -770,6 +784,7 @@ constructor(
770
784
const val ORGANIZATION = " organization"
771
785
const val TYPE_REFERENCE_DELIMITER = " /"
772
786
const val DEFAULT_COUNT = 200
787
+ const val PAGINATION_NEXT = " next"
773
788
774
789
/* *
775
790
* The list of resources whose types can be synced down as part of the Composition configs.
0 commit comments