feat: create medical record for therapy sessions

This commit is contained in:
Rucha Mahabal 2020-04-29 13:47:14 +05:30
parent 708bceba6e
commit 7a0f425674
5 changed files with 76 additions and 13 deletions

View File

@ -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) + "<br>"
if doc.practitioner:
subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner
if subject and doc.notes:

View File

@ -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)

View File

@ -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) {

View File

@ -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",

View File

@ -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):
@ -53,3 +71,23 @@ def create_therapy_session(source_name, target_doc=None):
}, target_doc, set_missing_values)
return doc
def insert_session_medical_record(doc):
subject = frappe.bold(_('Therapy: ')) + cstr(doc.therapy_type) + '<br>'
if doc.therapy_plan:
subject += frappe.bold(_('Therapy Plan: ')) + cstr(doc.therapy_plan) + '<br>'
if doc.practitioner:
subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner
subject += frappe.bold(_('Total Counts Targeted: ')) + cstr(doc.total_counts_targeted) + '<br>'
subject += frappe.bold(_('Total Counts Completed: ')) + cstr(doc.total_counts_completed) + '<br>'
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)