refactor: move call to fetch doctype fields to server-side
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 ee36346..bf3c5b9 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
@@ -18,7 +18,27 @@
if (doc.selected_fields)
document_fields = (JSON.parse(doc.selected_fields)).map(f => f.fieldname);
- let doctype_fields = frm.events.get_doctype_fields(frm, doc.document_type, document_fields);
+ frm.call({
+ method: 'get_doctype_fields',
+ doc: frm.doc,
+ args: {
+ document_type: doc.document_type,
+ fields: document_fields
+ },
+ freeze: true,
+ callback: function(r) {
+ if (r.message) {
+ let doctype = 'Patient History Custom Document Type';
+ if (standard)
+ doctype = 'Patient History Standard Document Type';
+
+ frm.events.show_field_selector_dialog(frm, doc, doctype, r.message);
+ }
+ }
+ });
+ },
+
+ show_field_selector_dialog: function(frm, doc, doctype, doc_fields) {
let d = new frappe.ui.Dialog({
title: __('{0} Fields', [__(doc.document_type)]),
fields: [
@@ -26,7 +46,7 @@
label: __('Select Fields'),
fieldtype: 'MultiCheck',
fieldname: 'fields',
- options: doctype_fields,
+ options: doc_fields,
columns: 2
}
]
@@ -49,9 +69,6 @@
});
}
}
- let doctype = 'Patient History Custom Document Type';
- if (standard)
- doctype = 'Patient History Standard Document Type';
d.refresh();
frappe.model.set_value(doctype, doc.name, 'selected_fields', JSON.stringify(selected_fields));
@@ -59,26 +76,6 @@
});
d.show();
- },
-
- get_doctype_fields(frm, document_type, fields) {
- let multiselect_fields = [];
-
- frappe.model.with_doctype(document_type, () => {
- // get doctype fields
- frappe.get_doc('DocType', document_type).fields.forEach(field => {
- if (!in_list(frappe.model.no_value_type, field.fieldtype) ||
- in_list(frappe.model.table_fields, field.fieldtype) && !field.hidden) {
- multiselect_fields.push({
- label: field.label,
- value: field.fieldname,
- checked: in_list(fields, field.fieldname)
- });
- }
- });
- });
-
- return multiselect_fields;
}
});
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 367c34f..9f18c6b 100644
--- a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
+import json
from frappe import _
from frappe.utils import cstr
from frappe.model.document import Document
@@ -24,6 +25,21 @@
frappe.throw(_('Row #{0}: Field {1} in Document Type {2} is not a Date / Datetime field.').format(
entry.idx, frappe.bold(entry.date_fieldname), frappe.bold(entry.document_type)))
+ def get_doctype_fields(self, document_type, fields):
+ multicheck_fields = []
+ doc_fields = frappe.get_meta(document_type).fields
+
+ for field in doc_fields:
+ if field.fieldtype not in frappe.model.no_value_fields or \
+ field.fieldtype in frappe.model.table_fields and not field.hidden:
+ multicheck_fields.append({
+ 'label': field.label,
+ 'value': field.fieldname,
+ 'checked': 1 if field.fieldname in fields else 0
+ })
+
+ return multicheck_fields
+
def create_medical_record(doc, method=None):
medical_record_required = validate_medical_record_required(doc)
@@ -100,7 +116,6 @@
def get_patient_history_fields(doc):
- import json
dt = get_patient_history_config_dt(doc.doctype)
patient_history_fields = frappe.db.get_value(dt, { 'document_type': doc.doctype }, 'selected_fields')