Merge pull request #16368 from ESS-LLP/pr_staging_fixes_2

feat: List Active Healthcare Practitioner
This commit is contained in:
Nabin Hait 2019-01-29 11:52:55 +05:30 committed by GitHub
commit 7fc9825954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1991 additions and 1885 deletions

View File

@ -43,7 +43,7 @@ class ClinicalProcedure(Document):
self.reload()
def complete(self):
if self.consume_stock:
if self.consume_stock and self.items:
create_stock_entry(self)
frappe.db.set_value("Clinical Procedure", self.name, "status", 'Completed')
@ -183,13 +183,15 @@ def create_procedure(appointment):
procedure.patient_age = appointment.patient_age
procedure.patient_sex = appointment.patient_sex
procedure.procedure_template = appointment.procedure_template
procedure.procedure_prescription = appointment.procedure_prescription
procedure.prescription = appointment.procedure_prescription
procedure.practitioner = appointment.practitioner
procedure.invoiced = appointment.invoiced
procedure.medical_department = appointment.department
procedure.start_date = appointment.appointment_date
procedure.start_time = appointment.appointment_time
procedure.notes = appointment.notes
procedure.service_unit = appointment.service_unit
procedure.company = appointment.company
consume_stock = frappe.db.get_value("Clinical Procedure Template", appointment.procedure_template, "consume_stock")
if consume_stock == 1:
procedure.consume_stock = True
@ -203,7 +205,9 @@ def create_procedure(appointment):
return procedure.as_dict()
def insert_clinical_procedure_to_medical_record(doc):
subject = cstr(doc.procedure_template) +" "+ doc.practitioner
subject = cstr(doc.procedure_template)
if doc.practitioner:
subject += " "+doc.practitioner
if subject and doc.notes:
subject += "<br/>"+doc.notes

View File

@ -68,6 +68,7 @@ def create_appointment(patient, practitioner, appointment_date, department):
appointment.department = department
appointment.appointment_date = appointment_date
appointment.company = "_Test Company"
appointment.duration = 15
appointment.save(ignore_permissions=True)
return appointment

View File

@ -1,5 +1,6 @@
{
"allow_copy": 1,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 1,
@ -431,6 +432,39 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "1",
"fieldname": "active",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Active",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
@ -927,7 +961,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-08-06 16:45:37.899084",
"modified": "2018-11-23 08:54:51.442105",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Healthcare Practitioner",

View File

@ -9,6 +9,7 @@ from frappe import throw, _
from frappe.utils import cstr
from erpnext.accounts.party import validate_party_accounts
from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address
from frappe.desk.reportview import build_match_conditions, get_filters_cond
class HealthcarePractitioner(Document):
def onload(self):
@ -65,3 +66,36 @@ class HealthcarePractitioner(Document):
def validate_service_item(item, msg):
if frappe.db.get_value("Item", item, "is_stock_item") == 1:
frappe.throw(_(msg))
def get_practitioner_list(doctype, txt, searchfield, start, page_len, filters=None):
fields = ["name", "first_name", "mobile_phone"]
match_conditions = build_match_conditions("Healthcare Practitioner")
match_conditions = "and {}".format(match_conditions) if match_conditions else ""
if filters:
filter_conditions = get_filters_cond(doctype, filters, [])
match_conditions += "{}".format(filter_conditions)
return frappe.db.sql("""select %s from `tabHealthcare Practitioner` where docstatus < 2
and (%s like %s or first_name like %s)
and active = 1
{match_conditions}
order by
case when name like %s then 0 else 1 end,
case when first_name like %s then 0 else 1 end,
name, first_name limit %s, %s""".format(
match_conditions=match_conditions) %
(
", ".join(fields),
frappe.db.escape(searchfield),
"%s", "%s", "%s", "%s", "%s", "%s"
),
(
"%%%s%%" % frappe.db.escape(txt),
"%%%s%%" % frappe.db.escape(txt),
"%%%s%%" % frappe.db.escape(txt),
"%%%s%%" % frappe.db.escape(txt),
start,
page_len
)
)

View File

@ -219,7 +219,7 @@
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "blood_group",
@ -252,7 +252,7 @@
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "dob",
@ -480,7 +480,7 @@
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "mobile",
@ -512,7 +512,7 @@
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "email",
@ -1391,7 +1391,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 50,
"modified": "2018-10-14 22:09:39.849116",
"modified": "2018-11-23 12:11:14.336657",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient",
@ -1456,7 +1456,7 @@
"write": 1
}
],
"quick_entry": 0,
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"restrict_to_domain": "Healthcare",

View File

@ -33,7 +33,6 @@ class Patient(Document):
"email": self.email,
"user_type": "Website User"
})
user.flags.no_welcome_email = True
user.flags.ignore_permissions = True
user.add_roles("Patient")

View File

@ -6,7 +6,7 @@ from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
import json
from frappe.utils import getdate, add_days
from frappe.utils import getdate, add_days, get_time
from frappe import _
import datetime
from frappe.core.doctype.sms_settings.sms_settings import send_sms
@ -24,9 +24,33 @@ class PatientAppointment(Document):
frappe.db.set_value("Patient Appointment", self.name, "status", "Open")
self.reload()
def validate(self):
end_time = datetime.datetime.combine(getdate(self.appointment_date), get_time(self.appointment_time)) + datetime.timedelta(minutes=float(self.duration))
overlaps = frappe.db.sql("""
select
name, practitioner, patient, appointment_time, duration
from
`tabPatient Appointment`
where
appointment_date=%s and name!=%s and status NOT IN ("Closed", "Cancelled")
and (practitioner=%s or patient=%s) and
((appointment_time<%s and appointment_time + INTERVAL duration MINUTE>%s) or
(appointment_time>%s and appointment_time<%s) or
(appointment_time=%s))
""", (self.appointment_date, self.name, self.practitioner, self.patient,
self.appointment_time, end_time.time(), self.appointment_time, end_time.time(), self.appointment_time))
if overlaps:
frappe.throw(_("""Appointment overlaps with {0}.<br> {1} has appointment scheduled
with {2} at {3} having {4} minute(s) duration.""").format(overlaps[0][0], overlaps[0][1], overlaps[0][2], overlaps[0][3], overlaps[0][4]))
def after_insert(self):
if self.procedure_prescription:
frappe.db.set_value("Procedure Prescription", self.procedure_prescription, "appointment_booked", True)
if self.procedure_template:
comments = frappe.db.get_value("Procedure Prescription", self.procedure_prescription, "comments")
if comments:
frappe.db.set_value("Patient Appointment", self.name, "notes", comments)
# Check fee validity exists
appointment = self
validity_exist = validity_exists(appointment.practitioner, appointment.patient)
@ -337,11 +361,19 @@ def get_events(start, end, filters=None):
from frappe.desk.calendar import get_event_conditions
conditions = get_event_conditions("Patient Appointment", filters)
data = frappe.db.sql("""select name, patient, practitioner, status,
duration, timestamp(appointment_date, appointment_time) as
'start' from `tabPatient Appointment` where
(appointment_date between %(start)s and %(end)s)
and docstatus < 2 {conditions}""".format(conditions=conditions),
data = frappe.db.sql("""
select
`tabPatient Appointment`.name, `tabPatient Appointment`.patient,
`tabPatient Appointment`.practitioner, `tabPatient Appointment`.status,
`tabPatient Appointment`.duration,
timestamp(`tabPatient Appointment`.appointment_date, `tabPatient Appointment`.appointment_time) as 'start',
`tabAppointment Type`.color
from
`tabPatient Appointment`
left join `tabAppointment Type` on `tabPatient Appointment`.appointment_type=`tabAppointment Type`.name
where
(`tabPatient Appointment`.appointment_date between %(start)s and %(end)s)
and `tabPatient Appointment`.status != 'Cancelled' and `tabPatient Appointment`.docstatus < 2 {conditions}""".format(conditions=conditions),
{"start": start, "end": end}, as_dict=True, update={"allDay": 0})
for item in data:

View File

@ -1,5 +1,6 @@
{
"allow_copy": 1,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
@ -460,7 +461,7 @@
"label": "Abdomen",
"length": 0,
"no_copy": 0,
"options": "\nBloated\nFull\nFluid\nConstipated",
"options": "\nNormal\nBloated\nFull\nFluid\nConstipated",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -936,7 +937,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-08-26 10:26:20.896305",
"modified": "2018-11-23 14:14:05.933292",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Vital Signs",

View File

@ -180,7 +180,8 @@ dump_report_map = "erpnext.startup.report_data_map.data_map"
before_tests = "erpnext.setup.utils.before_tests"
standard_queries = {
"Customer": "erpnext.selling.doctype.customer.customer.get_customer_list"
"Customer": "erpnext.selling.doctype.customer.customer.get_customer_list",
"Healthcare Practitioner": "erpnext.healthcare.doctype.healthcare_practitioner.healthcare_practitioner.get_practitioner_list"
}
doc_events = {