Skip to content

Commit

Permalink
feat: patch patient BMI observation (#304)
Browse files Browse the repository at this point in the history
- This patches patient's BMI entries
  • Loading branch information
EspiraMarvin committed Jan 22, 2024
1 parent ef18cc5 commit 490f193
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,5 @@ extend type Mutation {

patchPatientHeight(id: String!, value: String!): Observation!
patchPatientWeight(id: String!, value: String!): Observation!
patchPatientBMI(id: String!, value: String!): Observation!
}
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.

117 changes: 117 additions & 0 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 @@ -72,6 +72,11 @@ func (c *UseCasesClinicalImpl) PatchPatientWeight(ctx context.Context, id string
return c.PatchPatientObservations(ctx, id, value)
}

// PatchPatientBMI patches the BMI record of a patient
func (c *UseCasesClinicalImpl) PatchPatientBMI(ctx context.Context, id string, value string) (*dto.Observation, error) {
return c.PatchPatientObservations(ctx, id, value)
}

// RecordWeight records a patient's weight
func (c *UseCasesClinicalImpl) RecordWeight(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error) {
weightObservation, err := c.RecordObservation(ctx, input, common.WeightCIELTerminologyCode)
Expand Down
130 changes: 130 additions & 0 deletions pkg/clinical/usecases/clinical/observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3094,6 +3094,136 @@ func TestUseCasesClinicalImpl_GetPatientBMIEntries(t *testing.T) {
}
}

func TestUseCasesClinicalImpl_PatchPatientBMI(t *testing.T) {
type args struct {
ctx context.Context
id string
value string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy Case - successfully patch patient observation",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "18.21",
},
wantErr: false,
},
{
name: "Sad Case - missing observation ID",
args: args{
ctx: context.Background(),
value: "20.9",
},
wantErr: true,
},
{
name: "Sad Case - Fail validation nil value",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "",
},
wantErr: true,
},
{
name: "Sad Case - fail to get observation",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "20.9",
},
wantErr: true,
},
{
name: "Sad Case: fail to get encounter",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "20.9",
},
wantErr: true,
},
{
name: "Sad Case: fail on finished encounter",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "20.9",
},
wantErr: true,
},
{
name: "Sad Case - fail to patch patient bmi observation",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "20.9",
},
wantErr: true,
},
}
for _, tt := range tests {
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 - fail to get observation" {
fakeFHIR.MockGetFHIRObservationFn = func(ctx context.Context, id string) (*domain.FHIRObservationRelayPayload, error) {
return nil, fmt.Errorf("an error occurred")
}
}

if tt.name == "Sad Case: fail to get encounter" {
fakeFHIR.MockGetFHIREncounterFn = func(ctx context.Context, id string) (*domain.FHIREncounterRelayPayload, error) {
return nil, fmt.Errorf("an error occurred")
}
}

if tt.name == "Sad Case: fail on finished encounter" {
fakeFHIR.MockGetFHIREncounterFn = func(ctx context.Context, id string) (*domain.FHIREncounterRelayPayload, error) {
UUID := uuid.New().String()
PatientRef := "Patient/" + uuid.NewString()
return &domain.FHIREncounterRelayPayload{
Resource: &domain.FHIREncounter{
ID: &UUID,
Text: &domain.FHIRNarrative{},
Identifier: []*domain.FHIRIdentifier{},
Status: domain.EncounterStatusEnum(domain.EncounterStatusEnumFinished),
Subject: &domain.FHIRReference{
ID: &UUID,
Reference: &PatientRef,
},
},
}, nil
}
}

if tt.name == "Sad Case - fail to patch patient bmi observation" {
fakeFHIR.MockPatchFHIRObservationFn = func(ctx context.Context, id string, input domain.FHIRObservationInput) (*domain.FHIRObservation, error) {
return nil, fmt.Errorf("an error occurred")
}
}

_, err := u.PatchPatientBMI(tt.args.ctx, tt.args.id, tt.args.value)
if (err != nil) != tt.wantErr {
t.Errorf("UseCasesClinicalImpl.PatchPatientBMI() error = %v, wantErr %v", err, tt.wantErr)
return
}
}
}

func TestUseCasesClinicalImpl_GetPatientWeightEntries(t *testing.T) {
first := 10
ctx := context.Background()
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 @@ -88,6 +88,7 @@ type Clinical interface {
PatchPatientObservations(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientHeight(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientWeight(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientBMI(ctx context.Context, id string, value string) (*dto.Observation, error)
}

// Interactor is an implementation of the usecases interface
Expand Down

0 comments on commit 490f193

Please sign in to comment.