Skip to content

Commit

Permalink
query observations with encounterID filter (#290)
Browse files Browse the repository at this point in the history
* query observations with encounterID filter

* updates
  • Loading branch information
EspiraMarvin committed Dec 1, 2023
1 parent 3e6e888 commit 7909635
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 305 deletions.
10 changes: 2 additions & 8 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ func NewFHIRStoreImpl(
// SearchPatientObservations fetches all observations that belong to a specific patient
func (fh StoreImpl) SearchPatientObservations(
_ context.Context,
patientReference string,
observationCode string,
searchParameters map[string]interface{},
tenant dto.TenantIdentifiers,
pagination dto.Pagination,
) (*domain.PagedFHIRObservations, error) {
params := map[string]interface{}{
"patient": patientReference,
"code": observationCode,
}

observations, err := fh.Dataset.SearchFHIRResource(observationResourceType, params, tenant, pagination)
observations, err := fh.Dataset.SearchFHIRResource(observationResourceType, searchParameters, tenant, pagination)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4053,11 +4053,10 @@ func TestStoreImpl_EndEpisode(t *testing.T) {
func TestStoreImpl_SearchPatientObservations(t *testing.T) {
ctx := context.Background()
type args struct {
ctx context.Context
patientReference string
observationCode string
tenant dto.TenantIdentifiers
pagination dto.Pagination
ctx context.Context
params map[string]interface{}
tenant dto.TenantIdentifiers
pagination dto.Pagination
}
tests := []struct {
name string
Expand All @@ -4067,18 +4066,24 @@ func TestStoreImpl_SearchPatientObservations(t *testing.T) {
{
name: "Happy Case - Successfully search patient observation",
args: args{
ctx: ctx,
patientReference: fmt.Sprintf("Patient/%s", gofakeit.UUID()),
observationCode: "5088",
ctx: ctx,
params: map[string]interface{}{
"patient": fmt.Sprintf("Patient/%s", gofakeit.UUID()),
"encounter": fmt.Sprintf("Encounter/%s", gofakeit.UUID()),
"observationCode": "5088",
},
},
wantErr: false,
},
{
name: "Sad Case - fail to search fhir resource",
args: args{
ctx: ctx,
patientReference: fmt.Sprintf("Patient/%s", gofakeit.UUID()),
observationCode: "5088",
ctx: ctx,
params: map[string]interface{}{
"patient": fmt.Sprintf("Patient/%s", gofakeit.UUID()),
"encounter": fmt.Sprintf("Encounter/%s", gofakeit.UUID()),
"observationCode": "5088",
},
},
wantErr: true,
},
Expand All @@ -4093,8 +4098,7 @@ func TestStoreImpl_SearchPatientObservations(t *testing.T) {
return nil, fmt.Errorf("failed to search observation resource")
}
}

got, err := fh.SearchPatientObservations(tt.args.ctx, tt.args.patientReference, tt.args.observationCode, tt.args.tenant, tt.args.pagination)
got, err := fh.SearchPatientObservations(tt.args.ctx, tt.args.params, tt.args.tenant, tt.args.pagination)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.SearchPatientObservations() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type FHIRMock struct {
MockPatchFHIREpisodeOfCareFn func(ctx context.Context, id string, input domain.FHIREpisodeOfCareInput) (*domain.FHIREpisodeOfCare, error)
MockUpdateFHIREpisodeOfCareFn func(ctx context.Context, fhirResourceID string, payload map[string]interface{}) (*domain.FHIREpisodeOfCare, error)
MockSearchFHIRPatientFn func(ctx context.Context, searchParams string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PatientConnection, error)
MockSearchPatientObservationsFn func(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error)
MockSearchPatientObservationsFn func(ctx context.Context, searchParameters map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error)
MockGetFHIRAllergyIntoleranceFn func(ctx context.Context, id string) (*domain.FHIRAllergyIntoleranceRelayPayload, error)
MockSearchPatientAllergyIntoleranceFn func(ctx context.Context, patientReference string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRAllergy, error)
MockCreateFHIRMediaFn func(ctx context.Context, input domain.FHIRMedia) (*domain.FHIRMedia, error)
Expand Down Expand Up @@ -1323,7 +1323,7 @@ func NewFHIRMock() *FHIRMock {
PageInfo: &firebasetools.PageInfo{},
}, nil
},
MockSearchPatientObservationsFn: func(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error) {
MockSearchPatientObservationsFn: func(ctx context.Context, searchParameters map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error) {
uuid := uuid.New().String()
instant := gofakeit.TimeZone()
finalStatus := domain.ObservationStatusEnumFinal
Expand Down Expand Up @@ -1663,8 +1663,8 @@ func (fh *FHIRMock) SearchFHIRPatient(ctx context.Context, searchParams string,
}

// SearchPatientObservations mocks the implementation of searching patient observations
func (fh *FHIRMock) SearchPatientObservations(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error) {
return fh.MockSearchPatientObservationsFn(ctx, patientReference, conceptID, tenant, pagination)
func (fh *FHIRMock) SearchPatientObservations(ctx context.Context, searchParameters map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error) {
return fh.MockSearchPatientObservationsFn(ctx, searchParameters, tenant, pagination)
}

// GetFHIRAllergyIntolerance mocks the implementation of getting a resource by its ID
Expand Down
13 changes: 13 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,66 +25,79 @@ extend type Query {
# Observation
getPatientTemperatureEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientBloodPressureEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientHeightEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientRespiratoryRateEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientPulseRateEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientBMIEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientWeightEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientMuacEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientOxygenSaturationEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientViralLoad(
patientID: ID!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientBloodSugarEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientLastMenstrualPeriodEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

getPatientDiastolicBloodPressureEntries(
patientID: String!
encounterID: String
pagination: Pagination!
): ObservationConnection

Expand Down
52 changes: 26 additions & 26 deletions pkg/clinical/presentation/graph/clinical.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7909635

Please sign in to comment.