Skip to content

Commit

Permalink
feat: share referral form with a patient (#427)
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Apr 11, 2024
1 parent 6d23e7f commit 5a897c0
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/segmentio/ksuid v1.0.4
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/ttacon/libphonenumber v1.2.1
github.com/vektah/gqlparser/v2 v2.5.11
golang.org/x/oauth2 v0.18.0
google.golang.org/api v0.172.0
Expand Down Expand Up @@ -98,7 +99,6 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
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 @@ -225,4 +225,6 @@ extend type Mutation {

# Referral
referPatient(input: ReferralInput!): ServiceRequest!

shareReferralForm(serviceRequestID: ID!): Boolean!
}
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.

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

30 changes: 30 additions & 0 deletions pkg/clinical/usecases/clinical/referral_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clinical
import (
"bytes"
"context"
"errors"
"fmt"
"html/template"
"strings"
Expand Down Expand Up @@ -322,3 +323,32 @@ func (c *UseCasesClinicalImpl) CreateDocumentReference(ctx context.Context, payl

return nil
}

// ShareReferralForm is searched for a document reference associated with a service request, retrieves the document URL and sends it to the
// patient via SMS
func (c *UseCasesClinicalImpl) ShareReferralForm(ctx context.Context, serviceRequestID string) (bool, error) {
identifiers, err := c.infrastructure.BaseExtension.GetTenantIdentifiers(ctx)
if err != nil {
return false, err
}

params := map[string]interface{}{
"related": fmt.Sprintf("ServiceRequest/%s", serviceRequestID),
"_sort": "_lastUpdated",
"_count": "1",
}

output, err := c.infrastructure.FHIR.SearchFHIRDocumentReference(ctx, params, *identifiers, dto.Pagination{})
if err != nil {
utils.ReportErrorToSentry(err)
return false, err
}

if len(output.DocumentReferences) == 0 {
return false, errors.New("no document reference found")
}

// TODO: Send SMS here

return true, nil
}
80 changes: 80 additions & 0 deletions pkg/clinical/usecases/clinical/referral_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,83 @@ func TestUseCasesClinicalImpl_CreateDocumentReference(t *testing.T) {
})
}
}

func TestUseCasesClinicalImpl_ShareReferralForm(t *testing.T) {
type args struct {
ctx context.Context
serviceRequestID string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Happy case: share referral form",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
serviceRequestID: gofakeit.UUID(),
},
wantErr: false,
},
{
name: "Sad case: unable to share referral form",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
serviceRequestID: gofakeit.UUID(),
},
wantErr: true,
},
{
name: "Sad case: unable to get tenant identifiers",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
serviceRequestID: gofakeit.UUID(),
},
wantErr: true,
},
{
name: "Sad case: no document references found",
args: args{
ctx: addTenantIdentifierContext(context.Background()),
serviceRequestID: gofakeit.UUID(),
},
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)
c := clinicalUsecase.NewUseCasesClinicalImpl(infra)

if tt.name == "Sad case: unable to share referral form" {
fakeFHIR.MockSearchFHIRDocumentReferenceFn = func(ctx context.Context, searchParams map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRDocumentReference, error) {
return nil, fmt.Errorf("failed to search FHIR document reference")
}
}
if tt.name == "Sad case: unable to get tenant identifiers" {
fakeExt.MockGetTenantIdentifiersFn = func(ctx context.Context) (*dto.TenantIdentifiers, error) {
return nil, fmt.Errorf("failed to get tenant identifiers")
}
}
if tt.name == "Sad case: no document references found" {
fakeFHIR.MockSearchFHIRDocumentReferenceFn = func(ctx context.Context, searchParams map[string]interface{}, tenant dto.TenantIdentifiers, pagination dto.Pagination) (*domain.PagedFHIRDocumentReference, error) {
return &domain.PagedFHIRDocumentReference{}, nil
}
}

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

0 comments on commit 5a897c0

Please sign in to comment.