feat: Doctype filter for Patient History
diff --git a/erpnext/healthcare/page/patient_history/patient_history.css b/erpnext/healthcare/page/patient_history/patient_history.css
index 865d6ab..1bb5891 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.css
+++ b/erpnext/healthcare/page/patient_history/patient_history.css
@@ -109,6 +109,11 @@
padding-right: 0px;
}
+.patient-history-filter {
+ margin-left: 35px;
+ width: 25%;
+}
+
#page-medical_record .plot-wrapper {
padding: 20px 15px;
border-bottom: 1px solid #d1d8dd;
diff --git a/erpnext/healthcare/page/patient_history/patient_history.html b/erpnext/healthcare/page/patient_history/patient_history.html
index 60f4501..00b38e7 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.html
+++ b/erpnext/healthcare/page/patient_history/patient_history.html
@@ -10,6 +10,14 @@
<div id="chart" class="col-sm-12 patient_vital_charts">
</div>
</div>
+ <div class="col-sm-12 d-flex border-bottom py-3"></div>
+ <div class="row">
+ <div class="col-sm-12 d-flex">
+ <div class="patient-history-filter doctype-filter"></div>
+ <div class="patient-history-filter from-date-filter"></div>
+ <div class="patient-history-filter to-date-filter"></div>
+ </div>
+ </div>
<div class="col-sm-12 patient_documents_list">
</div>
<div class="col-sm-12 text-center py-3">
diff --git a/erpnext/healthcare/page/patient_history/patient_history.js b/erpnext/healthcare/page/patient_history/patient_history.js
index 5f1851f..40b86fd 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.js
+++ b/erpnext/healthcare/page/patient_history/patient_history.js
@@ -20,14 +20,16 @@
placeholder: __('Select Patient'),
only_select: true,
change: function(){
- if (pid != patient.get_value() && patient.get_value()) {
+ let patient_id = patient.get_value();
+ if (pid != patient_id && patient_id) {
me.start = 0;
me.page.main.find('.patient_documents_list').html('');
- get_documents(patient.get_value(), me);
- show_patient_info(patient.get_value(), me);
- show_patient_vital_charts(patient.get_value(), me, 'bp', 'mmHg', 'Blood Pressure');
+ setup_filters(patient_id, me)
+ get_documents(patient_id, me);
+ show_patient_info(patient_id, me);
+ show_patient_vital_charts(patient_id, me, 'bp', 'mmHg', 'Blood Pressure');
}
- pid = patient.get_value();
+ pid = patient_id;
}
},
});
@@ -93,14 +95,48 @@
});
};
-let get_documents = function(patient, me) {
+let setup_filters = function(patient, me) {
+ frappe.xcall(
+ 'erpnext.healthcare.page.patient_history.patient_history.get_patient_history_doctypes'
+ ).then(document_types => {
+ let doctype_filter = frappe.ui.form.make_control({
+ parent: $('.doctype-filter'),
+ df: {
+ fieldtype: 'MultiSelectList',
+ fieldname: 'document_type',
+ placeholder: __('Select Document Type'),
+ input_class: 'input-xs',
+ change: () => {
+ me.start = 0;
+ me.page.main.find('.patient_documents_list').html('');
+ get_documents(patient, me, doctype_filter.get_value());
+ },
+ get_data: () => {
+ return document_types.map(document_type => {
+ return {
+ description: document_type,
+ value: document_type
+ };
+ });
+ },
+ }
+ });
+ doctype_filter.refresh();
+ })
+}
+
+let get_documents = function(patient, me, document_types="") {
+ let filters = {
+ name: patient,
+ start: me.start,
+ page_length: 20
+ };
+ if (document_types)
+ filters['document_types'] = document_types;
+
frappe.call({
'method': 'erpnext.healthcare.page.patient_history.patient_history.get_feed',
- args: {
- name: patient,
- start: me.start,
- page_length: 20
- },
+ args: filters,
callback: function(r) {
let data = r.message;
if (data.length) {
diff --git a/erpnext/healthcare/page/patient_history/patient_history.py b/erpnext/healthcare/page/patient_history/patient_history.py
index 772aa4e..c04b376 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.py
+++ b/erpnext/healthcare/page/patient_history/patient_history.py
@@ -4,36 +4,53 @@
from __future__ import unicode_literals
import frappe
+import json
from frappe.utils import cint
from erpnext.healthcare.utils import render_docs_as_html
@frappe.whitelist()
-def get_feed(name, start=0, page_length=20):
+def get_feed(name, document_types=None, start=0, page_length=20):
"""get feed"""
- result = frappe.db.sql("""select name, owner, creation,
- reference_doctype, reference_name, subject
- from `tabPatient Medical Record`
- where patient=%(patient)s
- order by creation desc
- limit %(start)s, %(page_length)s""",
- {
- "patient": name,
- "start": cint(start),
- "page_length": cint(page_length)
- }, as_dict=True)
+ filters = {'patient': name}
+ if document_types:
+ document_types = json.loads(document_types)
+ filters['reference_doctype'] = ['IN', document_types]
+
+ result = frappe.db.get_all('Patient Medical Record',
+ fields=['name', 'owner', 'creation',
+ 'reference_doctype', 'reference_name', 'subject'],
+ filters=filters,
+ order_by='creation DESC',
+ limit=cint(page_length),
+ start=cint(start)
+ )
+
return result
@frappe.whitelist()
def get_feed_for_dt(doctype, docname):
"""get feed"""
- result = frappe.db.sql("""select name, owner, modified, creation,
- reference_doctype, reference_name, subject
- from `tabPatient Medical Record`
- where reference_name=%(docname)s and reference_doctype=%(doctype)s
- order by creation desc""",
- {
- "docname": docname,
- "doctype": doctype
- }, as_dict=True)
+ result = frappe.db.get_all('Patient Medical Record',
+ fields=['name', 'owner', 'creation',
+ 'reference_doctype', 'reference_name', 'subject'],
+ filters={
+ 'reference_doctype': doctype,
+ 'reference_name': docname
+ },
+ order_by='creation DESC'
+ )
return result
+
+@frappe.whitelist()
+def get_patient_history_doctypes():
+ document_types = []
+ settings = frappe.get_single("Patient History Settings")
+
+ for entry in settings.standard_doctypes:
+ document_types.append(entry.document_type)
+
+ for entry in settings.custom_doctypes:
+ document_types.append(entry.document_type)
+
+ return document_types
\ No newline at end of file