From 9bf733d82e2fae97fd033086c6834b727fcf83fd Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 11:16:34 +0530 Subject: [PATCH 1/6] fix: reload procedure doc on completion --- .../doctype/clinical_procedure/clinical_procedure.js | 8 +++++--- .../doctype/clinical_procedure/clinical_procedure.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js index 5f36bdd95c..87c22ccf6f 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.js @@ -80,6 +80,7 @@ frappe.ui.form.on('Clinical Procedure', { frappe.call({ method: 'complete_procedure', doc: frm.doc, + freeze: true, callback: function(r) { if (r.message) { frappe.show_alert({ @@ -87,8 +88,8 @@ frappe.ui.form.on('Clinical Procedure', { ['' + r.message + '']), indicator: 'green' }); - frm.reload_doc(); } + frm.reload_doc(); } }); } @@ -111,9 +112,10 @@ frappe.ui.form.on('Clinical Procedure', { frappe.call({ doc: frm.doc, method: 'make_material_receipt', + freeze: true, callback: function(r) { if (!r.exc) { - cur_frm.reload_doc(); + frm.reload_doc(); let doclist = frappe.model.sync(r.message); frappe.set_route('Form', doclist[0].doctype, doclist[0].name); } @@ -122,7 +124,7 @@ frappe.ui.form.on('Clinical Procedure', { } ); } else { - cur_frm.reload_doc(); + frm.reload_doc(); } } } diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index db3afc8807..d6c0893914 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -87,7 +87,8 @@ class ClinicalProcedure(Document): else: frappe.throw(_('Please set Customer in Patient {0}').format(frappe.bold(self.patient)), title=_('Customer Not Found')) - frappe.db.set_value('Clinical Procedure', self.name, 'status', 'Completed') + self.db_set('status', 'Completed') + if self.consume_stock and self.items: return stock_entry From 708bceba6e7dd303c0e3f258ba347af0b0408124 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 13:06:52 +0530 Subject: [PATCH 2/6] fix: change Patient Medical Record subject fieldtype to Text Editor --- .../clinical_procedure/clinical_procedure.py | 2 +- .../healthcare/doctype/lab_test/lab_test.py | 18 +++++++------- .../patient_encounter/patient_encounter.py | 23 +++++++++++------- .../patient_medical_record.json | 4 ++-- .../doctype/vital_signs/vital_signs.py | 24 +++++++++---------- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py index d6c0893914..297f1b9f4c 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py @@ -248,7 +248,7 @@ def make_procedure(source_name, target_doc=None): def insert_clinical_procedure_to_medical_record(doc): subject = cstr(doc.procedure_template) if doc.practitioner: - subject += ' ' + doc.practitioner + subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner if subject and doc.notes: subject += '
' + doc.notes diff --git a/erpnext/healthcare/doctype/lab_test/lab_test.py b/erpnext/healthcare/doctype/lab_test/lab_test.py index 4e4015d2f0..ea8ce25c97 100644 --- a/erpnext/healthcare/doctype/lab_test/lab_test.py +++ b/erpnext/healthcare/doctype/lab_test/lab_test.py @@ -288,23 +288,23 @@ def insert_lab_test_to_medical_record(doc): table_row = False subject = cstr(doc.lab_test_name) if doc.practitioner: - subject += " "+ doc.practitioner + subject += frappe.bold(_("Healthcare Practitioner: "))+ doc.practitioner + "
" if doc.normal_test_items: item = doc.normal_test_items[0] comment = "" if item.lab_test_comment: comment = str(item.lab_test_comment) - table_row = item.lab_test_name + table_row = frappe.bold(_("Lab Test Conducted: ")) + item.lab_test_name if item.lab_test_event: - table_row += " " + item.lab_test_event + table_row += frappe.bold(_("Lab Test Event: ")) + item.lab_test_event if item.result_value: - table_row += " " + item.result_value + table_row += " " + frappe.bold(_("Lab Test Result: ")) + item.result_value if item.normal_range: - table_row += " normal_range("+item.normal_range+")" - table_row += " "+comment + table_row += " " + _("Normal Range:") + item.normal_range + table_row += " " + comment elif doc.special_test_items: item = doc.special_test_items[0] @@ -316,12 +316,12 @@ def insert_lab_test_to_medical_record(doc): item = doc.sensitivity_test_items[0] if item.antibiotic and item.antibiotic_sensitivity: - table_row = item.antibiotic +" "+ item.antibiotic_sensitivity + table_row = item.antibiotic + " " + item.antibiotic_sensitivity if table_row: - subject += "
"+table_row + subject += "
" + table_row if doc.lab_test_comment: - subject += "
"+ cstr(doc.lab_test_comment) + subject += "
" + cstr(doc.lab_test_comment) medical_record = frappe.new_doc("Patient Medical Record") medical_record.patient = doc.patient diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py index 767643bc73..1734c28e52 100644 --- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py +++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py @@ -18,6 +18,9 @@ class PatientEncounter(Document): def after_insert(self): insert_encounter_to_medical_record(self) + def on_submit(self): + update_encounter_medical_record(self) + def on_cancel(self): if self.appointment: frappe.db.set_value('Patient Appointment', self.appointment, 'status', 'Open') @@ -66,22 +69,26 @@ def delete_medical_record(encounter): frappe.db.delete_doc_if_exists('Patient Medical Record', 'reference_name', encounter.name) def set_subject_field(encounter): - subject = encounter.practitioner + '\n' + subject = frappe.bold(_('Healthcare Practitioner: ')) + encounter.practitioner + '
' if encounter.symptoms: - subject += _('Symptoms: ') + cstr(encounter.symptoms) + '\n' + subject += frappe.bold(_('Symptoms: ')) + '
' + for entry in encounter.symptoms: + subject += cstr(entry.complaint) + '
' else: - subject += _('No Symptoms') + '\n' + subject += frappe.bold(_('No Symptoms')) + '
' if encounter.diagnosis: - subject += _('Diagnosis: ') + cstr(encounter.diagnosis) + '\n' + subject += frappe.bold(_('Diagnosis: ')) + '
' + for entry in encounter.diagnosis: + subject += cstr(entry.diagnosis) + '
' else: - subject += _('No Diagnosis') + '\n' + subject += frappe.bold(_('No Diagnosis')) + '
' if encounter.drug_prescription: - subject += '\n' + _('Drug(s) Prescribed.') + subject += '
' + _('Drug(s) Prescribed.') if encounter.lab_test_prescription: - subject += '\n' + _('Test(s) Prescribed.') + subject += '
' + _('Test(s) Prescribed.') if encounter.procedure_prescription: - subject += '\n' + _('Procedure(s) Prescribed.') + subject += '
' + _('Procedure(s) Prescribed.') return subject diff --git a/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json b/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json index 3655e24cb9..ed82355f33 100644 --- a/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json +++ b/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json @@ -57,7 +57,7 @@ }, { "fieldname": "subject", - "fieldtype": "Small Text", + "fieldtype": "Text Editor", "ignore_xss_filter": 1, "label": "Subject" }, @@ -125,7 +125,7 @@ ], "in_create": 1, "links": [], - "modified": "2020-03-23 19:26:59.308383", + "modified": "2020-04-29 12:26:57.679402", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Medical Record", diff --git a/erpnext/healthcare/doctype/vital_signs/vital_signs.py b/erpnext/healthcare/doctype/vital_signs/vital_signs.py index 959e8504c4..b0e78e8eb9 100644 --- a/erpnext/healthcare/doctype/vital_signs/vital_signs.py +++ b/erpnext/healthcare/doctype/vital_signs/vital_signs.py @@ -35,17 +35,17 @@ def delete_vital_signs_from_medical_record(doc): def set_subject_field(doc): subject = '' - if(doc.temperature): - subject += _('Temperature: ') + '\n'+ cstr(doc.temperature) + '. ' - if(doc.pulse): - subject += _('Pulse: ') + '\n' + cstr(doc.pulse) + '. ' - if(doc.respiratory_rate): - subject += _('Respiratory Rate: ') + '\n' + cstr(doc.respiratory_rate) + '. ' - if(doc.bp): - subject += _('BP: ') + '\n' + cstr(doc.bp) + '. ' - if(doc.bmi): - subject += _('BMI: ') + '\n' + cstr(doc.bmi) + '. ' - if(doc.nutrition_note): - subject += _('Note: ') + '\n' + cstr(doc.nutrition_note) + '. ' + if doc.temperature: + subject += frappe.bold(_('Temperature: ')) + cstr(doc.temperature) + '
' + if doc.pulse: + subject += frappe.bold(_('Pulse: ')) + cstr(doc.pulse) + '
' + if doc.respiratory_rate: + subject += frappe.bold(_('Respiratory Rate: ')) + cstr(doc.respiratory_rate) + '
' + if doc.bp: + subject += frappe.bold(_('BP: ')) + cstr(doc.bp) + '
' + if doc.bmi: + subject += frappe.bold(_('BMI: ')) + cstr(doc.bmi) + '
' + if doc.nutrition_note: + subject += frappe.bold(_('Note: ')) + cstr(doc.nutrition_note) + '
' return subject From 7a0f425674afff94c9942a2c261ddd23e253cbbb Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 13:47:14 +0530 Subject: [PATCH 3/6] 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 From 706f6b0030b2ddeb5873cfa6f154b27c2aa871b4 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 14:19:27 +0530 Subject: [PATCH 4/6] fix: mark form as dirty when editing or deleting exercise card --- .../doctype/exercise_type/exercise_type.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/healthcare/doctype/exercise_type/exercise_type.js b/erpnext/healthcare/doctype/exercise_type/exercise_type.js index f450c9bccb..ff99dc2d72 100644 --- a/erpnext/healthcare/doctype/exercise_type/exercise_type.js +++ b/erpnext/healthcare/doctype/exercise_type/exercise_type.js @@ -24,6 +24,8 @@ erpnext.ExerciseEditor = Class.extend({ this.exercise_cards = $('
').appendTo(this.wrapper); + this.row = $('
').appendTo(this.exercise_cards); + let me = this; this.exercise_toolbar.find(".btn-add") @@ -32,7 +34,7 @@ erpnext.ExerciseEditor = Class.extend({ me.show_add_card_dialog(frm); }); - if (frm.doc.steps_table.length > 0) { + if (frm.doc.steps_table && frm.doc.steps_table.length > 0) { this.make_cards(frm); this.make_buttons(frm); } @@ -41,7 +43,6 @@ erpnext.ExerciseEditor = Class.extend({ make_cards: function(frm) { var me = this; $(me.exercise_cards).empty(); - this.row = $('
').appendTo(me.exercise_cards); $.each(frm.doc.steps_table, function(i, step) { $(repl(` @@ -78,6 +79,7 @@ erpnext.ExerciseEditor = Class.extend({ frm.doc.steps_table.pop(id); frm.refresh_field('steps_table'); $('#col-'+id).remove(); + frm.dirty(); }, 300); }); }, @@ -106,7 +108,10 @@ erpnext.ExerciseEditor = Class.extend({ ], primary_action: function() { let data = d.get_values(); - let i = frm.doc.steps_table.length; + let i = 0; + if (frm.doc.steps_table) { + i = frm.doc.steps_table.length; + } $(repl(`
@@ -165,9 +170,10 @@ erpnext.ExerciseEditor = Class.extend({ frm.doc.steps_table[id].image = data.image; frm.doc.steps_table[id].description = data.step_description; refresh_field('steps_table'); + frm.dirty(); new_dialog.hide(); }, - primary_action_label: __("Save"), + primary_action_label: __("Edit"), }); new_dialog.set_values({ From b4b3872ff27311bcf346859a4a531d43a880e7e2 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 17:34:36 +0530 Subject: [PATCH 5/6] feat: add create Sales Invoice option from Therapy Session --- .../therapy_session/therapy_session.js | 78 ++++++++++++++++++- .../therapy_session/therapy_session.json | 15 +++- .../therapy_session/therapy_session.py | 41 +++++++++- 3 files changed, 129 insertions(+), 5 deletions(-) diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.js b/erpnext/healthcare/doctype/therapy_session/therapy_session.js index 80fca39661..abe4defaf9 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.js +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.js @@ -19,12 +19,86 @@ frappe.ui.form.on('Therapy Session', { } if (frm.doc.docstatus === 1) { - frm.add_custom_button(__('Patient Assessment'),function() { + frm.add_custom_button(__('Patient Assessment'), function() { frappe.model.open_mapped_doc({ method: 'erpnext.healthcare.doctype.patient_assessment.patient_assessment.create_patient_assessment', frm: frm, }) }, 'Create'); + + frm.add_custom_button(__('Sales Invoice'), function() { + frappe.model.open_mapped_doc({ + method: 'erpnext.healthcare.doctype.therapy_session.therapy_session.invoice_therapy_session', + frm: frm, + }) + }, 'Create'); + } + }, + + patient: function(frm) { + if (frm.doc.patient) { + frappe.call({ + 'method': 'erpnext.healthcare.doctype.patient.patient.get_patient_detail', + args: { + patient: frm.doc.patient + }, + callback: function (data) { + let age = ''; + if (data.message.dob) { + age = calculate_age(data.message.dob); + } else if (data.message.age) { + age = data.message.age; + if (data.message.age_as_on) { + age = __('{0} as on {1}', [age, data.message.age_as_on]); + } + } + frm.set_value('patient_age', age); + frm.set_value('gender', data.message.sex); + frm.set_value('patient_name', data.message.patient_name); + } + }); + } else { + frm.set_value('patient_age', ''); + frm.set_value('gender', ''); + frm.set_value('patient_name', ''); + } + }, + + appointment: function(frm) { + if (frm.doc.appointment) { + frappe.call({ + 'method': 'frappe.client.get', + args: { + doctype: 'Patient Appointment', + name: frm.doc.appointment + }, + callback: function(data) { + let values = { + 'patient':data.message.patient, + 'therapy_type': data.message.therapy_type, + 'therapy_plan': data.message.therapy_plan, + 'practitioner': data.message.practitioner, + 'department': data.message.department, + 'start_date': data.message.appointment_date, + 'start_time': data.message.appointment_time, + 'service_unit': data.message.service_unit, + 'company': data.message.company + }; + frm.set_value(values); + } + }); + } else { + let values = { + 'patient': '', + 'therapy_type': '', + 'therapy_plan': '', + 'practitioner': '', + 'department': '', + 'start_date': '', + 'start_time': '', + 'service_unit': '', + }; + frm.set_value(values); } }, @@ -39,6 +113,8 @@ frappe.ui.form.on('Therapy Session', { callback: function(data) { frm.set_value('duration', data.message.default_duration); frm.set_value('rate', data.message.rate); + frm.set_value('service_unit', data.message.healthcare_service_unit); + frm.set_value('department', data.message.medical_department); frm.doc.exercises = []; $.each(data.message.exercises, function(_i, e) { let exercise = frm.add_child('exercises'); diff --git a/erpnext/healthcare/doctype/therapy_session/therapy_session.json b/erpnext/healthcare/doctype/therapy_session/therapy_session.json index d8c4b99435..00d74a0949 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.json +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.json @@ -9,9 +9,11 @@ "naming_series", "appointment", "patient", + "patient_name", "patient_age", "gender", "column_break_5", + "company", "therapy_plan", "therapy_type", "practitioner", @@ -20,7 +22,6 @@ "duration", "rate", "location", - "company", "column_break_12", "service_unit", "start_date", @@ -163,7 +164,8 @@ "fieldname": "company", "fieldtype": "Link", "label": "Company", - "options": "Company" + "options": "Company", + "reqd": 1 }, { "default": "0", @@ -197,11 +199,18 @@ { "fieldname": "column_break_25", "fieldtype": "Column Break" + }, + { + "fetch_from": "patient.patient_name", + "fieldname": "patient_name", + "fieldtype": "Data", + "label": "Patient Name", + "read_only": 1 } ], "is_submittable": 1, "links": [], - "modified": "2020-04-29 13:22:13.190353", + "modified": "2020-04-29 16:49:16.286006", "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 7e240955cf..9650183712 100644 --- a/erpnext/healthcare/doctype/therapy_session/therapy_session.py +++ b/erpnext/healthcare/doctype/therapy_session/therapy_session.py @@ -7,7 +7,8 @@ import frappe from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from frappe import _ -from frappe.utils import cstr +from frappe.utils import cstr, getdate +from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account class TherapySession(Document): def validate(self): @@ -73,6 +74,44 @@ def create_therapy_session(source_name, target_doc=None): return doc +@frappe.whitelist() +def invoice_therapy_session(source_name, target_doc=None): + def set_missing_values(source, target): + target.customer = frappe.db.get_value('Patient', source.patient, 'customer') + target.due_date = getdate() + target.debit_to = get_receivable_account(source.company) + item = target.append('items', {}) + item = get_therapy_item(source, item) + target.set_missing_values(for_validate=True) + + doc = get_mapped_doc('Therapy Session', source_name, { + 'Therapy Session': { + 'doctype': 'Sales Invoice', + 'field_map': [ + ['patient', 'patient'], + ['referring_practitioner', 'practitioner'], + ['company', 'company'], + ['due_date', 'start_date'] + ] + } + }, target_doc, set_missing_values) + + return doc + + +def get_therapy_item(therapy, item): + item.item_code = frappe.db.get_value('Therapy Type', therapy.therapy_type, 'item') + item.description = _('Therapy Session Charges: {0}').format(therapy.practitioner) + item.income_account = get_income_account(therapy.practitioner, therapy.company) + item.cost_center = frappe.get_cached_value('Company', therapy.company, 'cost_center') + item.rate = therapy.rate + item.amount = therapy.rate + item.qty = 1 + item.reference_dt = 'Therapy Session' + item.reference_dn = therapy.name + return item + + def insert_session_medical_record(doc): subject = frappe.bold(_('Therapy: ')) + cstr(doc.therapy_type) + '
' if doc.therapy_plan: From 298c7e5be5cf8ef2795728d344aa12e21b703e97 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 29 Apr 2020 19:23:16 +0530 Subject: [PATCH 6/6] fix: exercise type --- erpnext/healthcare/doctype/exercise_type/exercise_type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/healthcare/doctype/exercise_type/exercise_type.js b/erpnext/healthcare/doctype/exercise_type/exercise_type.js index ff99dc2d72..68db0477c2 100644 --- a/erpnext/healthcare/doctype/exercise_type/exercise_type.js +++ b/erpnext/healthcare/doctype/exercise_type/exercise_type.js @@ -24,7 +24,7 @@ erpnext.ExerciseEditor = Class.extend({ this.exercise_cards = $('
').appendTo(this.wrapper); - this.row = $('
').appendTo(this.exercise_cards); + this.row = $('
').appendTo(this.wrapper); let me = this;