Hello community!
There may be a need to clarify, both in principle and in code, the nature of the relationship between Patient and Customer objects. Currently, one is able to select the same Customer in multiple Patient objects; this many-to-one relationship decouples the financial entity (Customer) and the medical (Patient), and supports requirements by other users, for example, Health Insurance Claims.
Currently, adding a new Patient creates a new Customer if Healthcare > Healthcare Settings > Link Customer To Patient is enabled. As expected, a new Customer is not created with a new Patient if this settings is disabled. Subsequently, an existing Customer can be manually added to the Patient object. So far so good.
However, data from the new Patient’s on_update
class method currently updates the existing Customer every time any Patient linked to the Customer is saved, which perhaps does not support the many-to-one Patient-Customer relationship.
Code from: erpnext/patient.py at version-13 · frappe/erpnext · GitHub
class Patient(Document):
'''...'''
def on_update(self):
if self.customer:
customer = frappe.get_doc('Customer', self.customer)
if self.customer_group:
customer.customer_group = self.customer_group
if self.territory:
customer.territory = self.territory
customer.customer_name = self.patient_name
customer.default_price_list = self.default_price_list
customer.default_currency = self.default_currency
customer.language = self.language
customer.ignore_mandatory = True
customer.save(ignore_permissions=True)
else:
if frappe.db.get_single_value('Healthcare Settings', 'link_customer_to_patient'):
create_customer(self)
Should this behaviour only apply globally when the setting Healthcare > Healthcare Settings > Link Customer To Patient is enabled?
Other options might include object-level control such as an update_customer_on_save
boolean attribute in every Patient object or an update_customer
Patient class method linked to an ‘Update Customer’ button on the Patient page. Both options could include validation to prevent the update of Customer objects linked to more than one Patient objects.