fix: move result value validations to server side

This commit is contained in:
Rucha Mahabal 2020-07-30 14:25:40 +05:30
parent b00f870c77
commit c33703d54c
5 changed files with 46 additions and 43 deletions

View File

@ -179,23 +179,6 @@ var show_lab_tests = function (frm, lab_test_list) {
d.show();
};
cur_frm.cscript.custom_before_submit = function (doc) {
if (doc.normal_test_items) {
for (let result in doc.normal_test_items) {
if (!doc.normal_test_items[result].result_value && !doc.normal_test_items[result].allow_blank && doc.normal_test_items[result].require_result_value) {
frappe.throw(__('Please input all required result values'));
}
}
}
if (doc.descriptive_test_items) {
for (let result in doc.descriptive_test_items) {
if (!doc.descriptive_test_items[result].result_value && !doc.descriptive_test_items[result].allow_blank && doc.descriptive_test_items[result].require_result_value) {
frappe.throw(__('Please input all required result values'));
}
}
}
};
var make_dialog = function (frm, emailed, printed) {
var number = frm.doc.mobile;

View File

@ -84,7 +84,7 @@
"fieldname": "naming_series",
"fieldtype": "Select",
"label": "Series",
"options": "LP-",
"options": "HLC-LAB-.YYYY.-",
"print_hide": 1,
"report_hide": 1,
"reqd": 1
@ -197,11 +197,10 @@
{
"fieldname": "status",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Status",
"options": "Draft\nCompleted\nApproved\nRejected\nCancelled",
"print_hide": 1,
"read_only": 1,
"report_hide": 1,
"search_index": 1
},
{
@ -354,7 +353,8 @@
},
{
"fieldname": "sb_normal",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Compound Test Result"
},
{
"fieldname": "normal_test_items",
@ -369,11 +369,13 @@
{
"depends_on": "descriptive_toggle",
"fieldname": "organisms_section",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Organism Test Result"
},
{
"fieldname": "sb_sensitivity",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Sensitivity Test Result"
},
{
"fieldname": "sensitivity_test_items",
@ -383,8 +385,10 @@
"report_hide": 1
},
{
"collapsible": 1,
"fieldname": "sb_comments",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Comments"
},
{
"fieldname": "lab_test_comment",
@ -531,7 +535,8 @@
},
{
"fieldname": "sb_descriptive",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"label": "Descriptive Test Result"
},
{
"default": "0",
@ -550,7 +555,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2020-07-16 13:35:24.811062",
"modified": "2020-07-30 14:03:00.166003",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Lab Test",

View File

@ -9,20 +9,21 @@ from frappe.model.document import Document
from frappe.utils import getdate, cstr
class LabTest(Document):
def validate(self):
if not self.is_new():
self.set_secondary_uom_result()
def on_submit(self):
self.validate_result_values()
self.db_set('submitted_date', getdate())
self.db_set('status', 'Completed')
insert_lab_test_to_medical_record(self)
def on_cancel(self):
delete_lab_test_from_medical_record(self)
self.db_set('status', 'Cancelled')
delete_lab_test_from_medical_record(self)
self.reload()
def validate(self):
if not self.is_new():
self.set_secondary_uom_result()
def on_update(self):
if self.sensitivity_test_items:
sensitivity = sorted(self.sensitivity_test_items, key=lambda x: x.antibiotic_sensitivity)
@ -51,7 +52,20 @@ class LabTest(Document):
item.secondary_uom_result = float(item.result_value) * float(item.conversion_factor)
except:
item.secondary_uom_result = ''
frappe.msgprint(_('Result for Secondary UOM not calculated for row #{0}'.format(item.idx)), title = _('Warning'))
frappe.msgprint(_('Row #{0}: Result for Secondary UOM not calculated'.format(item.idx)), title = _('Warning'))
def validate_result_values(self):
if self.normal_test_items:
for item in self.normal_test_items:
if not item.result_value and not item.allow_blank and item.require_result_value:
frappe.throw(_('Row #{0}: Please enter the result value for {1}').format(
item.idx, frappe.bold(item.lab_test_name)), title=_('Mandatory Results'))
if self.descriptive_test_items:
for item in self.descriptive_test_items:
if not item.result_value and not item.allow_blank and item.require_result_value:
frappe.throw(_('Row #{0}: Please enter the result value {1}').format(
item.idx, frappe.bold(item.lab_test_name)), title=_('Mandatory Results'))
def create_test_from_template(lab_test):
@ -263,8 +277,7 @@ def load_result_format(lab_test, template, prescription, invoice):
for lab_test_group in template.lab_test_groups:
# Template_in_group = None
if lab_test_group.lab_test_template:
template_in_group = frappe.get_doc('Lab Test Template',
lab_test_group.lab_test_template)
template_in_group = frappe.get_doc('Lab Test Template', lab_test_group.lab_test_template)
if template_in_group:
if template_in_group.lab_test_template_type == 'Single':
create_normals(template_in_group, lab_test)
@ -302,9 +315,10 @@ def load_result_format(lab_test, template, prescription, invoice):
@frappe.whitelist()
def get_employee_by_user_id(user_id):
emp_id = frappe.db.get_value('Employee', { 'user_id': user_id })
employee = frappe.get_doc('Employee', emp_id)
return employee
emp_id = frappe.db.exists('Employee', { 'user_id': user_id })
if emp_id:
return frappe.get_doc('Employee', emp_id)
return None
def insert_lab_test_to_medical_record(doc):
table_row = False
@ -325,7 +339,7 @@ def insert_lab_test_to_medical_record(doc):
table_row += ' ' + frappe.bold(_('Lab Test Result: ')) + item.result_value
if item.normal_range:
table_row += ' ' + _('Normal Range:') + item.normal_range
table_row += ' ' + _('Normal Range: ') + item.normal_range
table_row += ' ' + comment
elif doc.descriptive_test_items:
@ -356,7 +370,7 @@ def insert_lab_test_to_medical_record(doc):
medical_record.save(ignore_permissions = True)
def delete_lab_test_from_medical_record(self):
medical_record_id = frappe.db.sql('select name from `tabPatient Medical Record` where reference_name= %s', (self.name))
medical_record_id = frappe.db.sql('select name from `tabPatient Medical Record` where reference_name=%s', (self.name))
if medical_record_id and medical_record_id[0][0]:
frappe.delete_doc('Patient Medical Record', medical_record_id[0][0])

View File

@ -93,7 +93,8 @@
"depends_on": "secondary_uom",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"label": "Conversion Factor"
"label": "Conversion Factor",
"mandatory_depends_on": "secondary_uom"
},
{
"default": "0",
@ -106,7 +107,7 @@
],
"istable": 1,
"links": [],
"modified": "2020-06-24 10:59:01.921924",
"modified": "2020-07-30 12:36:03.082391",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Lab Test Group Template",

View File

@ -81,11 +81,11 @@ class LabTestTemplate(Document):
if self.lab_test_template_type == 'Compound':
for item in self.normal_test_templates:
if item.secondary_uom and not item.conversion_factor:
frappe.throw(_('Conversion Factor is mandatory'))
frappe.throw(_('Row #{0}: Conversion Factor is mandatory').format(item.idx))
if self.lab_test_template_type == 'Grouped':
for group in self.lab_test_groups:
if group.template_or_new_line == 'Add New Line' and group.secondary_uom and not group.conversion_factor:
frappe.throw(_('Conversion Factor is mandatory'))
frappe.throw(_('Row #{0}: Conversion Factor is mandatory').format(group.idx))
def create_item_from_template(doc):