From 75a93d90573ea97391b6ca03d8a404d681588a69 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 22 Jan 2021 15:51:25 +0530 Subject: [PATCH] feat: fetch date field for custom doctypes --- .../patient_history_settings.js | 23 +++++++++++++++++++ .../patient_history_settings.py | 8 +++++++ 2 files changed, 31 insertions(+) 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 5ea17af459..17324495e6 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 @@ frappe.ui.form.on('Patient History Settings', { }); 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 9ef97214c5..2e8c994c3d 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 @@ class PatientHistorySettings(Document): 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)