feat: fetch date field for custom doctypes
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 5ea17af..1732449 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
@@ -85,10 +85,33 @@
});
d.show();
+ },
+
+ get_date_field_for_dt: function(frm, row) {
+ frm.call({
+ method: 'get_date_field_for_dt',
+ doc: frm.doc,
+ args: {
+ document_type: row.document_type
+ },
+ callback: function(data) {
+ if (data.message) {
+ frappe.model.set_value('Patient History Custom Document Type',
+ row.name, 'date_fieldname', data.message);
+ }
+ }
+ });
}
});
frappe.ui.form.on('Patient History Custom Document Type', {
+ document_type: function(frm, cdt, cdn) {
+ let row = locals[cdt][cdn];
+ if (row.document_type) {
+ frm.events.get_date_field_for_dt(frm, row);
+ }
+ },
+
add_edit_fields: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.document_type) {
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 9ef9721..2e8c994 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
@@ -49,6 +49,14 @@
return multicheck_fields
+ def get_date_field_for_dt(self, document_type):
+ meta = frappe.get_meta(document_type)
+ date_fields = meta.get('fields', {
+ 'fieldtype': ['in', ['Date', 'Datetime']]
+ })
+
+ if date_fields:
+ return date_fields[0].get('fieldname')
def create_medical_record(doc, method=None):
medical_record_required = validate_medical_record_required(doc)