feat: Only allow submittable doctypes for Patient Medical Record

This commit is contained in:
Rucha Mahabal 2021-01-15 02:12:57 +05:30
parent b15a19c6e0
commit 1873c389e5
3 changed files with 25 additions and 8 deletions

View File

@ -7,7 +7,8 @@ frappe.ui.form.on('Patient History Settings', {
return {
filters: {
custom: 1,
module: 'Healthcare'
is_submittable: 1,
module: 'Healthcare',
}
};
});

View File

@ -6,14 +6,23 @@ from __future__ import unicode_literals
import frappe
import json
from frappe import _
from frappe.utils import cstr
from frappe.utils import cstr, cint
from frappe.model.document import Document
from erpnext.healthcare.page.patient_history.patient_history import get_patient_history_doctypes
class PatientHistorySettings(Document):
def validate(self):
self.validate_submittable_doctypes()
self.validate_date_fieldnames()
def validate_submittable_doctypes(self):
for entry in self.custom_doctypes:
if not cint(frappe.db.get_value('DocType', entry.document_type, 'is_submittable')):
msg = _('Row #{0}: Document Type {1} is not submittable. ').format(
entry.idx, frappe.bold(entry.document_type))
msg += _('Patient Medical Record can only be created for submittable document types.')
frappe.throw(msg)
def validate_date_fieldnames(self):
for entry in self.custom_doctypes:
field = frappe.get_meta(entry.document_type).get_field(entry.date_fieldname)
@ -155,10 +164,17 @@ def get_patient_history_config_dt(doctype):
def validate_medical_record_required(doc):
if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_setup_wizard \
or doc.meta.module != 'Healthcare':
or get_module(doc) != 'Healthcare':
return False
if doc.doctype not in get_patient_history_doctypes():
return False
return True
return True
def get_module(doc):
module = doc.meta.module
if not module:
module = frappe.db.get_value('DocType', doc.doctype, 'module')
return module

View File

@ -12,7 +12,7 @@ from erpnext.healthcare.doctype.patient_appointment.test_patient_appointment imp
class TestPatientHistorySettings(unittest.TestCase):
def setUp(self):
dt = create_custom_doctype()
settings = frappe.get_single('Patient History Settings')
settings = frappe.get_single("Patient History Settings")
settings.append("custom_doctypes", {
"document_type": dt.name,
"date_fieldname": "date",
@ -40,12 +40,12 @@ class TestPatientHistorySettings(unittest.TestCase):
doc = create_doc(patient)
# check for medical record
medical_rec = frappe.db.exists('Patient Medical Record', {'status': 'Open', 'reference_name': doc.name})
medical_rec = frappe.db.exists("Patient Medical Record", {"status": "Open", "reference_name": doc.name})
self.assertTrue(medical_rec)
medical_rec = frappe.get_doc('Patient Medical Record', medical_rec)
medical_rec = frappe.get_doc("Patient Medical Record", medical_rec)
expected_subject = "<b>Date: </b>{0}<br><b>Rating: </b>3<br><b>Feedback: </b>Test Patient History Settings<br>".format(
getdate().strftime("%d-%m-%Y"))
frappe.utils.format_date(getdate()))
self.assertEqual(medical_rec.subject, expected_subject)
self.assertEqual(medical_rec.patient, patient)
self.assertEqual(medical_rec.communication_date, getdate())