diff --git a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
index bf3c5b954e..92922b2888 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
@@ -7,7 +7,8 @@ frappe.ui.form.on('Patient History Settings', {
return {
filters: {
custom: 1,
- module: 'Healthcare'
+ is_submittable: 1,
+ module: 'Healthcare',
}
};
});
diff --git a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
index 7c7b6c8f4b..9ef97214c5 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
@@ -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
\ No newline at end of file
+ return True
+
+def get_module(doc):
+ module = doc.meta.module
+ if not module:
+ module = frappe.db.get_value('DocType', doc.doctype, 'module')
+
+ return module
\ No newline at end of file
diff --git a/erpnext/healthcare/doctype/patient_history_settings/test_patient_history_settings.py b/erpnext/healthcare/doctype/patient_history_settings/test_patient_history_settings.py
index 3190d84477..c93b788aed 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/test_patient_history_settings.py
+++ b/erpnext/healthcare/doctype/patient_history_settings/test_patient_history_settings.py
@@ -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 = "Date: {0}
Rating: 3
Feedback: Test Patient History Settings
".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())