feat: date range filter for Patient History
diff --git a/erpnext/healthcare/page/patient_history/patient_history.html b/erpnext/healthcare/page/patient_history/patient_history.html
index 00b38e7..deaaa97 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.html
+++ b/erpnext/healthcare/page/patient_history/patient_history.html
@@ -14,8 +14,7 @@
<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 class="patient-history-filter date-filter"></div>
</div>
</div>
<div class="col-sm-12 patient_documents_list">
diff --git a/erpnext/healthcare/page/patient_history/patient_history.js b/erpnext/healthcare/page/patient_history/patient_history.js
index 40b86fd..5a6295b 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.js
+++ b/erpnext/healthcare/page/patient_history/patient_history.js
@@ -109,7 +109,7 @@
change: () => {
me.start = 0;
me.page.main.find('.patient_documents_list').html('');
- get_documents(patient, me, doctype_filter.get_value());
+ get_documents(patient, me, doctype_filter.get_value(), date_range_field.get_value());
},
get_data: () => {
return document_types.map(document_type => {
@@ -122,10 +122,29 @@
}
});
doctype_filter.refresh();
- })
+
+ let date_range_field = frappe.ui.form.make_control({
+ df: {
+ fieldtype: 'DateRange',
+ fieldname: 'date_range',
+ placeholder: __('Date Range'),
+ input_class: 'input-xs',
+ change: () => {
+ let selected_date_range = date_range_field.get_value();
+ if (selected_date_range && selected_date_range.length === 2) {
+ me.start = 0;
+ me.page.main.find('.patient_documents_list').html('');
+ get_documents(patient, me, doctype_filter.get_value(), selected_date_range);
+ }
+ }
+ },
+ parent: $('.date-filter')
+ });
+ date_range_field.refresh();
+ });
}
-let get_documents = function(patient, me, document_types="") {
+let get_documents = function(patient, me, document_types="", selected_date_range="") {
let filters = {
name: patient,
start: me.start,
@@ -133,6 +152,8 @@
};
if (document_types)
filters['document_types'] = document_types;
+ if (selected_date_range)
+ filters['date_range'] = selected_date_range;
frappe.call({
'method': 'erpnext.healthcare.page.patient_history.patient_history.get_feed',
diff --git a/erpnext/healthcare/page/patient_history/patient_history.py b/erpnext/healthcare/page/patient_history/patient_history.py
index b8494c9..de8a577 100644
--- a/erpnext/healthcare/page/patient_history/patient_history.py
+++ b/erpnext/healthcare/page/patient_history/patient_history.py
@@ -9,13 +9,9 @@
from erpnext.healthcare.utils import render_docs_as_html
@frappe.whitelist()
-def get_feed(name, document_types=None, start=0, page_length=20):
+def get_feed(name, document_types=None, date_range=None, start=0, page_length=20):
"""get feed"""
- filters = {'patient': name}
- if document_types:
- document_types = json.loads(document_types)
- if len(document_types):
- filters['reference_doctype'] = ['IN', document_types]
+ filters = get_filters(name, document_types, date_range)
result = frappe.db.get_all('Patient Medical Record',
fields=['name', 'owner', 'creation',
@@ -28,6 +24,25 @@
return result
+
+def get_filters(name, document_types=None, date_range=None):
+ filters = {'patient': name}
+ if document_types:
+ document_types = json.loads(document_types)
+ if len(document_types):
+ filters['reference_doctype'] = ['IN', document_types]
+
+ if date_range:
+ try:
+ date_range = json.loads(date_range)
+ if date_range:
+ filters['creation'] = ['between', [date_range[0], date_range[1]]]
+ except json.decoder.JSONDecodeError:
+ pass
+
+ return filters
+
+
@frappe.whitelist()
def get_feed_for_dt(doctype, docname):
"""get feed"""
@@ -43,6 +58,7 @@
return result
+
@frappe.whitelist()
def get_patient_history_doctypes():
document_types = []
@@ -54,4 +70,4 @@
for entry in settings.custom_doctypes:
document_types.append(entry.document_type)
- return document_types
\ No newline at end of file
+ return document_types