Merge branch 'tundebabzy-issue-11080' into hotfix
This commit is contained in:
commit
014b138074
@ -30,6 +30,14 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
frm.add_custom_button(__('Cancel'), function() {
|
||||
btn_update_status(frm, "Cancelled");
|
||||
});
|
||||
|
||||
frm.add_custom_button(__("Consultation"),function(){
|
||||
btn_create_consultation(frm);
|
||||
},"Create");
|
||||
|
||||
frm.add_custom_button(__('Vital Signs'), function() {
|
||||
btn_create_vital_signs(frm);
|
||||
},"Create");
|
||||
}
|
||||
if(frm.doc.status == "Pending"){
|
||||
frm.add_custom_button(__('Set Open'), function() {
|
||||
@ -40,14 +48,6 @@ frappe.ui.form.on('Patient Appointment', {
|
||||
});
|
||||
}
|
||||
|
||||
frm.add_custom_button(__("Consultation"),function(){
|
||||
btn_create_consultation(frm);
|
||||
},"Create");
|
||||
|
||||
frm.add_custom_button(__('Vital Signs'), function() {
|
||||
btn_create_vital_signs(frm);
|
||||
},"Create");
|
||||
|
||||
if(!frm.doc.__islocal){
|
||||
if(frm.doc.sales_invoice && frappe.user.has_role("Accounts User")){
|
||||
frm.add_custom_button(__('Invoice'), function() {
|
||||
@ -188,7 +188,7 @@ var btn_update_status = function(frm, status){
|
||||
frappe.call({
|
||||
method:
|
||||
"erpnext.healthcare.doctype.patient_appointment.patient_appointment.update_status",
|
||||
args: {appointmentId: doc.name, status:status},
|
||||
args: {appointment_id: doc.name, status:status},
|
||||
callback: function(data){
|
||||
if(!data.exc){
|
||||
frm.reload_doc();
|
||||
|
@ -234,6 +234,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:!doc.__islocal",
|
||||
"fieldname": "section_break_1",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
@ -755,7 +756,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-10-05 12:13:03.204936",
|
||||
"modified": "2017-10-25 23:33:36.060803",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Patient Appointment",
|
||||
|
@ -6,18 +6,20 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from frappe.utils import getdate
|
||||
from frappe.utils import getdate, cint
|
||||
from frappe import _
|
||||
import datetime
|
||||
from frappe.core.doctype.sms_settings.sms_settings import send_sms
|
||||
from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account,get_income_account
|
||||
|
||||
|
||||
class PatientAppointment(Document):
|
||||
def on_update(self):
|
||||
today = datetime.date.today()
|
||||
appointment_date = getdate(self.appointment_date)
|
||||
|
||||
# If appointment created for today set as open
|
||||
if(today == appointment_date):
|
||||
if today == appointment_date:
|
||||
frappe.db.set_value("Patient Appointment", self.name, "status", "Open")
|
||||
self.reload()
|
||||
|
||||
@ -27,46 +29,78 @@ class PatientAppointment(Document):
|
||||
validity_exist = validity_exists(appointment.physician, appointment.patient)
|
||||
if validity_exist:
|
||||
fee_validity = frappe.get_doc("Fee Validity", validity_exist[0][0])
|
||||
|
||||
# Check if the validity is valid
|
||||
appointment_date = getdate(appointment.appointment_date)
|
||||
if((fee_validity.valid_till >= appointment_date) and (fee_validity.visited < fee_validity.max_visit)):
|
||||
if (fee_validity.valid_till >= appointment_date) and (fee_validity.visited < fee_validity.max_visit):
|
||||
visited = fee_validity.visited + 1
|
||||
frappe.db.set_value("Fee Validity", fee_validity.name, "visited", visited)
|
||||
if(fee_validity.ref_invoice):
|
||||
if fee_validity.ref_invoice:
|
||||
frappe.db.set_value("Patient Appointment", appointment.name, "sales_invoice", fee_validity.ref_invoice)
|
||||
frappe.msgprint(_("{0} has fee validity till {1}").format(appointment.patient, fee_validity.valid_till))
|
||||
confirm_sms(self)
|
||||
|
||||
def appointment_cancel(appointmentId):
|
||||
appointment = frappe.get_doc("Patient Appointment",appointmentId)
|
||||
def save(self, *args, **kwargs):
|
||||
# duration is the only changeable field in the document
|
||||
if not self.is_new():
|
||||
self.db_set('duration', cint(self.duration))
|
||||
else:
|
||||
super(PatientAppointment, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
def appointment_cancel(appointment_id):
|
||||
appointment = frappe.get_doc("Patient Appointment", appointment_id)
|
||||
|
||||
# If invoice --> fee_validity update with -1 visit
|
||||
if (appointment.sales_invoice):
|
||||
if appointment.sales_invoice:
|
||||
validity = frappe.db.exists({"doctype": "Fee Validity", "ref_invoice": appointment.sales_invoice})
|
||||
if(validity):
|
||||
if validity:
|
||||
fee_validity = frappe.get_doc("Fee Validity", validity[0][0])
|
||||
visited = fee_validity.visited - 1
|
||||
frappe.db.set_value("Fee Validity", fee_validity.name, "visited", visited)
|
||||
if visited <= 0:
|
||||
frappe.msgprint(_("Appointment cancelled, Please review and cancel the invoice {0}".format(appointment.sales_invoice)))
|
||||
frappe.msgprint(
|
||||
_("Appointment cancelled, Please review and cancel the invoice {0}".format(appointment.sales_invoice))
|
||||
)
|
||||
else:
|
||||
frappe.msgprint(_("Appointment cancelled"))
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_availability_data(date, physician):
|
||||
# get availability data of 'physician' on 'date'
|
||||
"""
|
||||
Get availability data of 'physician' on 'date'
|
||||
:param date: Date to check in schedule
|
||||
:param physician: Name of the physician
|
||||
:return: dict containing a list of available slots, list of appointments and time of appointments
|
||||
"""
|
||||
|
||||
date = getdate(date)
|
||||
weekday = date.strftime("%A")
|
||||
|
||||
available_slots = []
|
||||
physician_schedule_name = None
|
||||
physician_schedule = None
|
||||
time_per_appointment = None
|
||||
|
||||
# get physicians schedule
|
||||
physician_schedule_name = frappe.db.get_value("Physician", physician, "physician_schedule")
|
||||
if physician_schedule_name:
|
||||
physician_schedule = frappe.get_doc("Physician Schedule", physician_schedule_name)
|
||||
time_per_appointment = frappe.db.get_value("Physician", physician, "time_per_appointment")
|
||||
else:
|
||||
frappe.throw(_("Dr {0} does not have a Physician Schedule. Add it in Physician master".format(physician)))
|
||||
|
||||
if physician_schedule:
|
||||
for t in physician_schedule.time_slots:
|
||||
if weekday == t.day:
|
||||
available_slots.append(t)
|
||||
|
||||
# `time_per_appointment` should never be None since validation in `Patient` is supposed to prevent
|
||||
# that. However, it isn't impossible so we'll prepare for that.
|
||||
if not time_per_appointment:
|
||||
frappe.throw(_('"Time Per Appointment" hasn"t been set for Dr {0}. Add it in Physician master.').format(physician))
|
||||
|
||||
# if physician not available return
|
||||
if not available_slots:
|
||||
# TODO: return available slots in nearby dates
|
||||
@ -89,27 +123,36 @@ def get_availability_data(date, physician):
|
||||
"time_per_appointment": time_per_appointment
|
||||
}
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_status(appointmentId, status):
|
||||
frappe.db.set_value("Patient Appointment",appointmentId,"status",status)
|
||||
if(status=="Cancelled"):
|
||||
appointment_cancel(appointmentId)
|
||||
def update_status(appointment_id, status):
|
||||
frappe.db.set_value("Patient Appointment", appointment_id, "status", status)
|
||||
if status == "Cancelled":
|
||||
appointment_cancel(appointment_id)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_open_appointments():
|
||||
today = getdate()
|
||||
frappe.db.sql("""update `tabPatient Appointment` set status='Open' where status = 'Scheduled' and appointment_date = %s""",(today))
|
||||
frappe.db.sql(
|
||||
"update `tabPatient Appointment` set status='Open' where status = 'Scheduled'"
|
||||
" and appointment_date = %s", today)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_pending_appointments():
|
||||
today = getdate()
|
||||
frappe.db.sql("""update `tabPatient Appointment` set status='Pending' where status in ('Scheduled','Open') and appointment_date < %s""",(today))
|
||||
frappe.db.sql(
|
||||
"update `tabPatient Appointment` set status='Pending' where status in "
|
||||
"('Scheduled','Open') and appointment_date < %s", today)
|
||||
|
||||
|
||||
def confirm_sms(doc):
|
||||
if (frappe.db.get_value("Healthcare Settings", None, "app_con")=='1'):
|
||||
if frappe.db.get_value("Healthcare Settings", None, "app_con") == '1':
|
||||
message = frappe.db.get_value("Healthcare Settings", None, "app_con_msg")
|
||||
send_message(doc, message)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_invoice(company, physician, patient, appointment_id, appointment_date):
|
||||
if not appointment_id:
|
||||
@ -134,6 +177,7 @@ def create_invoice(company, physician, patient, appointment_id, appointment_date
|
||||
frappe.db.set_value("Consultation", consultation[0][0], "invoice", sales_invoice.name)
|
||||
return sales_invoice.name
|
||||
|
||||
|
||||
def get_fee_validity(physician, patient, date):
|
||||
validity_exist = validity_exists(physician, patient)
|
||||
if validity_exist:
|
||||
@ -143,12 +187,14 @@ def get_fee_validity(physician, patient, date):
|
||||
fee_validity = create_fee_validity(physician, patient, date)
|
||||
return fee_validity
|
||||
|
||||
|
||||
def validity_exists(physician, patient):
|
||||
return frappe.db.exists({
|
||||
"doctype": "Fee Validity",
|
||||
"physician": physician,
|
||||
"patient": patient})
|
||||
|
||||
|
||||
def update_fee_validity(fee_validity, date):
|
||||
max_visit = frappe.db.get_value("Healthcare Settings", None, "max_visit")
|
||||
valid_days = frappe.db.get_value("Healthcare Settings", None, "valid_days")
|
||||
@ -164,6 +210,7 @@ def update_fee_validity(fee_validity, date):
|
||||
fee_validity.save(ignore_permissions=True)
|
||||
return fee_validity
|
||||
|
||||
|
||||
def create_fee_validity(physician, patient, date):
|
||||
fee_validity = frappe.new_doc("Fee Validity")
|
||||
fee_validity.physician = physician
|
||||
@ -171,6 +218,7 @@ def create_fee_validity(physician, patient, date):
|
||||
fee_validity = update_fee_validity(fee_validity, date)
|
||||
return fee_validity
|
||||
|
||||
|
||||
def create_invoice_items(appointment_id, physician, company, invoice):
|
||||
item_line = invoice.append("items")
|
||||
item_line.item_name = "Consulting Charges"
|
||||
@ -185,6 +233,7 @@ def create_invoice_items(appointment_id, physician, company, invoice):
|
||||
item_line.amount = op_consulting_charge
|
||||
return invoice
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_consultation(appointment):
|
||||
appointment = frappe.get_doc("Patient Appointment", appointment)
|
||||
@ -199,12 +248,17 @@ def create_consultation(appointment):
|
||||
consultation.invoice = appointment.sales_invoice
|
||||
return consultation.as_dict()
|
||||
|
||||
def remind_appointment():
|
||||
if (frappe.db.get_value("Healthcare Settings", None, "app_rem")=='1'):
|
||||
rem_before = datetime.datetime.strptime(frappe.get_value("Healthcare Settings", None, "rem_before"), "%H:%M:%S")
|
||||
rem_dt = datetime.datetime.now() + datetime.timedelta(hours = rem_before.hour, minutes=rem_before.minute, seconds= rem_before.second)
|
||||
|
||||
appointment_list = frappe.db.sql("select name from `tabPatient Appointment` where start_dt between %s and %s and reminded = 0 ", (datetime.datetime.now(), rem_dt))
|
||||
def remind_appointment():
|
||||
if frappe.db.get_value("Healthcare Settings", None, "app_rem") == '1':
|
||||
rem_before = datetime.datetime.strptime(frappe.get_value("Healthcare Settings", None, "rem_before"), "%H:%M:%S")
|
||||
rem_dt = datetime.datetime.now() + datetime.timedelta(
|
||||
hours=rem_before.hour, minutes=rem_before.minute, seconds=rem_before.second)
|
||||
|
||||
appointment_list = frappe.db.sql(
|
||||
"select name from `tabPatient Appointment` where start_dt between %s and %s and reminded = 0 ",
|
||||
(datetime.datetime.now(), rem_dt)
|
||||
)
|
||||
|
||||
for i in range(0, len(appointment_list)):
|
||||
doc = frappe.get_doc("Patient Appointment", appointment_list[i][0])
|
||||
@ -212,17 +266,20 @@ def remind_appointment():
|
||||
send_message(doc, message)
|
||||
frappe.db.set_value("Patient Appointment", doc.name, "reminded",1)
|
||||
|
||||
|
||||
def send_message(doc, message):
|
||||
patient = frappe.get_doc("Patient", doc.patient)
|
||||
if(patient.mobile):
|
||||
if patient.mobile:
|
||||
context = {"doc": doc, "alert": doc, "comments": None}
|
||||
if doc.get("_comments"):
|
||||
context["comments"] = json.loads(doc.get("_comments"))
|
||||
|
||||
# jinja to string convertion happens here
|
||||
message = frappe.render_template(message, context)
|
||||
number = [patient.mobile]
|
||||
send_sms(number, message)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_events(start, end, filters=None):
|
||||
"""Returns events for Gantt / Calendar view rendering.
|
||||
|
@ -501,6 +501,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"description": "In minutes",
|
||||
"fieldname": "time_per_appointment",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
@ -809,7 +810,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-10-04 17:35:44.363742",
|
||||
"modified": "2017-10-05 16:08:24.624644",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Physician",
|
||||
|
@ -20,22 +20,32 @@ class Physician(Document):
|
||||
[cstr(self.get(f)).strip() for f in ["first_name","middle_name","last_name"]]))
|
||||
|
||||
def validate(self):
|
||||
self.validate_schedule_and_time()
|
||||
validate_party_accounts(self)
|
||||
|
||||
if self.user_id:
|
||||
self.validate_for_enabled_user_id()
|
||||
self.validate_duplicate_user_id()
|
||||
existing_user_id = frappe.db.get_value("Physician", self.name, "user_id")
|
||||
if(self.user_id != existing_user_id):
|
||||
if self.user_id != existing_user_id:
|
||||
frappe.permissions.remove_user_permission(
|
||||
"Physician", self.name, existing_user_id)
|
||||
|
||||
|
||||
else:
|
||||
existing_user_id = frappe.db.get_value("Physician", self.name, "user_id")
|
||||
if existing_user_id:
|
||||
frappe.permissions.remove_user_permission(
|
||||
"Physician", self.name, existing_user_id)
|
||||
|
||||
def validate_schedule_and_time(self):
|
||||
if (self.physician_schedule or self.time_per_appointment) and \
|
||||
not (self.physician_schedule and self.time_per_appointment):
|
||||
frappe.msgprint(
|
||||
_('Both "Physician Schedule" and Time Per Appointment" must be set for Dr {0}').format(
|
||||
self.first_name),
|
||||
title='Error', raise_exception=1, indicator='red'
|
||||
)
|
||||
|
||||
def on_update(self):
|
||||
if self.user_id:
|
||||
frappe.permissions.add_user_permission("Physician", self.name, self.user_id)
|
||||
|
@ -3,8 +3,35 @@
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
import unittest
|
||||
import frappe
|
||||
|
||||
test_dependencies = ['Physician Schedule']
|
||||
|
||||
# test_records = frappe.get_test_records('Physician')
|
||||
|
||||
class TestPhysician(unittest.TestCase):
|
||||
pass
|
||||
def tearDown(self):
|
||||
frappe.delete_doc_if_exists('Physician', '_Testdoctor2', force=1)
|
||||
|
||||
def test_schedule_and_time(self):
|
||||
physician = frappe.new_doc('Physician')
|
||||
physician.first_name = '_Testdoctor2'
|
||||
physician.physician_schedule = '_Test Testdoctor Schedule'
|
||||
|
||||
self.assertRaises(frappe.ValidationError, physician.insert)
|
||||
|
||||
physician.physician_schedule = ''
|
||||
physician.time_per_appointment = 15
|
||||
|
||||
self.assertRaises(frappe.ValidationError, physician.insert)
|
||||
|
||||
physician.physician_schedule = '_Test Testdoctor Schedule'
|
||||
physician.time_per_appointment = 15
|
||||
|
||||
physician.insert()
|
||||
|
||||
def test_new_physician_without_schedule(self):
|
||||
physician = frappe.new_doc('Physician')
|
||||
physician.first_name = '_Testdoctor2'
|
||||
|
||||
physician.insert()
|
||||
self.assertEqual(frappe.get_value('Physician', '_Testdoctor2', 'first_name'), '_Testdoctor2')
|
||||
|
@ -5,5 +5,7 @@
|
||||
from __future__ import unicode_literals
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class PhysicianSchedule(Document):
|
||||
pass
|
||||
def autoname(self):
|
||||
self.name = self.schedule_name
|
||||
|
Loading…
x
Reference in New Issue
Block a user