Skip to content

Commit

Permalink
feat: patch patient muac observation
Browse files Browse the repository at this point in the history
- This patches patient's muac entries
  • Loading branch information
EspiraMarvin committed Jan 26, 2024
1 parent b938355 commit 48f9d45
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 @@ -178,6 +178,7 @@ extend type Mutation {
input: PatchCompositionInput!
): Composition!

# Observation
patchPatientHeight(id: String!, value: String!): Observation!
patchPatientWeight(id: String!, value: String!): Observation!
patchPatientBMI(id: String!, value: String!): Observation!
Expand All @@ -188,6 +189,7 @@ extend type Mutation {
patchPatientOxygenSaturation(id: String!, value: String!): Observation!
patchPatientPulseRate(id: String!, value: String!): Observation!
patchPatientViralLoad(id: String!, value: String!): Observation!
patchPatientMuac(id: String!, value: String!): Observation!

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

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 @@ -112,6 +112,11 @@ func (c *UseCasesClinicalImpl) PatchPatientViralLoad(ctx context.Context, id str
return c.PatchPatientObservations(ctx, id, value)
}

// PatchPatientMuac patches the muac record of a patient
func (c *UseCasesClinicalImpl) PatchPatientMuac(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 @@ -4393,6 +4393,136 @@ func TestUseCasesClinicalImpl_GetPatientMuacEntries(t *testing.T) {
}
}

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

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

func TestUseCasesClinicalImpl_GetPatientOxygenSaturationEntries(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 @@ -98,6 +98,7 @@ type Clinical interface {
PatchPatientOxygenSaturation(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientPulseRate(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientViralLoad(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientMuac(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 48f9d45

Please sign in to comment.