Skip to content

Commit

Permalink
feat: record patient height api
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Mar 21, 2023
1 parent eb74e2b commit 6cba392
Show file tree
Hide file tree
Showing 6 changed files with 283 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 @@ -23,4 +23,5 @@ extend type Mutation {

# Observation
recordTemperature(input: ObservationInput!): Observation!
recordHeight(input: ObservationInput!): 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.

110 changes: 110 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.

10 changes: 10 additions & 0 deletions pkg/clinical/usecases/clinical/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func (c *UseCasesClinicalImpl) RecordTemperature(ctx context.Context, input dto.
return temperatureObservation, nil
}

// RecordHeight records a patient's height and saves it to fhir
func (c *UseCasesClinicalImpl) RecordHeight(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error) {
heightObservation, err := c.RecordObservation(ctx, input, common.HeightCIELTerminologyCode)
if err != nil {
return nil, err
}

return heightObservation, nil
}

func (c *UseCasesClinicalImpl) RecordObservation(ctx context.Context, input dto.ObservationInput, vitalSignConceptID string) (*dto.Observation, error) {
err := input.Validate()
if err != nil {
Expand Down
155 changes: 155 additions & 0 deletions pkg/clinical/usecases/clinical/observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,158 @@ func TestUseCasesClinicalImpl_RecordTemperature(t *testing.T) {
})
}
}

func TestUseCasesClinicalImpl_RecordHeight(t *testing.T) {
ctx := context.Background()
type args struct {
ctx context.Context
input dto.ObservationInput
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy Case - Successfully record height",
args: args{
ctx: ctx,
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "185.21",
},
},
wantErr: false,
},
{
name: "Sad Case - Fail to record height",
args: args{
ctx: ctx,
input: dto.ObservationInput{
EncounterID: uuid.New().String(),
Value: "12",
},
},
wantErr: true,
},
{
name: "Sad Case - Fail to get encounter",
args: args{
ctx: ctx,
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - return a finished encounter",
args: args{
ctx: ctx,
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - Fail to get CIEL concept",
args: args{
ctx: ctx,
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - Fail to get tenant meta tags",
args: args{
ctx: ctx,
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - Fail to create observation",
args: args{
ctx: ctx,
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fakeExt := fakeExtMock.NewFakeBaseExtensionMock()
fakeFHIR := fakeFHIRMock.NewFHIRMock()
fakeOCL := fakeOCLMock.NewFakeOCLMock()
fakeMCH := fakeMyCarehubMock.NewFakeMyCareHubServiceMock()

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

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

if tt.name == "Sad Case - return a finished encounter" {
fakeFHIR.MockGetFHIREncounterFn = func(ctx context.Context, id string) (*domain.FHIREncounterRelayPayload, error) {
return &domain.FHIREncounterRelayPayload{
Resource: &domain.FHIREncounter{
Status: domain.EncounterStatusEnumFinished,
},
}, nil
}
}

if tt.name == "Sad Case - Fail to get CIEL concept" {
fakeOCL.MockGetConceptFn = func(ctx context.Context, org, source, concept string, includeMappings, includeInverseMappings bool) (map[string]interface{}, error) {
return nil, fmt.Errorf("fail to get concept")
}
}

if tt.name == "Sad Case - Fail to get tenant meta tags" {
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 create observation" {
fakeFHIR.MockCreateFHIRObservationFn = func(ctx context.Context, input domain.FHIRObservationInput) (*domain.FHIRObservationRelayPayload, error) {
return nil, fmt.Errorf("failed to create observation")
}
}

got, err := u.RecordHeight(tt.args.ctx, tt.args.input)
if (err != nil) != tt.wantErr {
t.Errorf("UseCasesClinicalImpl.RecordHeight() error = %v, wantErr %v", err, tt.wantErr)
return
}

if !tt.wantErr {
if got == nil {
t.Errorf("expected a response but got %v", got)
return
}
}
})
}
}
1 change: 1 addition & 0 deletions pkg/clinical/usecases/usecases.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Clinical interface {
ListPatientEncounters(ctx context.Context, patientID string) ([]*dto.Encounter, error)

RecordTemperature(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error)
RecordHeight(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error)
RecordObservation(ctx context.Context, input dto.ObservationInput, vitalSignConceptID string) (*dto.Observation, error)
}

Expand Down

0 comments on commit 6cba392

Please sign in to comment.