fix: status inconsistencies in Clinical Procedure
This commit is contained in:
parent
0ed4cabb5d
commit
d244ac9c3a
@ -4,81 +4,86 @@
|
||||
frappe.ui.form.on('Clinical Procedure', {
|
||||
setup: function(frm) {
|
||||
frm.set_query('batch_no', 'items', function(doc, cdt, cdn) {
|
||||
var item = locals[cdt][cdn];
|
||||
if(!item.item_code) {
|
||||
frappe.throw(__("Please enter Item Code to get Batch Number"));
|
||||
let item = locals[cdt][cdn];
|
||||
if (!item.item_code) {
|
||||
frappe.throw(__('Please enter Item Code to get Batch Number'));
|
||||
} else {
|
||||
if (frm.doc.status == 'In Progress') {
|
||||
var filters = {
|
||||
let filters = {
|
||||
'item_code': item.item_code,
|
||||
'posting_date': frm.doc.start_date || frappe.datetime.nowdate()
|
||||
};
|
||||
if(frm.doc.warehouse) filters["warehouse"] = frm.doc.warehouse;
|
||||
if (frm.doc.warehouse) filters['warehouse'] = frm.doc.warehouse;
|
||||
} else {
|
||||
filters = {
|
||||
'item_code': item.item_code
|
||||
};
|
||||
}
|
||||
return {
|
||||
query : "erpnext.controllers.queries.get_batch_no",
|
||||
query : 'erpnext.controllers.queries.get_batch_no',
|
||||
filters: filters
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
refresh: function(frm) {
|
||||
frm.set_query("patient", function () {
|
||||
frm.set_query('patient', function () {
|
||||
return {
|
||||
filters: {"status": ["!=", "Disabled"]}
|
||||
filters: {'status': ['!=', 'Disabled']}
|
||||
};
|
||||
});
|
||||
frm.set_query("appointment", function () {
|
||||
|
||||
frm.set_query('appointment', function () {
|
||||
return {
|
||||
filters: {
|
||||
"procedure_template": ["not in", null],
|
||||
"status": ['in', 'Open, Scheduled']
|
||||
'procedure_template': ['not in', null],
|
||||
'status': ['in', 'Open, Scheduled']
|
||||
}
|
||||
};
|
||||
});
|
||||
frm.set_query("service_unit", function(){
|
||||
|
||||
frm.set_query('service_unit', function() {
|
||||
return {
|
||||
filters: {
|
||||
"is_group": false,
|
||||
"allow_appointments": true
|
||||
'is_group': false,
|
||||
'allow_appointments': true
|
||||
}
|
||||
};
|
||||
});
|
||||
frm.set_query("practitioner", function() {
|
||||
|
||||
frm.set_query('practitioner', function() {
|
||||
return {
|
||||
filters: {
|
||||
'department': frm.doc.medical_department
|
||||
}
|
||||
};
|
||||
});
|
||||
if(frm.doc.consume_stock){
|
||||
|
||||
if (frm.doc.consume_stock) {
|
||||
frm.set_indicator_formatter('item_code',
|
||||
function(doc) { return (doc.qty<=doc.actual_qty) ? "green" : "orange" ; });
|
||||
function(doc) { return (doc.qty<=doc.actual_qty) ? 'green' : 'orange' ; });
|
||||
}
|
||||
|
||||
if (!frm.doc.__islocal && frm.doc.status == 'In Progress'){
|
||||
|
||||
if(frm.doc.consume_stock){
|
||||
var btn_label = 'Complete and Consume';
|
||||
var msg = 'Complete '+frm.doc.name+' and Consume Stock?';
|
||||
}else{
|
||||
if (frm.doc.docstatus == 2 && frm.doc.status == 'In Progress') {
|
||||
let btn_label = '';
|
||||
let msg = '';
|
||||
if (frm.doc.consume_stock) {
|
||||
btn_label = 'Complete and Consume';
|
||||
msg = 'Complete '+ frm.doc.name +' and Consume Stock?';
|
||||
} else {
|
||||
btn_label = 'Complete';
|
||||
msg = 'Complete '+frm.doc.name+'?';
|
||||
msg = 'Complete '+ frm.doc.name +'?';
|
||||
}
|
||||
|
||||
frm.add_custom_button(__(btn_label), function () {
|
||||
frappe.confirm(
|
||||
__(msg),
|
||||
function(){
|
||||
function() {
|
||||
frappe.call({
|
||||
doc: frm.doc,
|
||||
method: "complete",
|
||||
method: 'complete',
|
||||
callback: function(r) {
|
||||
if(!r.exc){
|
||||
if (!r.exc) {
|
||||
cur_frm.reload_doc();
|
||||
}
|
||||
}
|
||||
@ -86,31 +91,31 @@ frappe.ui.form.on('Clinical Procedure', {
|
||||
}
|
||||
);
|
||||
});
|
||||
}else if (frm.doc.status == 'Draft') {
|
||||
frm.add_custom_button(__("Start"), function () {
|
||||
} else if (frm.doc.docstatus == 2 && frm.doc.status == 'Pending') {
|
||||
frm.add_custom_button(__('Start'), function () {
|
||||
frappe.call({
|
||||
doc: frm.doc,
|
||||
method: "start",
|
||||
method: 'start',
|
||||
callback: function(r) {
|
||||
if(!r.exc){
|
||||
if(frm.doc.status == 'Draft'){
|
||||
if (!r.exc) {
|
||||
if (frm.doc.status == 'Draft') {
|
||||
frappe.confirm(
|
||||
__("Stock quantity to start procedure is not available in the warehouse. Do you want to record a Stock Transfer"),
|
||||
function(){
|
||||
__('Stock quantity to start procedure is not available in the warehouse. Do you want to record a Stock Transfer'),
|
||||
function() {
|
||||
frappe.call({
|
||||
doc: frm.doc,
|
||||
method: "make_material_transfer",
|
||||
method: 'make_material_transfer',
|
||||
callback: function(r) {
|
||||
if(!r.exc){
|
||||
if (!r.exc) {
|
||||
cur_frm.reload_doc();
|
||||
var doclist = frappe.model.sync(r.message);
|
||||
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
|
||||
let doclist = frappe.model.sync(r.message);
|
||||
frappe.set_route('Form', doclist[0].doctype, doclist[0].name);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}else{
|
||||
} else {
|
||||
cur_frm.reload_doc();
|
||||
}
|
||||
}
|
||||
@ -118,130 +123,130 @@ frappe.ui.form.on('Clinical Procedure', {
|
||||
});
|
||||
});
|
||||
}
|
||||
if (frm.doc.__islocal){
|
||||
frm.set_df_property("consumables", "hidden", 1);
|
||||
}else{
|
||||
frm.set_df_property("consumables", "hidden", 0);
|
||||
if (frm.doc.__islocal) {
|
||||
frm.set_df_property('consumables', 'hidden', 1);
|
||||
} else {
|
||||
frm.set_df_property('consumables', 'hidden', 0);
|
||||
}
|
||||
},
|
||||
onload: function(frm){
|
||||
if(frm.doc.status == 'Completed'){
|
||||
frm.set_df_property("items", "read_only", 1);
|
||||
onload: function(frm) {
|
||||
if (frm.doc.status == 'Completed') {
|
||||
frm.set_df_property('items', 'read_only', 1);
|
||||
}
|
||||
if(frm.is_new()) {
|
||||
frm.add_fetch("procedure_template", "medical_department", "medical_department");
|
||||
frm.set_value("start_time", null);
|
||||
if (frm.is_new()) {
|
||||
frm.add_fetch('procedure_template', 'medical_department', 'medical_department');
|
||||
frm.set_value('start_time', null);
|
||||
}
|
||||
},
|
||||
patient: function(frm) {
|
||||
if(frm.doc.patient){
|
||||
if (frm.doc.patient) {
|
||||
frappe.call({
|
||||
"method": "erpnext.healthcare.doctype.patient.patient.get_patient_detail",
|
||||
'method': 'erpnext.healthcare.doctype.patient.patient.get_patient_detail',
|
||||
args: {
|
||||
patient: frm.doc.patient
|
||||
},
|
||||
callback: function (data) {
|
||||
let age = "";
|
||||
if(data.message.dob){
|
||||
let age = '';
|
||||
if (data.message.dob) {
|
||||
age = calculate_age(data.message.dob);
|
||||
}else if (data.message.age){
|
||||
}else if (data.message.age) {
|
||||
age = data.message.age;
|
||||
if(data.message.age_as_on){
|
||||
age = age+" as on "+data.message.age_as_on;
|
||||
if (data.message.age_as_on) {
|
||||
age = age+' as on '+data.message.age_as_on;
|
||||
}
|
||||
}
|
||||
frm.set_value("patient_age", age);
|
||||
frm.set_value("patient_sex", data.message.sex);
|
||||
frm.set_value('patient_age', age);
|
||||
frm.set_value('patient_sex', data.message.sex);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
frm.set_value("patient_age", "");
|
||||
frm.set_value("patient_sex", "");
|
||||
} else {
|
||||
frm.set_value('patient_age', '');
|
||||
frm.set_value('patient_sex', '');
|
||||
}
|
||||
},
|
||||
appointment: function(frm) {
|
||||
if(frm.doc.appointment){
|
||||
if (frm.doc.appointment) {
|
||||
frappe.call({
|
||||
"method": "frappe.client.get",
|
||||
'method': 'frappe.client.get',
|
||||
args: {
|
||||
doctype: "Patient Appointment",
|
||||
doctype: 'Patient Appointment',
|
||||
name: frm.doc.appointment
|
||||
},
|
||||
callback: function (data) {
|
||||
frm.set_value("patient", data.message.patient);
|
||||
frm.set_value("procedure_template", data.message.procedure_template);
|
||||
frm.set_value("medical_department", data.message.department);
|
||||
frm.set_value("start_date", data.message.appointment_date);
|
||||
frm.set_value("start_time", data.message.appointment_time);
|
||||
frm.set_value("notes", data.message.notes);
|
||||
frm.set_value("service_unit", data.message.service_unit);
|
||||
callback: function(data) {
|
||||
frm.set_value('patient', data.message.patient);
|
||||
frm.set_value('procedure_template', data.message.procedure_template);
|
||||
frm.set_value('medical_department', data.message.department);
|
||||
frm.set_value('start_date', data.message.appointment_date);
|
||||
frm.set_value('start_time', data.message.appointment_time);
|
||||
frm.set_value('notes', data.message.notes);
|
||||
frm.set_value('service_unit', data.message.service_unit);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
procedure_template: function(frm) {
|
||||
if(frm.doc.procedure_template){
|
||||
if (frm.doc.procedure_template) {
|
||||
frappe.call({
|
||||
"method": "frappe.client.get",
|
||||
'method': 'frappe.client.get',
|
||||
args: {
|
||||
doctype: "Clinical Procedure Template",
|
||||
doctype: 'Clinical Procedure Template',
|
||||
name: frm.doc.procedure_template
|
||||
},
|
||||
callback: function (data) {
|
||||
frm.set_value("medical_department", data.message.medical_department);
|
||||
frm.set_value("consume_stock", data.message.consume_stock);
|
||||
if(!frm.doc.warehouse){
|
||||
frm.set_value('medical_department', data.message.medical_department);
|
||||
frm.set_value('consume_stock', data.message.consume_stock);
|
||||
if (!frm.doc.warehouse) {
|
||||
frappe.call({
|
||||
method: "frappe.client.get_value",
|
||||
method: 'frappe.client.get_value',
|
||||
args: {
|
||||
doctype: "Stock Settings",
|
||||
fieldname: "default_warehouse"
|
||||
doctype: 'Stock Settings',
|
||||
fieldname: 'default_warehouse'
|
||||
},
|
||||
callback: function (data) {
|
||||
frm.set_value("warehouse", data.message.default_warehouse);
|
||||
frm.set_value('warehouse', data.message.default_warehouse);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}else{
|
||||
frm.set_value("consume_stock", 0);
|
||||
} else {
|
||||
frm.set_value('consume_stock', 0);
|
||||
}
|
||||
},
|
||||
service_unit: function(frm) {
|
||||
if(frm.doc.service_unit){
|
||||
if (frm.doc.service_unit) {
|
||||
frappe.call({
|
||||
method: "frappe.client.get_value",
|
||||
method: 'frappe.client.get_value',
|
||||
args:{
|
||||
fieldname: "warehouse",
|
||||
doctype: "Healthcare Service Unit",
|
||||
fieldname: 'warehouse',
|
||||
doctype: 'Healthcare Service Unit',
|
||||
filters:{name: frm.doc.service_unit},
|
||||
},
|
||||
callback: function(data) {
|
||||
if(data.message){
|
||||
frm.set_value("warehouse", data.message.warehouse);
|
||||
if (data.message) {
|
||||
frm.set_value('warehouse', data.message.warehouse);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
practitioner: function(frm) {
|
||||
if(frm.doc.practitioner){
|
||||
if (frm.doc.practitioner) {
|
||||
frappe.call({
|
||||
"method": "frappe.client.get",
|
||||
'method': 'frappe.client.get',
|
||||
args: {
|
||||
doctype: "Healthcare Practitioner",
|
||||
doctype: 'Healthcare Practitioner',
|
||||
name: frm.doc.practitioner
|
||||
},
|
||||
callback: function (data) {
|
||||
frappe.model.set_value(frm.doctype,frm.docname, "medical_department",data.message.department);
|
||||
frappe.model.set_value(frm.doctype,frm.docname, 'medical_department',data.message.department);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.set_query("procedure_template", function(doc) {
|
||||
cur_frm.set_query('procedure_template', function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
'medical_department': doc.medical_department
|
||||
@ -249,31 +254,31 @@ cur_frm.set_query("procedure_template", function(doc) {
|
||||
};
|
||||
});
|
||||
|
||||
cur_frm.set_query("appointment", function() {
|
||||
cur_frm.set_query('appointment', function() {
|
||||
return {
|
||||
filters: {
|
||||
status:['in',["Open"]]
|
||||
status:['in',['Open']]
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Clinical Procedure Item', {
|
||||
qty: function(frm, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
frappe.model.set_value(cdt, cdn, "transfer_qty", d.qty*d.conversion_factor);
|
||||
qty: function(frm, cdt, cdn) {
|
||||
let d = locals[cdt][cdn];
|
||||
frappe.model.set_value(cdt, cdn, 'transfer_qty', d.qty*d.conversion_factor);
|
||||
},
|
||||
uom: function(doc, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.uom && d.item_code){
|
||||
uom: function(doc, cdt, cdn) {
|
||||
let d = locals[cdt][cdn];
|
||||
if (d.uom && d.item_code) {
|
||||
return frappe.call({
|
||||
method: "erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details",
|
||||
method: 'erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details',
|
||||
args: {
|
||||
item_code: d.item_code,
|
||||
uom: d.uom,
|
||||
qty: d.qty
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
if (r.message) {
|
||||
frappe.model.set_value(cdt, cdn, r.message);
|
||||
}
|
||||
}
|
||||
@ -281,25 +286,25 @@ frappe.ui.form.on('Clinical Procedure Item', {
|
||||
}
|
||||
},
|
||||
item_code: function(frm, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
let d = locals[cdt][cdn];
|
||||
let args = null;
|
||||
if(d.item_code) {
|
||||
if (d.item_code) {
|
||||
args = {
|
||||
'doctype' : "Clinical Procedure",
|
||||
'doctype' : 'Clinical Procedure',
|
||||
'item_code' : d.item_code,
|
||||
'company' : frm.doc.company,
|
||||
'warehouse': frm.doc.warehouse
|
||||
};
|
||||
return frappe.call({
|
||||
method: "erpnext.stock.get_item_details.get_item_details",
|
||||
method: 'erpnext.stock.get_item_details.get_item_details',
|
||||
args: {args: args},
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
frappe.model.set_value(cdt, cdn, "item_name", r.message.item_name);
|
||||
frappe.model.set_value(cdt, cdn, "stock_uom", r.message.stock_uom);
|
||||
frappe.model.set_value(cdt, cdn, "conversion_factor", r.message.conversion_factor);
|
||||
frappe.model.set_value(cdt, cdn, "actual_qty", r.message.actual_qty);
|
||||
refresh_field("items");
|
||||
if (r.message) {
|
||||
frappe.model.set_value(cdt, cdn, 'item_name', r.message.item_name);
|
||||
frappe.model.set_value(cdt, cdn, 'stock_uom', r.message.stock_uom);
|
||||
frappe.model.set_value(cdt, cdn, 'conversion_factor', r.message.conversion_factor);
|
||||
frappe.model.set_value(cdt, cdn, 'actual_qty', r.message.actual_qty);
|
||||
refresh_field('items');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -307,16 +312,16 @@ frappe.ui.form.on('Clinical Procedure Item', {
|
||||
}
|
||||
});
|
||||
|
||||
var calculate_age = function(birth) {
|
||||
var ageMS = Date.parse(Date()) - Date.parse(birth);
|
||||
var age = new Date();
|
||||
let calculate_age = function(birth) {
|
||||
let ageMS = Date.parse(Date()) - Date.parse(birth);
|
||||
let age = new Date();
|
||||
age.setTime(ageMS);
|
||||
var years = age.getFullYear() - 1970;
|
||||
return years + " Year(s) " + age.getMonth() + " Month(s) " + age.getDate() + " Day(s)";
|
||||
let years = age.getFullYear() - 1970;
|
||||
return years + ' Year(s) ' + age.getMonth() + ' Month(s) ' + age.getDate() + ' Day(s)';
|
||||
};
|
||||
|
||||
// List Stock items
|
||||
cur_frm.set_query("item_code", "items", function() {
|
||||
cur_frm.set_query('item_code', 'items', function() {
|
||||
return {
|
||||
filters: {
|
||||
is_stock_item:1
|
||||
|
@ -14,6 +14,7 @@ from erpnext.stock.get_item_details import get_item_details
|
||||
|
||||
class ClinicalProcedure(Document):
|
||||
def validate(self):
|
||||
self.set_status()
|
||||
if self.consume_stock and not self.status == 'Draft':
|
||||
if not self.warehouse:
|
||||
frappe.throw(_("Set warehouse for Procedure {0} ").format(self.name))
|
||||
@ -42,6 +43,15 @@ class ClinicalProcedure(Document):
|
||||
frappe.db.set_value("Clinical Procedure", self.name, "sample", sample_collection.name)
|
||||
self.reload()
|
||||
|
||||
def set_status(self):
|
||||
if self.docstatus == 0:
|
||||
self.status = 'Draft'
|
||||
elif self.docstatus == 1:
|
||||
if self.status not in ['In Progress', 'Completed']:
|
||||
self.status = 'Pending'
|
||||
elif self.docstatus == 2:
|
||||
self.status = 'Cancelled'
|
||||
|
||||
def complete(self):
|
||||
if self.consume_stock and self.items:
|
||||
create_stock_entry(self)
|
||||
@ -83,7 +93,7 @@ class ClinicalProcedure(Document):
|
||||
self.status = 'In Progress'
|
||||
insert_clinical_procedure_to_medical_record(self)
|
||||
else:
|
||||
self.status = 'Draft'
|
||||
self.status = 'Pending'
|
||||
self.save()
|
||||
|
||||
def set_actual_qty(self):
|
||||
|
@ -0,0 +1,11 @@
|
||||
frappe.listview_settings['Clinical Procedure'] = {
|
||||
get_indicator: function(doc) {
|
||||
var colors = {
|
||||
'Completed': 'green',
|
||||
'In Progress': 'orange',
|
||||
'Pending': 'orange',
|
||||
'Cancelled': 'grey'
|
||||
};
|
||||
return [__(doc.status), colors[doc.status], 'status,=,' + doc.status];
|
||||
}
|
||||
};
|
@ -47,6 +47,7 @@
|
||||
"fieldtype": "Data",
|
||||
"label": "Item Code",
|
||||
"options": "Item",
|
||||
"read_only_depends_on": "eval: !doc.__islocal ",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@ -175,7 +176,7 @@
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2020-02-28 13:20:23.692613",
|
||||
"modified": "2020-02-28 14:16:13.184981",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Clinical Procedure Template",
|
||||
|
Loading…
x
Reference in New Issue
Block a user