feat: Standard doctype config for Patient History
This commit is contained in:
parent
f3df5c9f3c
commit
4097e89f8b
@ -13,7 +13,7 @@ frappe.ui.form.on('Patient History Settings', {
|
||||
});
|
||||
},
|
||||
|
||||
field_selector: function(frm, doc) {
|
||||
field_selector: function(frm, doc, standard=1) {
|
||||
let document_fields = (JSON.parse(doc.selected_fields)).map(f => f.fieldname);
|
||||
let d = new frappe.ui.Dialog({
|
||||
title: __('{0} Fields', [__(doc.document_type)]),
|
||||
@ -45,8 +45,12 @@ frappe.ui.form.on('Patient History Settings', {
|
||||
});
|
||||
}
|
||||
}
|
||||
let doctype = 'Patient History Custom Document Type';
|
||||
if (standard)
|
||||
doctype = 'Patient History Standard Document Type';
|
||||
|
||||
frappe.model.set_value('Patient History Custom Document Type', doc.name, 'selected_fields', JSON.stringify(selected_fields));
|
||||
|
||||
frappe.model.set_value(doctype, doc.name, 'selected_fields', JSON.stringify(selected_fields));
|
||||
d.hide();
|
||||
});
|
||||
|
||||
@ -75,6 +79,15 @@ frappe.ui.form.on('Patient History Settings', {
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Patient History Custom Document Type', {
|
||||
add_edit_fields: function(frm, cdt, cdn) {
|
||||
let row = locals[cdt][cdn];
|
||||
if (row.document_type) {
|
||||
frm.events.field_selector(frm, row, standard=0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Patient History Standard Document Type', {
|
||||
add_edit_fields: function(frm, cdt, cdn) {
|
||||
let row = locals[cdt][cdn];
|
||||
if (row.document_type) {
|
||||
|
@ -7,6 +7,7 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import cstr
|
||||
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):
|
||||
@ -29,6 +30,9 @@ def create_medical_record(doc, method=None):
|
||||
frappe.db.get_value('Doctype', doc.doctype, 'module') != 'Healthcare':
|
||||
return
|
||||
|
||||
if doc.doctype not in get_patient_history_doctypes():
|
||||
return
|
||||
|
||||
subject = set_subject_field(doc)
|
||||
date_field = get_date_field(doc.doctype)
|
||||
medical_record = frappe.new_doc('Patient Medical Record')
|
||||
@ -66,14 +70,15 @@ def set_subject_field(doc):
|
||||
|
||||
|
||||
def get_date_field(doctype):
|
||||
return frappe.db.get_value('Patient History Custom Document Type',
|
||||
{ 'document_type': doctype }, 'date_fieldname')
|
||||
dt = get_patient_history_config_dt(doctype)
|
||||
|
||||
return frappe.db.get_value(dt, { 'document_type': doctype }, 'date_fieldname')
|
||||
|
||||
|
||||
def get_patient_history_fields(doc):
|
||||
import json
|
||||
patient_history_fields = frappe.db.get_value('Patient History Custom Document Type',
|
||||
{ 'document_type': doc.doctype }, 'selected_fields')
|
||||
dt = get_patient_history_config_dt(doc.doctype)
|
||||
patient_history_fields = frappe.db.get_value(dt, { 'document_type': doc.doctype }, 'selected_fields')
|
||||
|
||||
if patient_history_fields:
|
||||
return json.loads(patient_history_fields)
|
||||
@ -99,6 +104,13 @@ def get_formatted_value_for_table_field(items, df):
|
||||
create_head = False
|
||||
table_row += '</tr>'
|
||||
|
||||
html += "<table class='table table-condensed table-bordered'>" + table_head + table_row + '</table>'
|
||||
html += "<table class='table table-condensed table-bordered'>" + table_head + table_row + "</table>"
|
||||
|
||||
return html
|
||||
|
||||
|
||||
def get_patient_history_config_dt(doctype):
|
||||
if frappe.db.get_value('DocType', doctype, 'custom'):
|
||||
return 'Patient History Custom Document Type'
|
||||
else:
|
||||
return 'Patient History Standard Document Type'
|
||||
|
@ -223,6 +223,7 @@ standard_queries = {
|
||||
doc_events = {
|
||||
"*": {
|
||||
"on_submit": "erpnext.healthcare.doctype.patient_history_settings.patient_history_settings.create_medical_record",
|
||||
"on_cancel": "erpnext.healthcare.doctype.patient_history_settings.patient_history_settings.update_medical_record",
|
||||
"on_cancel": "erpnext.healthcare.doctype.patient_history_settings.patient_history_settings.delete_medical_record"
|
||||
},
|
||||
"Stock Entry": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user