Skip to content

Commit

Permalink
feat: get patient's temperature entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Mar 23, 2023
1 parent a1f6067 commit 6783a10
Show file tree
Hide file tree
Showing 11 changed files with 523 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Run tests
run: |
go-acc -o coverage.txt --ignore generated,cmd ./... -- -timeout 60m
go-acc -o coverage.txt --ignore generated,cmd,graph ./... -- -timeout 60m
grep -v "generated.go" coverage.txt | grep -v "_gen.go" | grep -v "_mock.go" | grep -v "*mock.go" | grep -v "mocks.go" | grep -v "*resolver*go" | grep -v "server.go" > coverage.out
go tool cover -html=coverage.out -o coverage.html
gocov convert coverage.out > coverage.json
Expand Down
38 changes: 38 additions & 0 deletions pkg/clinical/infrastructure/datastore/cloudhealthcare/fhir.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,44 @@ func NewFHIRStoreImpl(
}
}

// SearchPatientObservations fetches all observations that belong to a specific patient
func (fh StoreImpl) SearchPatientObservations(
_ context.Context,
patientReference string,
observationCode string,
tenant dto.TenantIdentifiers,
) ([]*domain.FHIRObservation, error) {
params := map[string]interface{}{
"patient": patientReference,
"code": observationCode,
}

observations, err := fh.Dataset.SearchFHIRResource(observationResourceType, params, tenant)
if err != nil {
return nil, err
}

output := []*domain.FHIRObservation{}

for _, obs := range observations {
var observation domain.FHIRObservation

resourceBs, err := json.Marshal(obs)
if err != nil {
return nil, fmt.Errorf("unable to marshal resource to JSON: %w", err)
}

err = json.Unmarshal(resourceBs, &observation)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal resource: %w", err)
}

output = append(output, &observation)
}

return output, nil
}

// Encounters returns encounters that belong to the indicated patient.
//
// The patientReference should be a [string] in the format "Patient/<patient resource ID>".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3887,3 +3887,59 @@ 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
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy Case - Successfully search patient observation",
args: args{
ctx: ctx,
patientReference: fmt.Sprintf("Patient/%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",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dataset := fakeDataset.NewFakeFHIRRepositoryMock()
fh := FHIR.NewFHIRStoreImpl(dataset)

if tt.name == "Sad Case - fail to search fhir resource" {
dataset.MockSearchFHIRResourceFn = func(resourceType string, params map[string]interface{}, tenant dto.TenantIdentifiers) ([]map[string]interface{}, error) {
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)
if (err != nil) != tt.wantErr {
t.Errorf("StoreImpl.SearchPatientObservations() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && got == nil {
t.Errorf("expected response not to be nil for %v", tt.name)
return
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type FHIRMock struct {
MockPatchFHIRPatientFn func(ctx context.Context, id string, params []map[string]interface{}) (*domain.FHIRPatient, 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) (*domain.PatientConnection, error)
MockSearchPatientObservationsFn func(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers) ([]*domain.FHIRObservation, error)
}

// NewFHIRMock initializes a new instance of FHIR mock
Expand Down Expand Up @@ -466,7 +467,26 @@ func NewFHIRMock() *FHIRMock {
return true, nil
},
MockSearchFHIRObservationFn: func(ctx context.Context, params map[string]interface{}, tenant dto.TenantIdentifiers) (*domain.FHIRObservationRelayConnection, error) {
return &domain.FHIRObservationRelayConnection{}, nil
uuid := uuid.New().String()
finalStatus := domain.ObservationStatusEnumFinal
return &domain.FHIRObservationRelayConnection{
Edges: []*domain.FHIRObservationRelayEdge{
{
Cursor: new(string),
Node: &domain.FHIRObservation{
ID: &uuid,
Status: &finalStatus,
Subject: &domain.FHIRReference{
ID: &uuid,
},
Encounter: &domain.FHIRReference{
ID: &uuid,
},
},
},
},
PageInfo: &firebasetools.PageInfo{},
}, nil
},
MockCreateFHIRObservationFn: func(ctx context.Context, input domain.FHIRObservationInput) (*domain.FHIRObservationRelayPayload, error) {
uuid := uuid.New().String()
Expand Down Expand Up @@ -655,6 +675,33 @@ func NewFHIRMock() *FHIRMock {
PageInfo: &firebasetools.PageInfo{},
}, nil
},
MockSearchPatientObservationsFn: func(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers) ([]*domain.FHIRObservation, error) {
uuid := uuid.New().String()
finalStatus := domain.ObservationStatusEnumFinal
return []*domain.FHIRObservation{{
ID: &uuid,
Status: &finalStatus,
Subject: &domain.FHIRReference{
ID: &uuid,
},
Encounter: &domain.FHIRReference{
ID: &uuid,
},
Code: domain.FHIRCodeableConcept{
ID: new(string),
Coding: []*domain.FHIRCoding{
{
ID: new(string),
Version: new(string),
Code: "",
Display: "Vital",
UserSelected: new(bool),
},
},
Text: "",
},
}}, nil
},
}
}

Expand Down Expand Up @@ -902,3 +949,8 @@ func (fh *FHIRMock) UpdateFHIREpisodeOfCare(ctx context.Context, fhirResourceID
func (fh *FHIRMock) SearchFHIRPatient(ctx context.Context, searchParams string, tenant dto.TenantIdentifiers) (*domain.PatientConnection, error) {
return fh.MockSearchFHIRPatientFn(ctx, searchParams, tenant)
}

// SearchPatientObservations mocks the implementation of searching patient observations
func (fh *FHIRMock) SearchPatientObservations(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers) ([]*domain.FHIRObservation, error) {
return fh.MockSearchPatientObservationsFn(ctx, patientReference, conceptID, tenant)
}
3 changes: 3 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ extend type Query {

# Encounter
listPatientEncounters(patientID: String!): [Encounter!]!

# Observation
getPatientTemperatureEntries(patientID: String!): [Observation!]
}

extend type Mutation {
Expand Down
7 changes: 7 additions & 0 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.

0 comments on commit 6783a10

Please sign in to comment.