Skip to content

Commit

Permalink
chore: add current facility details to referral report
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Apr 11, 2024
1 parent 4232aca commit 1307796
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/clinical/application/utils/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const ReferralFormTemplate = `
<img alt="Empower Logo">
</td>
<td >
<h1 class="header-title">Empower Coast General Hospital</h1>
<h1 class="header-title">{{ .FacilityName }}</h1>
</td>
<td class="details-cell">
{{if .Date}}<div>Date: <strong>{{.Date}}</strong></div>{{end}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1674,11 +1674,17 @@ func NewFHIRMock() *FHIRMock {
},
MockGetFHIROrganizationFn: func(ctx context.Context, organisationID string) (*domain.FHIROrganizationRelayPayload, error) {
id := uuid.New().String()
phoneNumber := gofakeit.Phone()
name := "Test Organisation"
return &domain.FHIROrganizationRelayPayload{
Resource: &domain.FHIROrganization{
ID: &id,
Name: &name,
Telecom: []*domain.FHIRContactPoint{
{
Value: &phoneNumber,
},
},
},
}, nil
},
Expand Down
36 changes: 31 additions & 5 deletions pkg/clinical/usecases/clinical/referral_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/savannahghi/clinical/pkg/clinical/application/common"
"github.com/savannahghi/clinical/pkg/clinical/application/common/helpers"
"github.com/savannahghi/clinical/pkg/clinical/application/dto"
"github.com/savannahghi/clinical/pkg/clinical/application/extensions"
"github.com/savannahghi/clinical/pkg/clinical/application/utils"
"github.com/savannahghi/clinical/pkg/clinical/domain"
"github.com/savannahghi/scalarutils"
Expand Down Expand Up @@ -66,6 +67,7 @@ type TemplateData struct {
Date string
Time string
Reason string
FacilityName string
Patient Patient
NextOfKin NextOfKin
Facility Facility
Expand Down Expand Up @@ -156,11 +158,33 @@ func (c *UseCasesClinicalImpl) GenerateReferralReportPDF(ctx context.Context, se
referralReason = string(*serviceRequest.Resource.Note[0].Text)
}

facilityID, err := extensions.GetFacilityIDFromContext(ctx)
if err != nil {
return nil, err
}

facility, err := c.infrastructure.FHIR.GetFHIROrganization(ctx, facilityID)
if err != nil {
return nil, err
}

var facilityContact string

if facility.Resource.Telecom != nil {
for _, tel := range facility.Resource.Telecom {
if tel.Value != nil {
facilityContact = *tel.Value
break
}
}
}

data := TemplateData{
Date: time.Now().Format("Monday, Jan 2, 2006"),
Time: time.Now().Format("15:04"),
Patient: patientData,
NextOfKin: NextOfKin{},
Date: time.Now().Format("Monday, Jan 2, 2006"),
Time: time.Now().Format("15:04"),
FacilityName: *facility.Resource.Name,
Patient: patientData,
NextOfKin: NextOfKin{},
Facility: Facility{
Name: referredFacilityName,
Contact: referredFacilityContact,
Expand All @@ -170,7 +194,9 @@ func (c *UseCasesClinicalImpl) GenerateReferralReportPDF(ctx context.Context, se
Reason: referralReason,
},
MedicalHistory: MedicalHistory{Procedure: "Screening", Medication: "None", ReferralNotes: referralReason, Tests: []Test{{Name: "VIA", Results: "Positive", Date: "13th May 2024"}}},
Footer: Footer{},
Footer: Footer{
Phone: facilityContact,
},
}

var htmlBuffer bytes.Buffer
Expand Down
31 changes: 22 additions & 9 deletions pkg/clinical/usecases/clinical/referral_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,62 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
{
name: "Happy Case - Successfully generate a referral report pdf",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
// TODO: Fix this @salaton
wantErr: true,
wantErr: false,
},
{
name: "Sad Case - Missing service request ID",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
},
wantErr: true,
},
{
name: "Sad Case - Fail to get service request",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
},
{
name: "Sad Case - Fail to get patient",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
},
{
name: "Sad Case - unable to upload media",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
},
{
name: "Sad Case - unable to create FHIR document reference",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
},
{
name: "Sad Case - unable to get terminology concept",
args: args{
ctx: ctx,
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
},
{
name: "Sad Case - Fail to get organization",
args: args{
ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
Expand Down Expand Up @@ -126,6 +133,12 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
}
}

if tt.name == "Sad Case - Fail to get organization" {
fakeFHIR.MockGetFHIROrganizationFn = func(ctx context.Context, organisationID string) (*domain.FHIROrganizationRelayPayload, error) {
return nil, fmt.Errorf("failed to get organization")
}
}

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

0 comments on commit 1307796

Please sign in to comment.