Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: display nationalID and referral notes on referral report PDF #410

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 21 additions & 28 deletions pkg/clinical/usecases/clinical/referral_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"time"

"github.com/SebastiaanKlippert/go-wkhtmltopdf"
"github.com/savannahghi/clinical/pkg/clinical/application/common/helpers"
"github.com/savannahghi/clinical/pkg/clinical/application/utils"
"github.com/savannahghi/scalarutils"
)

type Patient struct {
Expand Down Expand Up @@ -51,13 +53,6 @@ type MedicalHistory struct {
Tests []Test
}

type ReferredBy struct {
Name string
Designation string
Phone string
Signature string
}

type Footer struct {
Phone string
Email string
Expand All @@ -73,7 +68,6 @@ type TemplateData struct {
Facility Facility
Referral Referral
MedicalHistory MedicalHistory
ReferredBy ReferredBy
Footer Footer
}

Expand Down Expand Up @@ -106,37 +100,43 @@ func (c *UseCasesClinicalImpl) GenerateReferralReportPDF(ctx context.Context, se
return nil, err
}

var nationalID string

for _, identifier := range patient.Resource.Identifier {
system := scalarutils.URI(helpers.IDIdentifierSystem)
if identifier.System == &system && identifier.Value != "" {
nationalID = identifier.Value
}
}

age := time.Since(patient.Resource.BirthDate.AsTime()).Hours() / 24 / 365
patientData := Patient{
Name: patient.Resource.Name[0].Text,
EmpowerID: "",
NationalID: "",
NationalID: nationalID,
PhoneNumber: *patient.Resource.Telecom[0].Value,
DateOfBirth: patient.Resource.BirthDate.String(),
Age: int(age),
Sex: patient.Resource.Gender.String(),
}

var referredFacilityName, referredSpecialistName string
var referredFacilityName string

for _, extension := range serviceRequest.Resource.Extension {
switch extension.URL {
case "http://savannahghi.org/fhir/StructureDefinition/referred-facility":
if extension.URL == "http://savannahghi.org/fhir/StructureDefinition/referred-facility" {
for _, ext := range extension.Extension {
if ext.URL == "facilityName" {
referredFacilityName = ext.ValueString
}
}

case "http://savannahghi.org/fhir/StructureDefinition/referred-specialist":
for _, ext := range extension.Extension {
if ext.URL == "specialistName" {
referredSpecialistName = ext.ValueString
}
}
}
}

var referralReason string
if len(serviceRequest.Resource.Note) > 0 && serviceRequest.Resource.Note[0].Text != nil {
referralReason = string(*serviceRequest.Resource.Note[0].Text)
}

data := TemplateData{
Date: time.Now().Format("Monday Jan 2"),
Time: time.Now().Format("15:04"),
Expand All @@ -146,17 +146,10 @@ func (c *UseCasesClinicalImpl) GenerateReferralReportPDF(ctx context.Context, se
Name: referredFacilityName,
},
Referral: Referral{
// TODO: Get the reason from the API
Reason: "Further Testing",
Reason: referralReason,
},
MedicalHistory: MedicalHistory{Procedure: "Screening", Medication: "None", ReferralNotes: "Patient complains of severe abdominal pain and intermittent bleeding.", Tests: []Test{{Name: "VIA", Results: "Positive", Date: "13th May 2024"}}},
ReferredBy: ReferredBy{
Name: referredSpecialistName,
Designation: "Doctor",
Phone: "+254711990990",
Signature: "",
},
Footer: Footer{},
Footer: Footer{},
}

tmpl, err := template.ParseFiles("templates/referral_report_template.html")
Expand Down
8 changes: 3 additions & 5 deletions templates/referral_report_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ <h2>Medical history</h2>
</div>
{{end}}

{{if .ReferredBy}}
<div class="detail-section">
<h2>Referred by</h2>
{{if .ReferredBy.Name}}<div class="detail"><strong>Referring Officer:</strong> {{.ReferredBy.Name}}</div>{{end}}
{{if .ReferredBy.Designation}}<div class="detail"><strong>Designation:</strong> {{.ReferredBy.Designation}}</div>{{end}}
{{if .ReferredBy.Phone}}<div class="detail"><strong>Phone:</strong> {{.ReferredBy.Phone}}</div>{{end}}
<div class="detail"><strong>Referring Officer:</strong></div>
<div class="detail"><strong>Designation:</strong></div>
<div class="detail"><strong>Phone:</strong></div>
<div class="detail"><strong>Signature:</strong></div>
</div>
{{end}}
</div>
{{if or .Footer.Phone .Footer.Email .Footer.Address}}
<div class="footer">
Expand Down