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

fix patient report generation #1027

Merged
merged 1 commit into from
Sep 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions care/facility/tasks/patient/discharge_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,23 @@ def randomString(stringLength):
@celery.task()
def generate_discharge_report(patient_id, email):
patient = PatientRegistration.objects.get(id=patient_id)
consultations = PatientConsultation.objects.filter(patient=patient).order_by("-created_date")
consultations = PatientConsultation.objects.filter(patient=patient).order_by(
"-created_date"
)
diseases = Disease.objects.filter(patient=patient)
if consultations.exists():
consultation = consultations.first()
samples = PatientSample.objects.filter(patient=patient, consultation=consultation)
samples = PatientSample.objects.filter(
patient=patient, consultation=consultation
)
daily_rounds = DailyRound.objects.filter(consultation=consultation)
investigations = InvestigationValue.objects.filter(consultation=consultation.id)
investigations = list(filter(lambda inv: inv.value is not None or inv.notes is not None, investigations))
investigations = list(
filter(
lambda inv: inv.value is not None or inv.notes is not None,
investigations,
)
)
else:
consultation = None
samples = None
Expand All @@ -47,7 +56,7 @@ def generate_discharge_report(patient_id, email):
date = make_aware(datetime.datetime.now())
disease_status = DiseaseStatusEnum(patient.disease_status).name.capitalize()
html_string = render_to_string(
"patient_pdf_template.html",
"reports/patient_pdf_report.html",
{
"patient": patient,
"samples": samples,
Expand All @@ -64,11 +73,19 @@ def generate_discharge_report(patient_id, email):
bytestring_to_pdf(
html_string.encode(),
default_storage.open(filename, "w+"),
**{"no-margins": None, "disable-gpu": None, "disable-dev-shm-usage": False, "window-size": "2480,3508"},
**{
"no-margins": None,
"disable-gpu": None,
"disable-dev-shm-usage": False,
"window-size": "2480,3508",
},
)
file = default_storage.open(filename, "rb")
msg = EmailMessage(
"Patient Discharge Summary", "Please find the attached file", settings.DEFAULT_FROM_EMAIL, (email,),
"Patient Discharge Summary",
"Please find the attached file",
settings.DEFAULT_FROM_EMAIL,
(email,),
)
msg.content_subtype = "html" # Main content is now text/html
msg.attach(patient.name + "-Discharge_Summary.pdf", file.read(), "application/pdf")
Expand Down
18 changes: 18 additions & 0 deletions care/facility/templatetags/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.template import Library

register = Library()


@register.filter(name="suggestion_string")
def suggestion_string(suggestion_code: str):
if suggestion_code == "A":
return "Admission"
if suggestion_code == "HI":
return "Home Isolation"
if suggestion_code == "R":
return "Referral"
if suggestion_code == "OP":
return "OP Consultation"
if suggestion_code == "DC":
return "Domiciliary Care"
return "Other"