Skip to content

Commit

Permalink
feat: patch patient pulse rate observation (#313)
Browse files Browse the repository at this point in the history
- This patches patient's pulse rate entries
  • Loading branch information
EspiraMarvin committed Jan 26, 2024
1 parent c35a4fb commit 005f056
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ extend type Mutation {
patchPatientSystolicBloodPressure(id: String!, value: String!): Observation!
patchPatientRespiratoryRate(id: String!, value: String!): Observation!
patchPatientOxygenSaturation(id: String!, value: String!): Observation!
PatchPatientPulseRate(id: String!, value: String!): Observation!

# Consent
recordConsent(input: ConsentInput!): ConsentOutput!
}
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.

118 changes: 118 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 @@ -102,6 +102,11 @@ func (c *UseCasesClinicalImpl) PatchPatientOxygenSaturation(ctx context.Context,
return c.PatchPatientObservations(ctx, id, value)
}

// PatchPatientPulseRate patches the pulse rate record of a patient
func (c *UseCasesClinicalImpl) PatchPatientPulseRate(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 @@ -1426,6 +1426,136 @@ func TestUseCasesClinicalImpl_RecordPulseRate(t *testing.T) {
}
}

func TestUseCasesClinicalImpl_PatchPatientPulseRate(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: "80",
},
wantErr: false,
},
{
name: "Sad Case - missing observation ID",
args: args{
ctx: context.Background(),
value: "80",
},
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: "80",
},
wantErr: true,
},
{
name: "Sad Case: fail to get encounter",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "80",
},
wantErr: true,
},
{
name: "Sad Case: fail on finished encounter",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "80",
},
wantErr: true,
},
{
name: "Sad Case - fail to patch patient pulse rate observation",
args: args{
ctx: context.Background(),
id: gofakeit.UUID(),
value: "80",
},
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 pulse rate observation" {
fakeFHIR.MockPatchFHIRObservationFn = func(ctx context.Context, id string, input domain.FHIRObservationInput) (*domain.FHIRObservation, error) {
return nil, fmt.Errorf("an error occurred")
}
}

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

func TestUseCasesClinicalImpl_RecordBloodPressure(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 @@ -96,6 +96,7 @@ type Clinical interface {
PatchPatientSystolicBloodPressure(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientRespiratoryRate(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientOxygenSaturation(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientPulseRate(ctx context.Context, id string, value string) (*dto.Observation, error)

// Questionnaire
CreateQuestionnaire(ctx context.Context, questionnaireInput *domain.FHIRQuestionnaire) (*domain.FHIRQuestionnaire, error)
Expand Down

0 comments on commit 005f056

Please sign in to comment.