From 81b28b899843dcbf66d5c2cc241429e363ab04ac Mon Sep 17 00:00:00 2001 From: Chillar Anand Date: Wed, 25 Aug 2021 20:08:11 +0530 Subject: [PATCH] fix(healthcare): Removed ignore user permissions flag in appointment (#27129) --- .../healthcare_practitioner.json | 5 ++- .../patient_appointment.json | 1 - .../test_patient_appointment.py | 43 +++++++++++++++++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json index 8162f03f6dc..cb455eb5014 100644 --- a/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json +++ b/erpnext/healthcare/doctype/healthcare_practitioner/healthcare_practitioner.json @@ -282,7 +282,7 @@ ], "image_field": "image", "links": [], - "modified": "2021-01-22 10:14:43.187675", + "modified": "2021-08-24 10:42:08.513054", "modified_by": "Administrator", "module": "Healthcare", "name": "Healthcare Practitioner", @@ -295,6 +295,7 @@ "read": 1, "report": 1, "role": "Laboratory User", + "select": 1, "share": 1, "write": 1 }, @@ -307,6 +308,7 @@ "read": 1, "report": 1, "role": "Physician", + "select": 1, "share": 1, "write": 1 }, @@ -319,6 +321,7 @@ "read": 1, "report": 1, "role": "Nursing User", + "select": 1, "share": 1, "write": 1 } diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json index 6e996bd128b..73ec3bc325f 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json @@ -142,7 +142,6 @@ { "fieldname": "practitioner", "fieldtype": "Link", - "ignore_user_permissions": 1, "in_standard_filter": 1, "label": "Healthcare Practitioner", "options": "Healthcare Practitioner", diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 2df6921b14f..9c3392cd5b2 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -199,10 +199,33 @@ class TestPatientAppointment(unittest.TestCase): assert new_invoice_count == invoice_count + 1 + def test_patient_appointment_should_consider_permissions_while_fetching_appointments(self): + patient, medical_department, practitioner = create_healthcare_docs() + create_appointment(patient, practitioner, nowdate()) + + patient, medical_department, new_practitioner = create_healthcare_docs(practitioner_name='Dr. John') + create_appointment(patient, new_practitioner, nowdate()) + + roles = [{"doctype": "Has Role", "role": "Physician"}] + user = create_user(roles=roles) + new_practitioner = frappe.get_doc('Healthcare Practitioner', new_practitioner) + new_practitioner.user_id = user.email + new_practitioner.save() + + frappe.set_user(user.name) + appointments = frappe.get_list('Patient Appointment') + assert len(appointments) == 1 + + frappe.set_user("Administrator") + appointments = frappe.get_list('Patient Appointment') + assert len(appointments) == 2 + +def create_healthcare_docs(practitioner_name=None): + if not practitioner_name: + practitioner_name = '_Test Healthcare Practitioner' -def create_healthcare_docs(): patient = create_patient() - practitioner = frappe.db.exists('Healthcare Practitioner', '_Test Healthcare Practitioner') + practitioner = frappe.db.exists('Healthcare Practitioner', practitioner_name) medical_department = frappe.db.exists('Medical Department', '_Test Medical Department') if not medical_department: @@ -213,7 +236,7 @@ def create_healthcare_docs(): if not practitioner: practitioner = frappe.new_doc('Healthcare Practitioner') - practitioner.first_name = '_Test Healthcare Practitioner' + practitioner.first_name = practitioner_name practitioner.gender = 'Female' practitioner.department = medical_department practitioner.op_consulting_charge = 500 @@ -319,3 +342,17 @@ def create_appointment_type(args=None): 'price_list': args.get('price_list') or frappe.db.get_value("Price List", {"selling": 1}), 'items': args.get('items') or items }).insert() + +def create_user(email=None, roles=None): + if not email: + email = '{}@frappe.com'.format(frappe.utils.random_string(10)) + user = frappe.db.exists('User', email) + if not user: + user = frappe.get_doc({ + "doctype": "User", + "email": email, + "first_name": "test_user", + "password": "password", + "roles": roles, + }).insert() + return user