Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: patch patient temperature observation #305

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ extend type Mutation {
patchPatientHeight(id: String!, value: String!): Observation!
patchPatientWeight(id: String!, value: String!): Observation!
patchPatientBMI(id: String!, value: String!): Observation!
patchPatientTemperature(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 @@ -77,6 +77,11 @@ func (c *UseCasesClinicalImpl) PatchPatientBMI(ctx context.Context, id string, v
return c.PatchPatientObservations(ctx, id, value)
}

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

func TestUseCasesClinicalImpl_PatchPatientTemperature(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 temperature 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 temperature observation" {
fakeFHIR.MockPatchFHIRObservationFn = func(ctx context.Context, id string, input domain.FHIRObservationInput) (*domain.FHIRObservation, error) {
return nil, fmt.Errorf("an error occurred")
}
}

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

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

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