feat: Create Patient Medical Record on configured doctype submission
This commit is contained in:
parent
f2932d7208
commit
c91e03c891
@ -40,7 +40,8 @@ frappe.ui.form.on('Patient History Settings', {
|
|||||||
if (field) {
|
if (field) {
|
||||||
selected_fields.push({
|
selected_fields.push({
|
||||||
label: field.label,
|
label: field.label,
|
||||||
fieldname: field.fieldname
|
fieldname: field.fieldname,
|
||||||
|
fieldtype: field.fieldtype
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +59,8 @@ frappe.ui.form.on('Patient History Settings', {
|
|||||||
frappe.model.with_doctype(document_type, () => {
|
frappe.model.with_doctype(document_type, () => {
|
||||||
// get doctype fields
|
// get doctype fields
|
||||||
frappe.get_doc('DocType', document_type).fields.forEach(field => {
|
frappe.get_doc('DocType', document_type).fields.forEach(field => {
|
||||||
if (!in_list(frappe.model.no_value_type, field.fieldtype) && !field.hidden) {
|
if (!in_list(frappe.model.no_value_type, field.fieldtype) ||
|
||||||
|
in_list(frappe.model.table_fields, field.fieldtype) && !field.hidden) {
|
||||||
multiselect_fields.push({
|
multiselect_fields.push({
|
||||||
label: field.label,
|
label: field.label,
|
||||||
value: field.fieldname,
|
value: field.fieldname,
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.utils import cstr
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class PatientHistorySettings(Document):
|
class PatientHistorySettings(Document):
|
||||||
@ -20,4 +21,54 @@ class PatientHistorySettings(Document):
|
|||||||
|
|
||||||
if field.fieldtype not in ['Date', 'Datetime']:
|
if field.fieldtype not in ['Date', 'Datetime']:
|
||||||
frappe.throw(_('Row #{0}: Field {1} in Document Type {2} is not a Date / Datetime field.').format(
|
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)))
|
entry.idx, frappe.bold(entry.date_fieldname), frappe.bold(entry.document_type)))
|
||||||
|
|
||||||
|
|
||||||
|
def create_medical_record(doc, method=None):
|
||||||
|
if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_setup_wizard or \
|
||||||
|
frappe.db.get_value('Doctype', doc.doctype, 'module') != 'Healthcare':
|
||||||
|
return
|
||||||
|
|
||||||
|
subject = set_subject_field(doc)
|
||||||
|
date_field = get_date_field(doc.doctype)
|
||||||
|
medical_record = frappe.new_doc('Patient Medical Record')
|
||||||
|
medical_record.patient = doc.patient
|
||||||
|
medical_record.subject = subject
|
||||||
|
medical_record.status = 'Open'
|
||||||
|
medical_record.communication_date = doc.get(date_field)
|
||||||
|
medical_record.reference_doctype = doc.doctype
|
||||||
|
medical_record.reference_name = doc.name
|
||||||
|
medical_record.reference_owner = doc.owner
|
||||||
|
medical_record.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
|
def set_subject_field(doc):
|
||||||
|
from frappe.utils.formatters import format_value
|
||||||
|
|
||||||
|
meta = frappe.get_meta(doc.doctype)
|
||||||
|
subject = ''
|
||||||
|
patient_history_fields = get_patient_history_fields(doc)
|
||||||
|
|
||||||
|
for entry in patient_history_fields:
|
||||||
|
fieldname = entry.get('fieldname')
|
||||||
|
if doc.get(fieldname):
|
||||||
|
formated_value = format_value(doc.get(fieldname), meta.get_field(fieldname), doc)
|
||||||
|
subject += frappe.bold(_(entry.get('label')) + ': ') + cstr(formated_value)
|
||||||
|
subject += '<br>'
|
||||||
|
|
||||||
|
return subject
|
||||||
|
|
||||||
|
|
||||||
|
def get_date_field(doctype):
|
||||||
|
return frappe.db.get_value('Patient History Custom Document Type',
|
||||||
|
{ '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')
|
||||||
|
|
||||||
|
if patient_history_fields:
|
||||||
|
return json.loads(patient_history_fields)
|
||||||
|
|
||||||
|
|||||||
@ -221,6 +221,10 @@ standard_queries = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doc_events = {
|
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.delete_medical_record"
|
||||||
|
},
|
||||||
"Stock Entry": {
|
"Stock Entry": {
|
||||||
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty",
|
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty",
|
||||||
"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty"
|
"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user