Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/srdc/onfhir
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncay Namli committed Sep 10, 2024
2 parents 9e81bfe + 6910022 commit e4e4a3c
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,18 @@ case class OnFhirNetworkClient(serverBaseUrl:String, interceptors:Seq[IHttpReque
override def next[T <: FHIRPaginatedBundle](bundle: T): Future[T] = {
val nextPageParams = Uri.apply(bundle.getNext()).query().toMultiMap
val previousPageParams = bundle.request.request.queryParams
// Identify the pagination parameter by comparing the "next" link's parameters with the previous request's parameters
val paginationParam =
nextPageParams.find {
case (pn, pv) => !previousPageParams.contains(pn) || previousPageParams(pn).toSet != pv.toSet
}.getOrElse(throw FhirClientException(s"Problem in response no pagination param found in response!"))
case (pn, pv) =>
// Check if the parameter is either "_page" or "_skip"
(pn.contentEquals("_page") || pn.contentEquals("_skip")) &&
// Ensure that either the parameter does not exist in the previous request,
// or it has a different value compared to the "next" link's parameter
(!previousPageParams.contains(pn) || previousPageParams(pn).toSet != pv.toSet)
}
// If no pagination parameter is found, throw an exception indicating a problem with the FHIR client response
.getOrElse(throw FhirClientException(s"Problem in response no pagination param found in response!"))

//Set the new page
bundle.request match {
Expand Down

0 comments on commit e4e4a3c

Please sign in to comment.