Skip to content

Commit

Permalink
adds fetching patient's diastolic blood pressure (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
EspiraMarvin committed Oct 4, 2023
1 parent 21b6ca5 commit 56eefb1
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 22 deletions.
5 changes: 5 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ extend type Query {
pagination: Pagination!
): ObservationConnection

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

# Allergy
searchAllergy(name: String!, pagination: Pagination!): TerminologyConnection
getAllergy(id: ID!): Allergy!
Expand Down
6 changes: 6 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.

166 changes: 144 additions & 22 deletions pkg/clinical/presentation/graph/generated/generated.go

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

5 changes: 5 additions & 0 deletions pkg/clinical/usecases/clinical/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ func (c *UseCasesClinicalImpl) RecordDiastolicBloodPressure(ctx context.Context,
return c.RecordObservation(ctx, input, common.DiastolicBloodPressureCIELTerminologyCode)
}

// GetPatientDiastolicBloodPressureEntries retrieves all diastolic blood pressure entries for a patient
func (c *UseCasesClinicalImpl) GetPatientDiastolicBloodPressureEntries(ctx context.Context, patientID string, pagination *dto.Pagination) (*dto.ObservationConnection, error) {
return c.GetPatientObservations(ctx, patientID, common.DiastolicBloodPressureCIELTerminologyCode, pagination)
}

// RecordObservation is an extracted function that takes any observation input and saves it to FHIR.
// A concept ID is also passed so that we can get the concept code of the passed observation
func (c *UseCasesClinicalImpl) RecordObservation(ctx context.Context, input dto.ObservationInput, vitalSignConceptID string) (*dto.Observation, error) {
Expand Down
121 changes: 121 additions & 0 deletions pkg/clinical/usecases/clinical/observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,127 @@ func TestUseCasesClinicalImpl_RecordDiastolicBloodPressure(t *testing.T) {
})
}
}

func TestUseCasesClinicalImpl_GetPatientDiastolicBloodPressureEntries(t *testing.T) {
ctx := context.Background()
first := 10
type args struct {
ctx context.Context
patientID string
pagination *dto.Pagination
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy Case - Successfully get patient diastolic blood pressure entries",
args: args{
ctx: ctx,
patientID: uuid.New().String(),
pagination: &dto.Pagination{
First: &first,
},
},
wantErr: false,
},
{
name: "Sad Case - Invalid patient ID",
args: args{
ctx: ctx,
patientID: "invalid",
pagination: &dto.Pagination{
First: &first,
},
},
wantErr: true,
},
{
name: "Sad Case - Incorrect patient ID",
args: args{
ctx: ctx,
patientID: gofakeit.UUID(),
pagination: &dto.Pagination{
First: &first,
},
},
wantErr: true,
},
{
name: "Sad Case - fail to get tenant identifiers",
args: args{
ctx: ctx,
patientID: uuid.New().String(),
pagination: &dto.Pagination{
First: &first,
},
},
wantErr: true,
},
{
name: "Sad Case - fail to get patient observations",
args: args{
ctx: ctx,
patientID: uuid.New().String(),
pagination: &dto.Pagination{
First: &first,
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fakeExt := fakeExtMock.NewFakeBaseExtensionMock()
fakeFHIR := fakeFHIRMock.NewFHIRMock()
fakeOCL := fakeOCLMock.NewFakeOCLMock()
fakePubSub := fakePubSubMock.NewPubSubServiceMock()

fakeUpload := fakeUploadMock.NewFakeUploadMock()

infra := infrastructure.NewInfrastructureInteractor(fakeExt, fakeFHIR, fakeOCL, fakeUpload, fakePubSub)
u := clinicalUsecase.NewUseCasesClinicalImpl(infra)

if tt.name == "Sad Case - Invalid patient ID" {
fakeFHIR.MockGetFHIRPatientFn = func(ctx context.Context, id string) (*domain.FHIRPatientRelayPayload, error) {
return nil, fmt.Errorf("an error occurred")
}
}

if tt.name == "Sad Case - Incorrect patient ID" {
fakeFHIR.MockGetFHIRPatientFn = func(ctx context.Context, id string) (*domain.FHIRPatientRelayPayload, error) {
return nil, fmt.Errorf("incorrect patient ID")
}
}

if tt.name == "Sad Case - fail to get tenant identifiers" {
fakeExt.MockGetTenantIdentifiersFn = func(ctx context.Context) (*dto.TenantIdentifiers, error) {
return nil, fmt.Errorf("failed to get tenant identifiers")
}
}

if tt.name == "Sad Case - fail to get patient observations" {
fakeFHIR.MockSearchPatientObservationsFn = func(ctx context.Context, patientReference, conceptID string, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRObservations, error) {
return nil, fmt.Errorf("an error occured")
}
}

got, err := u.GetPatientDiastolicBloodPressureEntries(tt.args.ctx, tt.args.patientID, tt.args.pagination)
if (err != nil) != tt.wantErr {
t.Errorf("UseCasesClinicalImpl.GetPatientDiastolicBloodPressureEntries() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
if got == nil {
t.Errorf("expected a response but got %v", got)
return
}
}
})
}
}

func TestUseCasesClinicalImpl_RecordBMI(t *testing.T) {
ctx := context.Background()
type args struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/clinical/usecases/usecases.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Clinical interface {
GetPatientViralLoad(ctx context.Context, patientID string, pagination *dto.Pagination) (*dto.ObservationConnection, error)
GetPatientBloodSugarEntries(ctx context.Context, patientID string, pagination *dto.Pagination) (*dto.ObservationConnection, error)
GetPatientLastMenstrualPeriodEntries(ctx context.Context, patientID string, pagination *dto.Pagination) (*dto.ObservationConnection, error)
GetPatientDiastolicBloodPressureEntries(ctx context.Context, patientID string, pagination *dto.Pagination) (*dto.ObservationConnection, error)

CreateAllergyIntolerance(ctx context.Context, input dto.AllergyInput) (*dto.Allergy, error)
SearchAllergy(ctx context.Context, name string, pagination dto.Pagination) (*dto.TerminologyConnection, error)
Expand Down

0 comments on commit 56eefb1

Please sign in to comment.