Skip to content

Commit

Permalink
feat: record pap smear report (#331)
Browse files Browse the repository at this point in the history
- API records the Pap smear results of a patient

Link to documentation: https://savannahghi.atlassian.net/wiki/spaces/OHE/pages/468025506/API+Documentation#Record-PapSmear

Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Jan 30, 2024
1 parent 2eb9765 commit 302fd72
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/clinical/application/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const (

// HPVCIELTerminologyCode is the terminology code used to represent HPV test.
HPVCIELTerminologyCode = "1213"

// PapSmearTerminologyCode is the terminology code used to represent pap smear test.
PapSmearTerminologyCode = "154451"
)

// DefaultIdentifier assigns a patient a code to function as their
Expand Down
2 changes: 2 additions & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ extend type Mutation {
# Visual Inspection with Acetic Acid
recordVIA(input: ObservationInput!): Observation!

recordPapSmear(input: ObservationInput!): Observation!

# Patient
createPatient(input: PatientInput!): Patient!
patchPatient(id: String!, input: PatchPatientInput!): Patient!
Expand Down
7 changes: 7 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.

111 changes: 111 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 @@ -544,3 +544,8 @@ func (c *UseCasesClinicalImpl) RecordHPV(ctx context.Context, input dto.Observat

return c.RecordObservation(ctx, input, common.HPVCIELTerminologyCode, nil)
}

// RecordPapSmear records patients pap smear findings
func (c *UseCasesClinicalImpl) RecordPapSmear(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error) {
return c.RecordObservation(ctx, input, common.PapSmearTerminologyCode, nil)
}
151 changes: 151 additions & 0 deletions pkg/clinical/usecases/clinical/observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6252,3 +6252,154 @@ func TestUseCasesClinicalImpl_RecordHPV(t *testing.T) {
})
}
}

func TestUseCasesClinicalImpl_RecordPapSmear(t *testing.T) {
type args struct {
ctx context.Context
input dto.ObservationInput
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy case: record pap smear",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: "12345678905432345",
Value: "1234",
},
},
wantErr: false,
},
{
name: "Sad case: unable to record pap smear",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: "12345678905432345",
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - Fail to get encounter",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - return a finished encounter",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
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: addTenantIdentifierContext(context.Background()),
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: addTenantIdentifierContext(context.Background()),
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: uuid.New().String(),
Value: "1234",
},
},
wantErr: true,
},
{
name: "Sad Case - Fail to create observation",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: "12345678905432345",
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()
fakePubSub := fakePubSubMock.NewPubSubServiceMock()

fakeUpload := fakeUploadMock.NewFakeUploadMock()

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

if tt.name == "Sad case: unable to record pap smear" {
fakeFHIR.MockGetFHIREncounterFn = func(ctx context.Context, id string) (*domain.FHIREncounterRelayPayload, 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("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) (*domain.Concept, 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.FHIRObservation, error) {
return nil, fmt.Errorf("failed to create observation")
}
}

_, err := u.RecordPapSmear(tt.args.ctx, tt.args.input)
if (err != nil) != tt.wantErr {
t.Errorf("UseCasesClinicalImpl.RecordPapSmear() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
1 change: 1 addition & 0 deletions pkg/clinical/usecases/usecases.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type Clinical interface {
PatchPatientViralLoad(ctx context.Context, id string, value string) (*dto.Observation, error)
PatchPatientMuac(ctx context.Context, id string, value string) (*dto.Observation, error)
RecordHPV(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error)
RecordPapSmear(ctx context.Context, input dto.ObservationInput) (*dto.Observation, error)

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

0 comments on commit 302fd72

Please sign in to comment.