Skip to content

Commit

Permalink
refactor!: Removed healthcare module from ERPNext (#27362)
Browse files Browse the repository at this point in the history
* chore: Removed healthcare module

* chore: Removed healthcare demo, patch files

* chore: Rename imports from erpnext to healthcare

* chore: Added healthcare deprecation warning patch

* chore: Removed healthcare module code in other modules

* chore: Code clean up

* refactor: Remove sales invoice custom js related to healthcare

* fix: sider

Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com>
  • Loading branch information
ruchamahabal committed Oct 4, 2021
2 parents b483f17 + 01bea14 commit 5905cf9
Show file tree
Hide file tree
Showing 468 changed files with 37 additions and 31,241 deletions.
11 changes: 9 additions & 2 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import unittest

import frappe
from frappe import MandatoryError

from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.healthcare.doctype.lab_test_template.lab_test_template import make_item_price
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.get_item_details import get_item_details
Expand Down Expand Up @@ -623,3 +621,12 @@ def delete_existing_pricing_rules():
"Pricing Rule Item Group", "Pricing Rule Brand"]:

frappe.db.sql("delete from `tab{0}`".format(doctype))


def make_item_price(item, price_list_name, item_price):
frappe.get_doc({
'doctype': 'Item Price',
'price_list': price_list_name,
'item_code': item,
'price_list_rate': item_price
}).insert(ignore_permissions=True, ignore_mandatory=True)
273 changes: 0 additions & 273 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,276 +1033,3 @@ var select_loyalty_program = function(frm, loyalty_programs) {

dialog.show();
}

// Healthcare
var get_healthcare_services_to_invoice = function(frm) {
var me = this;
let selected_patient = '';
var dialog = new frappe.ui.Dialog({
title: __("Get Items from Healthcare Services"),
fields:[
{
fieldtype: 'Link',
options: 'Patient',
label: 'Patient',
fieldname: "patient",
reqd: true
},
{ fieldtype: 'Section Break' },
{ fieldtype: 'HTML', fieldname: 'results_area' }
]
});
var $wrapper;
var $results;
var $placeholder;
dialog.set_values({
'patient': frm.doc.patient
});
dialog.fields_dict["patient"].df.onchange = () => {
var patient = dialog.fields_dict.patient.input.value;
if(patient && patient!=selected_patient){
selected_patient = patient;
var method = "erpnext.healthcare.utils.get_healthcare_services_to_invoice";
var args = {patient: patient, company: frm.doc.company};
var columns = (["service", "reference_name", "reference_type"]);
get_healthcare_items(frm, true, $results, $placeholder, method, args, columns);
}
else if(!patient){
selected_patient = '';
$results.empty();
$results.append($placeholder);
}
}
$wrapper = dialog.fields_dict.results_area.$wrapper.append(`<div class="results"
style="border: 1px solid #d1d8dd; border-radius: 3px; height: 300px; overflow: auto;"></div>`);
$results = $wrapper.find('.results');
$placeholder = $(`<div class="multiselect-empty-state">
<span class="text-center" style="margin-top: -40px;">
<i class="fa fa-2x fa-heartbeat text-extra-muted"></i>
<p class="text-extra-muted">No billable Healthcare Services found</p>
</span>
</div>`);
$results.on('click', '.list-item--head :checkbox', (e) => {
$results.find('.list-item-container .list-row-check')
.prop("checked", ($(e.target).is(':checked')));
});
set_primary_action(frm, dialog, $results, true);
dialog.show();
};

var get_healthcare_items = function(frm, invoice_healthcare_services, $results, $placeholder, method, args, columns) {
var me = this;
$results.empty();
frappe.call({
method: method,
args: args,
callback: function(data) {
if(data.message){
$results.append(make_list_row(columns, invoice_healthcare_services));
for(let i=0; i<data.message.length; i++){
$results.append(make_list_row(columns, invoice_healthcare_services, data.message[i]));
}
}else {
$results.append($placeholder);
}
}
});
}

var make_list_row= function(columns, invoice_healthcare_services, result={}) {
var me = this;
// Make a head row by default (if result not passed)
let head = Object.keys(result).length === 0;
let contents = ``;
columns.forEach(function(column) {
contents += `<div class="list-item__content ellipsis">
${
head ? `<span class="ellipsis">${__(frappe.model.unscrub(column))}</span>`
:(column !== "name" ? `<span class="ellipsis">${__(result[column])}</span>`
: `<a class="list-id ellipsis">
${__(result[column])}</a>`)
}
</div>`;
})

let $row = $(`<div class="list-item">
<div class="list-item__content" style="flex: 0 0 10px;">
<input type="checkbox" class="list-row-check" ${result.checked ? 'checked' : ''}>
</div>
${contents}
</div>`);

$row = list_row_data_items(head, $row, result, invoice_healthcare_services);
return $row;
};

var set_primary_action= function(frm, dialog, $results, invoice_healthcare_services) {
var me = this;
dialog.set_primary_action(__('Add'), function() {
let checked_values = get_checked_values($results);
if(checked_values.length > 0){
if(invoice_healthcare_services) {
frm.set_value("patient", dialog.fields_dict.patient.input.value);
}
frm.set_value("items", []);
add_to_item_line(frm, checked_values, invoice_healthcare_services);
dialog.hide();
}
else{
if(invoice_healthcare_services){
frappe.msgprint(__("Please select Healthcare Service"));
}
else{
frappe.msgprint(__("Please select Drug"));
}
}
});
};

var get_checked_values= function($results) {
return $results.find('.list-item-container').map(function() {
let checked_values = {};
if ($(this).find('.list-row-check:checkbox:checked').length > 0 ) {
checked_values['dn'] = $(this).attr('data-dn');
checked_values['dt'] = $(this).attr('data-dt');
checked_values['item'] = $(this).attr('data-item');
if($(this).attr('data-rate') != 'undefined'){
checked_values['rate'] = $(this).attr('data-rate');
}
else{
checked_values['rate'] = false;
}
if($(this).attr('data-income-account') != 'undefined'){
checked_values['income_account'] = $(this).attr('data-income-account');
}
else{
checked_values['income_account'] = false;
}
if($(this).attr('data-qty') != 'undefined'){
checked_values['qty'] = $(this).attr('data-qty');
}
else{
checked_values['qty'] = false;
}
if($(this).attr('data-description') != 'undefined'){
checked_values['description'] = $(this).attr('data-description');
}
else{
checked_values['description'] = false;
}
return checked_values;
}
}).get();
};

var get_drugs_to_invoice = function(frm) {
var me = this;
let selected_encounter = '';
var dialog = new frappe.ui.Dialog({
title: __("Get Items from Prescriptions"),
fields:[
{ fieldtype: 'Link', options: 'Patient', label: 'Patient', fieldname: "patient", reqd: true },
{ fieldtype: 'Link', options: 'Patient Encounter', label: 'Patient Encounter', fieldname: "encounter", reqd: true,
description:'Quantity will be calculated only for items which has "Nos" as UoM. You may change as required for each invoice item.',
get_query: function(doc) {
return {
filters: {
patient: dialog.get_value("patient"),
company: frm.doc.company,
docstatus: 1
}
};
}
},
{ fieldtype: 'Section Break' },
{ fieldtype: 'HTML', fieldname: 'results_area' }
]
});
var $wrapper;
var $results;
var $placeholder;
dialog.set_values({
'patient': frm.doc.patient,
'encounter': ""
});
dialog.fields_dict["encounter"].df.onchange = () => {
var encounter = dialog.fields_dict.encounter.input.value;
if(encounter && encounter!=selected_encounter){
selected_encounter = encounter;
var method = "erpnext.healthcare.utils.get_drugs_to_invoice";
var args = {encounter: encounter};
var columns = (["drug_code", "quantity", "description"]);
get_healthcare_items(frm, false, $results, $placeholder, method, args, columns);
}
else if(!encounter){
selected_encounter = '';
$results.empty();
$results.append($placeholder);
}
}
$wrapper = dialog.fields_dict.results_area.$wrapper.append(`<div class="results"
style="border: 1px solid #d1d8dd; border-radius: 3px; height: 300px; overflow: auto;"></div>`);
$results = $wrapper.find('.results');
$placeholder = $(`<div class="multiselect-empty-state">
<span class="text-center" style="margin-top: -40px;">
<i class="fa fa-2x fa-heartbeat text-extra-muted"></i>
<p class="text-extra-muted">No Drug Prescription found</p>
</span>
</div>`);
$results.on('click', '.list-item--head :checkbox', (e) => {
$results.find('.list-item-container .list-row-check')
.prop("checked", ($(e.target).is(':checked')));
});
set_primary_action(frm, dialog, $results, false);
dialog.show();
};

var list_row_data_items = function(head, $row, result, invoice_healthcare_services) {
if(invoice_healthcare_services){
head ? $row.addClass('list-item--head')
: $row = $(`<div class="list-item-container"
data-dn= "${result.reference_name}" data-dt= "${result.reference_type}" data-item= "${result.service}"
data-rate = ${result.rate}
data-income-account = "${result.income_account}"
data-qty = ${result.qty}
data-description = "${result.description}">
</div>`).append($row);
}
else{
head ? $row.addClass('list-item--head')
: $row = $(`<div class="list-item-container"
data-item= "${result.drug_code}"
data-qty = ${result.quantity}
data-description = "${result.description}">
</div>`).append($row);
}
return $row
};

var add_to_item_line = function(frm, checked_values, invoice_healthcare_services){
if(invoice_healthcare_services){
frappe.call({
doc: frm.doc,
method: "set_healthcare_services",
args:{
checked_values: checked_values
},
callback: function() {
frm.trigger("validate");
frm.refresh_fields();
}
});
}
else{
for(let i=0; i<checked_values.length; i++){
var si_item = frappe.model.add_child(frm.doc, 'Sales Invoice Item', 'items');
frappe.model.set_value(si_item.doctype, si_item.name, 'item_code', checked_values[i]['item']);
frappe.model.set_value(si_item.doctype, si_item.name, 'qty', 1);
if(checked_values[i]['qty'] > 1){
frappe.model.set_value(si_item.doctype, si_item.name, 'qty', parseFloat(checked_values[i]['qty']));
}
}
frm.refresh_fields();
}
};
53 changes: 0 additions & 53 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
post_depreciation_entries,
)
from erpnext.controllers.selling_controller import SellingController
from erpnext.healthcare.utils import manage_invoice_submit_cancel
from erpnext.projects.doctype.timesheet.timesheet import get_projectwise_timesheet_data
from erpnext.setup.doctype.company.company import update_company_current_month_sales
from erpnext.stock.doctype.batch.batch import set_batch_nos
Expand Down Expand Up @@ -263,13 +262,6 @@ def on_submit(self):
if self.redeem_loyalty_points and not self.is_consolidated and self.loyalty_points:
self.apply_loyalty_points()

# Healthcare Service Invoice.
domain_settings = frappe.get_doc('Domain Settings')
active_domains = [d.domain for d in domain_settings.active_domains]

if "Healthcare" in active_domains:
manage_invoice_submit_cancel(self, "on_submit")

self.process_common_party_accounting()

def validate_pos_return(self):
Expand Down Expand Up @@ -352,12 +344,6 @@ def on_cancel(self):

unlink_inter_company_doc(self.doctype, self.name, self.inter_company_invoice_reference)

# Healthcare Service Invoice.
domain_settings = frappe.get_doc('Domain Settings')
active_domains = [d.domain for d in domain_settings.active_domains]

if "Healthcare" in active_domains:
manage_invoice_submit_cancel(self, "on_cancel")
self.unlink_sales_invoice_from_timesheets()
self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry', 'Repost Item Valuation')

Expand Down Expand Up @@ -1430,45 +1416,6 @@ def apply_loyalty_points(self):
if points_to_redeem < 1: # since points_to_redeem is integer
break

# Healthcare
@frappe.whitelist()
def set_healthcare_services(self, checked_values):
self.set("items", [])
from erpnext.stock.get_item_details import get_item_details
for checked_item in checked_values:
item_line = self.append("items", {})
price_list, price_list_currency = frappe.db.get_values("Price List", {"selling": 1}, ['name', 'currency'])[0]
args = {
'doctype': "Sales Invoice",
'item_code': checked_item['item'],
'company': self.company,
'customer': frappe.db.get_value("Patient", self.patient, "customer"),
'selling_price_list': price_list,
'price_list_currency': price_list_currency,
'plc_conversion_rate': 1.0,
'conversion_rate': 1.0
}
item_details = get_item_details(args)
item_line.item_code = checked_item['item']
item_line.qty = 1
if checked_item['qty']:
item_line.qty = checked_item['qty']
if checked_item['rate']:
item_line.rate = checked_item['rate']
else:
item_line.rate = item_details.price_list_rate
item_line.amount = float(item_line.rate) * float(item_line.qty)
if checked_item['income_account']:
item_line.income_account = checked_item['income_account']
if checked_item['dt']:
item_line.reference_dt = checked_item['dt']
if checked_item['dn']:
item_line.reference_dn = checked_item['dn']
if checked_item['description']:
item_line.description = checked_item['description']

self.set_missing_values(for_validate = True)

def set_status(self, update=False, status=None, update_modified=True):
if self.is_new():
if self.get('amended_from'):
Expand Down
Loading

0 comments on commit 5905cf9

Please sign in to comment.