Skip to content

Commit

Permalink
chore: add FHIR observations API pagination
Browse files Browse the repository at this point in the history
- configures pagination to the following APIs
  - getPatientTemperatureEntries
  - getPatientBloodPressureEntries
  - getPatientHeightEntries
  - getPatientHeightEntries
  - getPatientPulseRateEntries
  - getPatientBMIEntries
  - getPatientWeightEntries

Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Apr 27, 2023
1 parent 431fab0 commit a6def60
Show file tree
Hide file tree
Showing 17 changed files with 1,792 additions and 1,295 deletions.
26 changes: 8 additions & 18 deletions pkg/clinical/domain/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package domain
import (
"time"

"github.com/savannahghi/firebasetools"
"github.com/savannahghi/scalarutils"
)

Expand Down Expand Up @@ -407,21 +406,12 @@ type FHIRObservationReferencerangeInput struct {
Text *string `json:"text,omitempty"`
}

// FHIRObservationRelayConnection is a Relay connection for Observation
type FHIRObservationRelayConnection struct {
Edges []*FHIRObservationRelayEdge `json:"edges,omitempty"`

PageInfo *firebasetools.PageInfo `json:"pageInfo,omitempty"`
}

// FHIRObservationRelayEdge is a Relay edge for Observation
type FHIRObservationRelayEdge struct {
Cursor *string `json:"cursor,omitempty"`

Node *FHIRObservation `json:"node,omitempty"`
}

// FHIRObservationRelayPayload is used to return single instances of Observation
type FHIRObservationRelayPayload struct {
Resource *FHIRObservation `json:"resource,omitempty"`
// PagedFHIRAllergy is an allergy's paginaton dataclass
type PagedFHIRObservations struct {
Observations []FHIRObservation
HasNextPage bool
NextCursor string
HasPreviousPage bool
PreviousCursor string
TotalCount int
}
42 changes: 25 additions & 17 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (fh StoreImpl) SearchPatientObservations(
observationCode string,
tenant dto.TenantIdentifiers,
pagination dto.Pagination,
) ([]*domain.FHIRObservation, error) {
) (*domain.PagedFHIRObservations, error) {
params := map[string]interface{}{
"patient": patientReference,
"code": observationCode,
Expand All @@ -80,7 +80,14 @@ func (fh StoreImpl) SearchPatientObservations(
return nil, err
}

output := []*domain.FHIRObservation{}
observationOutput := domain.PagedFHIRObservations{
Observations: []domain.FHIRObservation{},
HasNextPage: observations.HasNextPage,
NextCursor: observations.NextCursor,
HasPreviousPage: observations.HasPreviousPage,
PreviousCursor: observations.PreviousCursor,
TotalCount: observations.TotalCount,
}

for _, obs := range observations.Resources {
var observation domain.FHIRObservation
Expand All @@ -95,10 +102,10 @@ func (fh StoreImpl) SearchPatientObservations(
return nil, fmt.Errorf("unable to unmarshal resource: %w", err)
}

output = append(output, &observation)
observationOutput.Observations = append(observationOutput.Observations, observation)
}

return output, nil
return &observationOutput, nil
}

// Encounters returns encounters that belong to the indicated patient.
Expand Down Expand Up @@ -1081,14 +1088,21 @@ func (fh StoreImpl) DeleteFHIRMedicationRequest(_ context.Context, id string) (b
}

// SearchFHIRObservation provides a search API for FHIRObservation
func (fh StoreImpl) SearchFHIRObservation(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.FHIRObservationRelayConnection, error) {
output := domain.FHIRObservationRelayConnection{}

func (fh StoreImpl) SearchFHIRObservation(_ context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error) {
resources, err := fh.Dataset.SearchFHIRResource(observationResourceType, params, tenant, pagination)
if err != nil {
return nil, err
}

observationOutput := domain.PagedFHIRObservations{
Observations: []domain.FHIRObservation{},
HasNextPage: resources.HasNextPage,
NextCursor: resources.NextCursor,
HasPreviousPage: resources.HasPreviousPage,
PreviousCursor: resources.PreviousCursor,
TotalCount: resources.TotalCount,
}

for _, result := range resources.Resources {
var resource domain.FHIRObservation

Expand All @@ -1103,16 +1117,14 @@ func (fh StoreImpl) SearchFHIRObservation(_ context.Context, params map[string]i
"server error: Unable to unmarshal %s: %w", observationResourceType, err)
}

output.Edges = append(output.Edges, &domain.FHIRObservationRelayEdge{
Node: &resource,
})
observationOutput.Observations = append(observationOutput.Observations, resource)
}

return &output, nil
return &observationOutput, nil
}

// CreateFHIRObservation creates a FHIRObservation instance
func (fh StoreImpl) CreateFHIRObservation(_ context.Context, input domain.FHIRObservationInput) (*domain.FHIRObservationRelayPayload, error) {
func (fh StoreImpl) CreateFHIRObservation(_ context.Context, input domain.FHIRObservationInput) (*domain.FHIRObservation, error) {
payload, err := converterandformatter.StructToMap(input)
if err != nil {
return nil, fmt.Errorf("unable to turn %s input into a map: %w", observationResourceType, err)
Expand All @@ -1125,11 +1137,7 @@ func (fh StoreImpl) CreateFHIRObservation(_ context.Context, input domain.FHIROb
return nil, fmt.Errorf("unable to create/update %s resource: %w", observationResourceType, err)
}

output := &domain.FHIRObservationRelayPayload{
Resource: resource,
}

return output, nil
return resource, nil
}

// DeleteFHIRObservation deletes the FHIRObservation identified by the passed ID
Expand Down
Loading

0 comments on commit a6def60

Please sign in to comment.