Skip to content

Commit

Permalink
feat: record ultrasound test
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Feb 28, 2024
1 parent 1e7435f commit 1cdd7c1
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/clinical/application/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ const (

// MRITerminologySystem is the terminology code used to represent MRI scan of the breast
MRITerminologySystem = "168651"

// UltrasoundTerminologySystem is the terminology code used to represent left breast ultrasound scan
LeftBreastUltrasoundTerminologySystem = "161289"

// RightBreastUltrasoundTerminologySystem is the terminology code used to represent right breast scan
RightBreastUltrasoundTerminologySystem = "161290"

// BilateralConceptTerminologySystem is the terminology code used to represent miscellaneous bilateral concepts
BilateralConceptTerminologySystem = "160406"
)

// DefaultIdentifier assigns a patient a code to function as their
Expand Down
1 change: 1 addition & 0 deletions pkg/clinical/presentation/graph/clinical.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ extend type Mutation {
recordMammographyResult(input: DiagnosticReportInput!): DiagnosticReport!
recordBiopsy(input: DiagnosticReportInput!): DiagnosticReport!
recordMRI(input: DiagnosticReportInput!): DiagnosticReport!
recordUltrasound(input: DiagnosticReportInput!): DiagnosticReport!

getEncounterAssociatedResources(encounterID: String!): EncounterAssociatedResources!
}
5 changes: 5 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.

21 changes: 21 additions & 0 deletions pkg/clinical/usecases/clinical/diagnostic_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ func (c *UseCasesClinicalImpl) RecordMRI(ctx context.Context, input dto.Diagnost
return c.RecordDiagnosticReport(ctx, common.MRITerminologySystem, input, observationOutput, []DiagnosticReportMutatorFunc{addNuclearMagneticResonanceCategory})
}

// RecordUltrasound is used to record the breast ultrasound diagnostic reports
func (c *UseCasesClinicalImpl) RecordUltrasound(ctx context.Context, input dto.DiagnosticReportInput) (*dto.DiagnosticReport, error) {
err := input.Validate()
if err != nil {
return nil, err
}

observationInput := &dto.ObservationInput{
Status: dto.ObservationStatusFinal,
EncounterID: input.EncounterID,
Value: input.Findings,
}

observationOutput, err := c.RecordObservation(ctx, *observationInput, common.BilateralConceptTerminologySystem, []ObservationInputMutatorFunc{addImagingCategory})
if err != nil {
return nil, err
}

return c.RecordDiagnosticReport(ctx, common.BilateralConceptTerminologySystem, input, observationOutput, []DiagnosticReportMutatorFunc{addRadiologyUltrasoundCategory})
}

// RecordDiagnosticReport is a re-usable method to help with diagnostic report recording
func (c *UseCasesClinicalImpl) RecordDiagnosticReport(ctx context.Context, conceptID string, input dto.DiagnosticReportInput, observation *dto.Observation, mutators []DiagnosticReportMutatorFunc) (*dto.DiagnosticReport, error) {
observationsReference := fmt.Sprintf("Observation/%s", observation.ID)
Expand Down
20 changes: 20 additions & 0 deletions pkg/clinical/usecases/clinical/diagnostic_report_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ var addNuclearMagneticResonanceCategory = func(ctx context.Context, diagnosticRe

return nil
}

// addRadiologyUltrasoundCategory is used to add radiology ultrasound category
var addRadiologyUltrasoundCategory = func(ctx context.Context, diagnosticReport *domain.FHIRDiagnosticReportInput) error {
category := []*domain.FHIRCodeableConceptInput{
{
Coding: []*domain.FHIRCodingInput{
{
System: (*scalarutils.URI)(&diagnosticReportCategorySystem),
Code: scalarutils.Code("RUS"),
Display: "Radiology Ultrasound",
},
},
Text: "Radiology Ultrasound",
},
}

diagnosticReport.Category = append(diagnosticReport.Category, category...)

return nil
}
149 changes: 149 additions & 0 deletions pkg/clinical/usecases/clinical/diagnostic_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,152 @@ func TestUseCasesClinicalImpl_RecordMRI(t *testing.T) {
})
}
}

func TestUseCasesClinicalImpl_RecordUltrasound(t *testing.T) {
type args struct {
ctx context.Context
input dto.DiagnosticReportInput
}
tests := []struct {
name string
args args
want *dto.DiagnosticReport
wantErr bool
}{
{
name: "Happy case: record ultrasound",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.DiagnosticReportInput{
EncounterID: "12345678905432345",
Note: "No lumps felt",
Media: &dto.Media{
URL: gofakeit.URL(),
Name: gofakeit.Name(),
},
Findings: gofakeit.HipsterSentence(20),
},
},
wantErr: false,
},
{
name: "Sad case: unable to record ultrasound results",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.DiagnosticReportInput{
EncounterID: "12345678905432345",
Note: "No lumps felt",
Media: &dto.Media{
URL: gofakeit.URL(),
Name: gofakeit.Name(),
},
Findings: gofakeit.HipsterSentence(20),
},
},
wantErr: true,
},
{
name: "Sad case: fail validation",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.DiagnosticReportInput{
EncounterID: "12345678905432345",
Media: &dto.Media{
URL: gofakeit.URL(),
Name: gofakeit.Name(),
},
},
},
wantErr: true,
},
{
name: "Sad case: unable to record observation",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.DiagnosticReportInput{
EncounterID: "12345678905432345",
Note: "No lumps felt",
Media: &dto.Media{
URL: gofakeit.URL(),
Name: gofakeit.Name(),
},
Findings: gofakeit.HipsterSentence(20),
},
},
wantErr: true,
},
{
name: "Sad case: unable to get tenant identifiers",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.DiagnosticReportInput{
EncounterID: "12345678905432345",
Note: "No lumps felt",
Media: &dto.Media{
URL: gofakeit.URL(),
Name: gofakeit.Name(),
},
Findings: gofakeit.HipsterSentence(20),
},
},
wantErr: true,
},
{
name: "Sad case: unable to get organization",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
input: dto.DiagnosticReportInput{
EncounterID: "12345678905432345",
Note: "No lumps felt",
Media: &dto.Media{
URL: gofakeit.URL(),
Name: gofakeit.Name(),
},
Findings: gofakeit.HipsterSentence(20),
},
},
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()

fakeAdvantage := fakeAdvantageMock.NewFakeAdvantageMock()

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

if tt.name == "Sad case: unable to record ultrasound results" {
fakeFHIR.MockCreateFHIRDiagnosticReportFn = func(_ context.Context, input *domain.FHIRDiagnosticReportInput) (*domain.FHIRDiagnosticReport, error) {
return nil, fmt.Errorf("an error occurred")
}
}
if tt.name == "Sad case: unable to record observation" {
fakeFHIR.MockGetFHIREncounterFn = func(ctx context.Context, id string) (*domain.FHIREncounterRelayPayload, error) {
return nil, fmt.Errorf("an error occurred")
}
}
if tt.name == "Sad case: unable to get tenant identifiers" {
fakeExt.MockGetTenantIdentifiersFn = func(ctx context.Context) (*dto.TenantIdentifiers, error) {
return nil, fmt.Errorf("an error occurred")
}
}
if tt.name == "Sad case: unable to get organization" {
fakeFHIR.MockGetFHIROrganizationFn = func(ctx context.Context, organisationID string) (*domain.FHIROrganizationRelayPayload, error) {
return nil, fmt.Errorf("an error occurred")
}
}

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

0 comments on commit 1cdd7c1

Please sign in to comment.