From 7a0f425674afff94c9942a2c261ddd23e253cbbb Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 13:47:14 +0530 Subject: [PATCH] feat: create medical record for therapy sessions --- .../clinical_procedure/clinical_procedure.py | 2 +- .../doctype/therapy_plan/therapy_plan.py | 10 ++++- .../therapy_session/therapy_session.js | 11 ++--- .../therapy_session/therapy_session.json | 26 +++++++++++- .../therapy_session/therapy_session.py | 40 ++++++++++++++++++- 5 files changed, 76 insertions(+), 13 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index 297f1b9f4c..b7d7a62a95 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -246,7 +246,7 @@ def make_procedure(source_name, target_doc=None): def insert_clinical_procedure_to_medical_record(doc): - subject = cstr(doc.procedure_template) + subject = frappe.bold(_("Clinical Procedure conducted: ")) + cstr(doc.procedure_template) + "
" if doc.practitioner: subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner if subject and doc.notes: diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index 201264f829..c19be17ba8 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -21,8 +21,14 @@ class TherapyPlan(Document): self.status = 'Completed' def set_totals(self): - total_sessions = sum([int(d.no_of_sessions) for d in self.get('therapy_plan_details')]) - total_sessions_completed = sum([int(d.sessions_completed) for d in self.get('therapy_plan_details')]) + total_sessions = 0 + total_sessions_completed = 0 + for entry in self.therapy_plan_details: + if entry.no_of_sessions: + total_sessions += entry.no_of_sessions + if entry.sessions_completed: + total_sessions_completed += entry.sessions_completed + self.db_set('total_sessions', total_sessions) self.db_set('total_sessions_completed', total_sessions_completed) diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.js b/erpnext/healthcare/doctype/therapy_session/therapy_session.js index bb675752bb..80fca39661 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.js +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.js @@ -13,14 +13,9 @@ frappe.ui.form.on('Therapy Session', { refresh: function(frm) { if (!frm.doc.__islocal) { - let target = 0; - let completed = 0; - $.each(frm.doc.exercises, function(_i, e) { - target += e.counts_target; - completed += e.counts_completed; - }); - frm.dashboard.add_indicator(__('Counts Targetted: {0}', [target]), 'blue'); - frm.dashboard.add_indicator(__('Counts Completed: {0}', [completed]), (completed < target) ? 'orange' : 'green'); + frm.dashboard.add_indicator(__('Counts Targeted: {0}', [frm.doc.total_counts_targeted]), 'blue'); + frm.dashboard.add_indicator(__('Counts Completed: {0}', [frm.doc.total_counts_completed]), + (frm.doc.total_counts_completed < frm.doc.total_counts_targeted) ? 'orange' : 'green'); } if (frm.doc.docstatus === 1) { diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.json b/erpnext/healthcare/doctype/therapy_session/therapy_session.json index 5ff719672f..d8c4b99435 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.json +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.json @@ -28,6 +28,10 @@ "invoiced", "exercises_section", "exercises", + "section_break_23", + "total_counts_targeted", + "column_break_25", + "total_counts_completed", "amended_from" ], "fields": [ @@ -173,11 +177,31 @@ "fieldtype": "Data", "label": "Patient Age", "read_only": 1 + }, + { + "fieldname": "total_counts_targeted", + "fieldtype": "Int", + "label": "Total Counts Targeted", + "read_only": 1 + }, + { + "fieldname": "total_counts_completed", + "fieldtype": "Int", + "label": "Total Counts Completed", + "read_only": 1 + }, + { + "fieldname": "section_break_23", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_25", + "fieldtype": "Column Break" } ], "is_submittable": 1, "links": [], - "modified": "2020-04-21 13:16:46.378798", + "modified": "2020-04-29 13:22:13.190353", "modified_by": "Administrator", "module": "Healthcare", "name": "Therapy Session", diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.py b/erpnext/healthcare/doctype/therapy_session/therapy_session.py index 45d2ee60e6..7e240955cf 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.py +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.py @@ -6,10 +6,16 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc +from frappe import _ +from frappe.utils import cstr class TherapySession(Document): + def validate(self): + self.set_total_counts() + def on_submit(self): self.update_sessions_count_in_therapy_plan() + insert_session_medical_record(self) def on_cancel(self): self.update_sessions_count_in_therapy_plan(on_cancel=True) @@ -24,6 +30,18 @@ class TherapySession(Document): entry.sessions_completed += 1 therapy_plan.save() + def set_total_counts(self): + target_total = 0 + counts_completed = 0 + for entry in self.exercises: + if entry.counts_target: + target_total += entry.counts_target + if entry.counts_completed: + counts_completed += entry.counts_completed + + self.db_set('total_counts_targeted', target_total) + self.db_set('total_counts_completed', counts_completed) + @frappe.whitelist() def create_therapy_session(source_name, target_doc=None): @@ -52,4 +70,24 @@ def create_therapy_session(source_name, target_doc=None): } }, target_doc, set_missing_values) - return doc \ No newline at end of file + return doc + + +def insert_session_medical_record(doc): + subject = frappe.bold(_('Therapy: ')) + cstr(doc.therapy_type) + '
' + if doc.therapy_plan: + subject += frappe.bold(_('Therapy Plan: ')) + cstr(doc.therapy_plan) + '
' + if doc.practitioner: + subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner + subject += frappe.bold(_('Total Counts Targeted: ')) + cstr(doc.total_counts_targeted) + '
' + subject += frappe.bold(_('Total Counts Completed: ')) + cstr(doc.total_counts_completed) + '
' + + medical_record = frappe.new_doc('Patient Medical Record') + medical_record.patient = doc.patient + medical_record.subject = subject + medical_record.status = 'Open' + medical_record.communication_date = doc.start_date + medical_record.reference_doctype = 'Therapy Session' + medical_record.reference_name = doc.name + medical_record.reference_owner = doc.owner + medical_record.save(ignore_permissions=True) \ No newline at end of file