diff --git a/pkg/clinical/application/utils/templates.go b/pkg/clinical/application/utils/templates.go
index 5092d20..748ae19 100644
--- a/pkg/clinical/application/utils/templates.go
+++ b/pkg/clinical/application/utils/templates.go
@@ -142,7 +142,7 @@ const ReferralFormTemplate = `
-
+
|
{{if .Date}} Date: {{.Date}} {{end}}
diff --git a/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go b/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go
index 2687001..192a4fd 100644
--- a/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go
+++ b/pkg/clinical/infrastructure/datastore/cloudhealthcare/mock/fhir_mock.go
@@ -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
},
diff --git a/pkg/clinical/usecases/clinical/referral_report.go b/pkg/clinical/usecases/clinical/referral_report.go
index b70db3f..124529e 100644
--- a/pkg/clinical/usecases/clinical/referral_report.go
+++ b/pkg/clinical/usecases/clinical/referral_report.go
@@ -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"
@@ -66,6 +67,7 @@ type TemplateData struct {
Date string
Time string
Reason string
+ FacilityName string
Patient Patient
NextOfKin NextOfKin
Facility Facility
@@ -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,
@@ -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
diff --git a/pkg/clinical/usecases/clinical/referral_report_test.go b/pkg/clinical/usecases/clinical/referral_report_test.go
index bbebfe1..b52facc 100644
--- a/pkg/clinical/usecases/clinical/referral_report_test.go
+++ b/pkg/clinical/usecases/clinical/referral_report_test.go
@@ -33,23 +33,22 @@ 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,
},
{
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,
@@ -57,7 +56,7 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
{
name: "Sad Case - Fail to get patient",
args: args{
- ctx: ctx,
+ ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
@@ -65,7 +64,7 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
{
name: "Sad Case - unable to upload media",
args: args{
- ctx: ctx,
+ ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
@@ -73,7 +72,7 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
{
name: "Sad Case - unable to create FHIR document reference",
args: args{
- ctx: ctx,
+ ctx: addTenantIdentifierContext(ctx),
serviceRequestID: uuid.New().String(),
},
wantErr: true,
@@ -81,7 +80,15 @@ func TestUseCasesClinicalImpl_GenerateReferralReportPDF(t *testing.T) {
{
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,
@@ -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)
}
|