mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 23:22:52 +00:00
Merge branch 'develop' of https://github.com/frappe/erpnext into rebrand-ui
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
"enable_free_follow_ups",
|
||||
"max_visits",
|
||||
"valid_days",
|
||||
"inpatient_settings_section",
|
||||
"allow_discharge_despite_unbilled_services",
|
||||
"do_not_bill_inpatient_encounters",
|
||||
"healthcare_service_items",
|
||||
"inpatient_visit_charge_item",
|
||||
"op_consulting_charge_item",
|
||||
@@ -302,11 +305,28 @@
|
||||
"fieldname": "enable_free_follow_ups",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enable Free Follow-ups"
|
||||
},
|
||||
{
|
||||
"fieldname": "inpatient_settings_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Inpatient Settings"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "allow_discharge_despite_unbilled_services",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Discharge Despite Unbilled Healthcare Services"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "do_not_bill_inpatient_encounters",
|
||||
"fieldtype": "Check",
|
||||
"label": "Do Not Bill Patient Encounters for Inpatients"
|
||||
}
|
||||
],
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2020-07-08 15:17:21.543218",
|
||||
"modified": "2021-01-13 09:04:35.877700",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Healthcare Settings",
|
||||
|
||||
@@ -5,6 +5,7 @@ frappe.ui.form.on('Inpatient Medication Entry', {
|
||||
refresh: function(frm) {
|
||||
// Ignore cancellation of doctype on cancel all
|
||||
frm.ignore_doctypes_on_cancel_all = ['Stock Entry'];
|
||||
frm.fields_dict['medication_orders'].grid.wrapper.find('.grid-add-row').hide();
|
||||
|
||||
frm.set_query('item_code', () => {
|
||||
return {
|
||||
|
||||
@@ -139,7 +139,6 @@
|
||||
"fieldtype": "Table",
|
||||
"label": "Inpatient Medication Orders",
|
||||
"options": "Inpatient Medication Entry Detail",
|
||||
"read_only": 1,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -180,7 +179,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-11-03 13:22:37.820707",
|
||||
"modified": "2021-01-11 12:37:46.749659",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Inpatient Medication Entry",
|
||||
|
||||
@@ -15,8 +15,6 @@ class InpatientMedicationEntry(Document):
|
||||
self.validate_medication_orders()
|
||||
|
||||
def get_medication_orders(self):
|
||||
self.validate_datetime_filters()
|
||||
|
||||
# pull inpatient medication orders based on selected filters
|
||||
orders = get_pending_medication_orders(self)
|
||||
|
||||
@@ -27,22 +25,6 @@ class InpatientMedicationEntry(Document):
|
||||
self.set('medication_orders', [])
|
||||
frappe.msgprint(_('No pending medication orders found for selected criteria'))
|
||||
|
||||
def validate_datetime_filters(self):
|
||||
if self.from_date and self.to_date:
|
||||
self.validate_from_to_dates('from_date', 'to_date')
|
||||
|
||||
if self.from_date and getdate(self.from_date) > getdate():
|
||||
frappe.throw(_('From Date cannot be after the current date.'))
|
||||
|
||||
if self.to_date and getdate(self.to_date) > getdate():
|
||||
frappe.throw(_('To Date cannot be after the current date.'))
|
||||
|
||||
if self.from_time and self.from_time > nowtime():
|
||||
frappe.throw(_('From Time cannot be after the current time.'))
|
||||
|
||||
if self.to_time and self.to_time > nowtime():
|
||||
frappe.throw(_('To Time cannot be after the current time.'))
|
||||
|
||||
def add_mo_to_table(self, orders):
|
||||
# Add medication orders in the child table
|
||||
self.set('medication_orders', [])
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe, json
|
||||
from frappe import _
|
||||
from frappe.utils import today, now_datetime, getdate, get_datetime
|
||||
from frappe.utils import today, now_datetime, getdate, get_datetime, get_link_to_form
|
||||
from frappe.model.document import Document
|
||||
from frappe.desk.reportview import get_match_cond
|
||||
|
||||
@@ -113,6 +113,7 @@ def schedule_inpatient(args):
|
||||
inpatient_record.status = 'Admission Scheduled'
|
||||
inpatient_record.save(ignore_permissions = True)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def schedule_discharge(args):
|
||||
discharge_order = json.loads(args)
|
||||
@@ -126,16 +127,19 @@ def schedule_discharge(args):
|
||||
frappe.db.set_value('Patient', discharge_order['patient'], 'inpatient_status', inpatient_record.status)
|
||||
frappe.db.set_value('Patient Encounter', inpatient_record.discharge_encounter, 'inpatient_status', inpatient_record.status)
|
||||
|
||||
|
||||
def set_details_from_ip_order(inpatient_record, ip_order):
|
||||
for key in ip_order:
|
||||
inpatient_record.set(key, ip_order[key])
|
||||
|
||||
|
||||
def set_ip_child_records(inpatient_record, inpatient_record_child, encounter_child):
|
||||
for item in encounter_child:
|
||||
table = inpatient_record.append(inpatient_record_child)
|
||||
for df in table.meta.get('fields'):
|
||||
table.set(df.fieldname, item.get(df.fieldname))
|
||||
|
||||
|
||||
def check_out_inpatient(inpatient_record):
|
||||
if inpatient_record.inpatient_occupancies:
|
||||
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
||||
@@ -144,54 +148,88 @@ def check_out_inpatient(inpatient_record):
|
||||
inpatient_occupancy.check_out = now_datetime()
|
||||
frappe.db.set_value("Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant")
|
||||
|
||||
|
||||
def discharge_patient(inpatient_record):
|
||||
validate_invoiced_inpatient(inpatient_record)
|
||||
validate_inpatient_invoicing(inpatient_record)
|
||||
inpatient_record.discharge_date = today()
|
||||
inpatient_record.status = "Discharged"
|
||||
|
||||
inpatient_record.save(ignore_permissions = True)
|
||||
|
||||
def validate_invoiced_inpatient(inpatient_record):
|
||||
pending_invoices = []
|
||||
|
||||
def validate_inpatient_invoicing(inpatient_record):
|
||||
if frappe.db.get_single_value("Healthcare Settings", "allow_discharge_despite_unbilled_services"):
|
||||
return
|
||||
|
||||
pending_invoices = get_pending_invoices(inpatient_record)
|
||||
|
||||
if pending_invoices:
|
||||
message = _("Cannot mark Inpatient Record as Discharged since there are unbilled services. ")
|
||||
|
||||
formatted_doc_rows = ''
|
||||
|
||||
for doctype, docnames in pending_invoices.items():
|
||||
formatted_doc_rows += """
|
||||
<td>{0}</td>
|
||||
<td>{1}</td>
|
||||
</tr>""".format(doctype, docnames)
|
||||
|
||||
message += """
|
||||
<table class='table'>
|
||||
<thead>
|
||||
<th>{0}</th>
|
||||
<th>{1}</th>
|
||||
</thead>
|
||||
{2}
|
||||
</table>
|
||||
""".format(_("Healthcare Service"), _("Documents"), formatted_doc_rows)
|
||||
|
||||
frappe.throw(message, title=_("Unbilled Services"), is_minimizable=True, wide=True)
|
||||
|
||||
|
||||
def get_pending_invoices(inpatient_record):
|
||||
pending_invoices = {}
|
||||
if inpatient_record.inpatient_occupancies:
|
||||
service_unit_names = False
|
||||
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
||||
if inpatient_occupancy.invoiced != 1:
|
||||
if not inpatient_occupancy.invoiced:
|
||||
if service_unit_names:
|
||||
service_unit_names += ", " + inpatient_occupancy.service_unit
|
||||
else:
|
||||
service_unit_names = inpatient_occupancy.service_unit
|
||||
if service_unit_names:
|
||||
pending_invoices.append("Inpatient Occupancy (" + service_unit_names + ")")
|
||||
pending_invoices["Inpatient Occupancy"] = service_unit_names
|
||||
|
||||
docs = ["Patient Appointment", "Patient Encounter", "Lab Test", "Clinical Procedure"]
|
||||
|
||||
for doc in docs:
|
||||
doc_name_list = get_inpatient_docs_not_invoiced(doc, inpatient_record)
|
||||
doc_name_list = get_unbilled_inpatient_docs(doc, inpatient_record)
|
||||
if doc_name_list:
|
||||
pending_invoices = get_pending_doc(doc, doc_name_list, pending_invoices)
|
||||
|
||||
if pending_invoices:
|
||||
frappe.throw(_("Can not mark Inpatient Record Discharged, there are Unbilled Invoices {0}").format(", "
|
||||
.join(pending_invoices)), title=_('Unbilled Invoices'))
|
||||
return pending_invoices
|
||||
|
||||
|
||||
def get_pending_doc(doc, doc_name_list, pending_invoices):
|
||||
if doc_name_list:
|
||||
doc_ids = False
|
||||
for doc_name in doc_name_list:
|
||||
doc_link = get_link_to_form(doc, doc_name.name)
|
||||
if doc_ids:
|
||||
doc_ids += ", "+doc_name.name
|
||||
doc_ids += ", " + doc_link
|
||||
else:
|
||||
doc_ids = doc_name.name
|
||||
doc_ids = doc_link
|
||||
if doc_ids:
|
||||
pending_invoices.append(doc + " (" + doc_ids + ")")
|
||||
pending_invoices[doc] = doc_ids
|
||||
|
||||
return pending_invoices
|
||||
|
||||
def get_inpatient_docs_not_invoiced(doc, inpatient_record):
|
||||
|
||||
def get_unbilled_inpatient_docs(doc, inpatient_record):
|
||||
return frappe.db.get_list(doc, filters = {'patient': inpatient_record.patient,
|
||||
'inpatient_record': inpatient_record.name, 'docstatus': 1, 'invoiced': 0})
|
||||
|
||||
|
||||
def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None):
|
||||
inpatient_record.admitted_datetime = check_in
|
||||
inpatient_record.status = 'Admitted'
|
||||
@@ -203,6 +241,7 @@ def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=N
|
||||
frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_status', 'Admitted')
|
||||
frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_record', inpatient_record.name)
|
||||
|
||||
|
||||
def transfer_patient(inpatient_record, service_unit, check_in):
|
||||
item_line = inpatient_record.append('inpatient_occupancies', {})
|
||||
item_line.service_unit = service_unit
|
||||
@@ -212,6 +251,7 @@ def transfer_patient(inpatient_record, service_unit, check_in):
|
||||
|
||||
frappe.db.set_value("Healthcare Service Unit", service_unit, "occupancy_status", "Occupied")
|
||||
|
||||
|
||||
def patient_leave_service_unit(inpatient_record, check_out, leave_from):
|
||||
if inpatient_record.inpatient_occupancies:
|
||||
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
||||
@@ -221,6 +261,7 @@ def patient_leave_service_unit(inpatient_record, check_out, leave_from):
|
||||
frappe.db.set_value("Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant")
|
||||
inpatient_record.save(ignore_permissions = True)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_leave_from(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
@@ -8,6 +8,8 @@ import unittest
|
||||
from frappe.utils import now_datetime, today
|
||||
from frappe.utils.make_random import get_random
|
||||
from erpnext.healthcare.doctype.inpatient_record.inpatient_record import admit_patient, discharge_patient, schedule_discharge
|
||||
from erpnext.healthcare.doctype.lab_test.test_lab_test import create_patient_encounter
|
||||
from erpnext.healthcare.utils import get_encounters_to_invoice
|
||||
|
||||
class TestInpatientRecord(unittest.TestCase):
|
||||
def test_admit_and_discharge(self):
|
||||
@@ -40,6 +42,60 @@ class TestInpatientRecord(unittest.TestCase):
|
||||
self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_record"))
|
||||
self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_status"))
|
||||
|
||||
def test_allow_discharge_despite_unbilled_services(self):
|
||||
frappe.db.sql("""delete from `tabInpatient Record`""")
|
||||
setup_inpatient_settings(key="allow_discharge_despite_unbilled_services", value=1)
|
||||
patient = create_patient()
|
||||
# Schedule Admission
|
||||
ip_record = create_inpatient(patient)
|
||||
ip_record.expected_length_of_stay = 0
|
||||
ip_record.save(ignore_permissions = True)
|
||||
|
||||
# Admit
|
||||
service_unit = get_healthcare_service_unit()
|
||||
admit_patient(ip_record, service_unit, now_datetime())
|
||||
|
||||
# Discharge
|
||||
schedule_discharge(frappe.as_json({"patient": patient}))
|
||||
self.assertEqual("Vacant", frappe.db.get_value("Healthcare Service Unit", service_unit, "occupancy_status"))
|
||||
|
||||
ip_record = frappe.get_doc("Inpatient Record", ip_record.name)
|
||||
# Should not validate Pending Invoices
|
||||
ip_record.discharge()
|
||||
|
||||
self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_record"))
|
||||
self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_status"))
|
||||
|
||||
setup_inpatient_settings(key="allow_discharge_despite_unbilled_services", value=0)
|
||||
|
||||
def test_do_not_bill_patient_encounters_for_inpatients(self):
|
||||
frappe.db.sql("""delete from `tabInpatient Record`""")
|
||||
setup_inpatient_settings(key="do_not_bill_inpatient_encounters", value=1)
|
||||
patient = create_patient()
|
||||
# Schedule Admission
|
||||
ip_record = create_inpatient(patient)
|
||||
ip_record.expected_length_of_stay = 0
|
||||
ip_record.save(ignore_permissions = True)
|
||||
|
||||
# Admit
|
||||
service_unit = get_healthcare_service_unit()
|
||||
admit_patient(ip_record, service_unit, now_datetime())
|
||||
|
||||
# Patient Encounter
|
||||
patient_encounter = create_patient_encounter()
|
||||
encounters = get_encounters_to_invoice(patient, "_Test Company")
|
||||
encounter_ids = [entry.reference_name for entry in encounters]
|
||||
self.assertFalse(patient_encounter.name in encounter_ids)
|
||||
|
||||
# Discharge
|
||||
schedule_discharge(frappe.as_json({"patient": patient}))
|
||||
self.assertEqual("Vacant", frappe.db.get_value("Healthcare Service Unit", service_unit, "occupancy_status"))
|
||||
|
||||
ip_record = frappe.get_doc("Inpatient Record", ip_record.name)
|
||||
mark_invoiced_inpatient_occupancy(ip_record)
|
||||
discharge_patient(ip_record)
|
||||
setup_inpatient_settings(key="do_not_bill_inpatient_encounters", value=0)
|
||||
|
||||
def test_validate_overlap_admission(self):
|
||||
frappe.db.sql("""delete from `tabInpatient Record`""")
|
||||
patient = create_patient()
|
||||
@@ -63,6 +119,13 @@ def mark_invoiced_inpatient_occupancy(ip_record):
|
||||
inpatient_occupancy.invoiced = 1
|
||||
ip_record.save(ignore_permissions = True)
|
||||
|
||||
|
||||
def setup_inpatient_settings(key, value):
|
||||
settings = frappe.get_single("Healthcare Settings")
|
||||
settings.set(key, value)
|
||||
settings.save()
|
||||
|
||||
|
||||
def create_inpatient(patient):
|
||||
patient_obj = frappe.get_doc('Patient', patient)
|
||||
inpatient_record = frappe.new_doc('Inpatient Record')
|
||||
@@ -78,6 +141,7 @@ def create_inpatient(patient):
|
||||
inpatient_record.scheduled_date = today()
|
||||
return inpatient_record
|
||||
|
||||
|
||||
def get_healthcare_service_unit():
|
||||
service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1})
|
||||
if not service_unit:
|
||||
@@ -105,6 +169,7 @@ def get_healthcare_service_unit():
|
||||
return service_unit.name
|
||||
return service_unit
|
||||
|
||||
|
||||
def get_service_unit_type():
|
||||
service_unit_type = get_random("Healthcare Service Unit Type", filters={"inpatient_occupancy": 1})
|
||||
|
||||
@@ -116,6 +181,7 @@ def get_service_unit_type():
|
||||
return service_unit_type.name
|
||||
return service_unit_type
|
||||
|
||||
|
||||
def create_patient():
|
||||
patient = frappe.db.exists('Patient', '_Test IPD Patient')
|
||||
if not patient:
|
||||
|
||||
@@ -22,6 +22,7 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
filters: {'status': 'Active'}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('practitioner', function() {
|
||||
return {
|
||||
filters: {
|
||||
@@ -29,6 +30,7 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('service_unit', function(){
|
||||
return {
|
||||
filters: {
|
||||
@@ -39,6 +41,16 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('therapy_plan', function() {
|
||||
return {
|
||||
filters: {
|
||||
'patient': frm.doc.patient
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.trigger('set_therapy_type_filter');
|
||||
|
||||
if (frm.is_new()) {
|
||||
frm.page.set_primary_action(__('Check Availability'), function() {
|
||||
if (!frm.doc.patient) {
|
||||
@@ -136,6 +148,24 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
}
|
||||
},
|
||||
|
||||
therapy_plan: function(frm) {
|
||||
frm.trigger('set_therapy_type_filter');
|
||||
},
|
||||
|
||||
set_therapy_type_filter: function(frm) {
|
||||
if (frm.doc.therapy_plan) {
|
||||
frm.call('get_therapy_types').then(r => {
|
||||
frm.set_query('therapy_type', function() {
|
||||
return {
|
||||
filters: {
|
||||
'name': ['in', r.message]
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
therapy_type: function(frm) {
|
||||
if (frm.doc.therapy_type) {
|
||||
frappe.db.get_value('Therapy Type', frm.doc.therapy_type, 'default_duration', (r) => {
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
"procedure_template",
|
||||
"get_procedure_from_encounter",
|
||||
"procedure_prescription",
|
||||
"therapy_plan",
|
||||
"therapy_type",
|
||||
"get_prescribed_therapies",
|
||||
"therapy_plan",
|
||||
"practitioner",
|
||||
"practitioner_name",
|
||||
"department",
|
||||
@@ -284,7 +284,7 @@
|
||||
"report_hide": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.patient;",
|
||||
"depends_on": "eval:doc.patient && doc.therapy_plan;",
|
||||
"fieldname": "therapy_type",
|
||||
"fieldtype": "Link",
|
||||
"label": "Therapy",
|
||||
@@ -292,17 +292,16 @@
|
||||
"set_only_once": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.patient && doc.__islocal;",
|
||||
"depends_on": "eval:doc.patient && doc.therapy_plan && doc.__islocal;",
|
||||
"fieldname": "get_prescribed_therapies",
|
||||
"fieldtype": "Button",
|
||||
"label": "Get Prescribed Therapies"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: doc.patient && doc.therapy_type",
|
||||
"depends_on": "eval: doc.patient;",
|
||||
"fieldname": "therapy_plan",
|
||||
"fieldtype": "Link",
|
||||
"label": "Therapy Plan",
|
||||
"mandatory_depends_on": "eval: doc.patient && doc.therapy_type",
|
||||
"options": "Therapy Plan"
|
||||
},
|
||||
{
|
||||
@@ -348,7 +347,7 @@
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2020-05-21 03:04:21.400893",
|
||||
"modified": "2020-12-16 13:16:58.578503",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Patient Appointment",
|
||||
|
||||
@@ -91,6 +91,17 @@ class PatientAppointment(Document):
|
||||
if fee_validity:
|
||||
frappe.msgprint(_('{0} has fee validity till {1}').format(self.patient, fee_validity.valid_till))
|
||||
|
||||
def get_therapy_types(self):
|
||||
if not self.therapy_plan:
|
||||
return
|
||||
|
||||
therapy_types = []
|
||||
doc = frappe.get_doc('Therapy Plan', self.therapy_plan)
|
||||
for entry in doc.therapy_plan_details:
|
||||
therapy_types.append(entry.therapy_type)
|
||||
|
||||
return therapy_types
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def check_payment_fields_reqd(patient):
|
||||
@@ -145,7 +156,7 @@ def invoice_appointment(appointment_doc):
|
||||
sales_invoice.flags.ignore_mandatory = True
|
||||
sales_invoice.save(ignore_permissions=True)
|
||||
sales_invoice.submit()
|
||||
frappe.msgprint(_('Sales Invoice {0} created'.format(sales_invoice.name)), alert=True)
|
||||
frappe.msgprint(_('Sales Invoice {0} created').format(sales_invoice.name), alert=True)
|
||||
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'invoiced', 1)
|
||||
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'ref_sales_invoice', sales_invoice.name)
|
||||
|
||||
|
||||
@@ -23,8 +23,10 @@ class TestPatientAppointment(unittest.TestCase):
|
||||
self.assertEquals(appointment.status, 'Open')
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 2))
|
||||
self.assertEquals(appointment.status, 'Scheduled')
|
||||
create_encounter(appointment)
|
||||
encounter = create_encounter(appointment)
|
||||
self.assertEquals(frappe.db.get_value('Patient Appointment', appointment.name, 'status'), 'Closed')
|
||||
encounter.cancel()
|
||||
self.assertEquals(frappe.db.get_value('Patient Appointment', appointment.name, 'status'), 'Open')
|
||||
|
||||
def test_start_encounter(self):
|
||||
patient, medical_department, practitioner = create_healthcare_docs()
|
||||
|
||||
@@ -5,10 +5,10 @@ from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
import unittest
|
||||
from frappe.utils import getdate, flt
|
||||
from frappe.utils import getdate, flt, nowdate
|
||||
from erpnext.healthcare.doctype.therapy_type.test_therapy_type import create_therapy_type
|
||||
from erpnext.healthcare.doctype.therapy_plan.therapy_plan import make_therapy_session, make_sales_invoice
|
||||
from erpnext.healthcare.doctype.patient_appointment.test_patient_appointment import create_healthcare_docs, create_patient
|
||||
from erpnext.healthcare.doctype.patient_appointment.test_patient_appointment import create_healthcare_docs, create_patient, create_appointment
|
||||
|
||||
class TestTherapyPlan(unittest.TestCase):
|
||||
def test_creation_on_encounter_submission(self):
|
||||
@@ -28,6 +28,15 @@ class TestTherapyPlan(unittest.TestCase):
|
||||
frappe.get_doc(session).submit()
|
||||
self.assertEquals(frappe.db.get_value('Therapy Plan', plan.name, 'status'), 'Completed')
|
||||
|
||||
patient, medical_department, practitioner = create_healthcare_docs()
|
||||
appointment = create_appointment(patient, practitioner, nowdate())
|
||||
session = make_therapy_session(plan.name, plan.patient, 'Basic Rehab', '_Test Company', appointment.name)
|
||||
session = frappe.get_doc(session)
|
||||
session.submit()
|
||||
self.assertEquals(frappe.db.get_value('Patient Appointment', appointment.name, 'status'), 'Closed')
|
||||
session.cancel()
|
||||
self.assertEquals(frappe.db.get_value('Patient Appointment', appointment.name, 'status'), 'Open')
|
||||
|
||||
def test_therapy_plan_from_template(self):
|
||||
patient = create_patient()
|
||||
template = create_therapy_plan_template()
|
||||
|
||||
@@ -47,7 +47,7 @@ class TherapyPlan(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_therapy_session(therapy_plan, patient, therapy_type, company):
|
||||
def make_therapy_session(therapy_plan, patient, therapy_type, company, appointment=None):
|
||||
therapy_type = frappe.get_doc('Therapy Type', therapy_type)
|
||||
|
||||
therapy_session = frappe.new_doc('Therapy Session')
|
||||
@@ -58,6 +58,7 @@ def make_therapy_session(therapy_plan, patient, therapy_type, company):
|
||||
therapy_session.duration = therapy_type.default_duration
|
||||
therapy_session.rate = therapy_type.rate
|
||||
therapy_session.exercises = therapy_type.exercises
|
||||
therapy_session.appointment = appointment
|
||||
|
||||
if frappe.flags.in_test:
|
||||
therapy_session.start_date = today()
|
||||
|
||||
@@ -19,6 +19,15 @@ frappe.ui.form.on('Therapy Session', {
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('appointment', function() {
|
||||
|
||||
return {
|
||||
filters: {
|
||||
'status': ['in', ['Open', 'Scheduled']]
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
||||
@@ -43,7 +43,14 @@ class TherapySession(Document):
|
||||
self.update_sessions_count_in_therapy_plan()
|
||||
insert_session_medical_record(self)
|
||||
|
||||
def on_update(self):
|
||||
if self.appointment:
|
||||
frappe.db.set_value('Patient Appointment', self.appointment, 'status', 'Closed')
|
||||
|
||||
def on_cancel(self):
|
||||
if self.appointment:
|
||||
frappe.db.set_value('Patient Appointment', self.appointment, 'status', 'Open')
|
||||
|
||||
self.update_sessions_count_in_therapy_plan(on_cancel=True)
|
||||
|
||||
def update_sessions_count_in_therapy_plan(self, on_cancel=False):
|
||||
|
||||
@@ -77,11 +77,13 @@ def get_appointments_to_invoice(patient, company):
|
||||
|
||||
|
||||
def get_encounters_to_invoice(patient, company):
|
||||
if not isinstance(patient, str):
|
||||
patient = patient.name
|
||||
encounters_to_invoice = []
|
||||
encounters = frappe.get_list(
|
||||
'Patient Encounter',
|
||||
fields=['*'],
|
||||
filters={'patient': patient.name, 'company': company, 'invoiced': False, 'docstatus': 1}
|
||||
filters={'patient': patient, 'company': company, 'invoiced': False, 'docstatus': 1}
|
||||
)
|
||||
if encounters:
|
||||
for encounter in encounters:
|
||||
@@ -90,6 +92,10 @@ def get_encounters_to_invoice(patient, company):
|
||||
income_account = None
|
||||
service_item = None
|
||||
if encounter.practitioner:
|
||||
if encounter.inpatient_record and \
|
||||
frappe.db.get_single_value('Healthcare Settings', 'do_not_bill_inpatient_encounters'):
|
||||
continue
|
||||
|
||||
service_item, practitioner_charge = get_service_item_and_practitioner_charge(encounter)
|
||||
income_account = get_income_account(encounter.practitioner, encounter.company)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user