def get_healthcare_service_units(doctype, txt, searchfield, start, page_len, filters): query = """ select name from `tabHealthcare Service Unit` where is_group = 0 and company = {company} and name like {txt}""".format(company=frappe.db.escape( filters.get('company')), txt=frappe.db.escape('%{0}%'.format(txt))) if filters and filters.get('inpatient_record'): from erpnext.healthcare.doctype.inpatient_medication_entry.inpatient_medication_entry import ( get_current_healthcare_service_unit, ) service_unit = get_current_healthcare_service_unit( filters.get('inpatient_record')) # if the patient is admitted, then appointments should be allowed against the admission service unit, # inspite of it being an Inpatient Occupancy service unit if service_unit: query += " and (allow_appointments = 1 or name = {service_unit})".format( service_unit=frappe.db.escape(service_unit)) else: query += " and allow_appointments = 1" else: query += " and allow_appointments = 1" return frappe.db.sql(query, filters)
def validate_service_unit(self): if self.inpatient_record and self.service_unit: from erpnext.healthcare.doctype.inpatient_medication_entry.inpatient_medication_entry import get_current_healthcare_service_unit is_inpatient_occupancy_unit = frappe.db.get_value('Healthcare Service Unit', self.service_unit, 'inpatient_occupancy') service_unit = get_current_healthcare_service_unit(self.inpatient_record) if is_inpatient_occupancy_unit and service_unit != self.service_unit: msg = _('Patient {0} is not admitted in the service unit {1}').format(frappe.bold(self.patient), frappe.bold(self.service_unit)) + '<br>' msg += _('Appointment for service units with Inpatient Occupancy can only be created against the unit where patient has been admitted.') frappe.throw(msg, title=_('Invalid Healthcare Service Unit'))
def get_inpatient_details(data, service_unit): service_unit_filtered_data = [] for entry in data: entry["healthcare_service_unit"] = get_current_healthcare_service_unit(entry.inpatient_record) if entry.is_completed: entry["inpatient_medication_entry"] = get_inpatient_medication_entry(entry.name) if service_unit and entry.healthcare_service_unit and service_unit != entry.healthcare_service_unit: service_unit_filtered_data.append(entry) entry.pop("name", None) for entry in service_unit_filtered_data: data.remove(entry) return data
def validate_service_unit(self): if self.inpatient_record and self.service_unit: from erpnext.healthcare.doctype.inpatient_medication_entry.inpatient_medication_entry import ( get_current_healthcare_service_unit, ) is_inpatient_occupancy_unit = frappe.db.get_value( "Healthcare Service Unit", self.service_unit, "inpatient_occupancy") service_unit = get_current_healthcare_service_unit( self.inpatient_record) if is_inpatient_occupancy_unit and service_unit != self.service_unit: msg = (_("Patient {0} is not admitted in the service unit {1}" ).format(frappe.bold(self.patient), frappe.bold(self.service_unit)) + "<br>") msg += _( "Appointment for service units with Inpatient Occupancy can only be created against the unit where patient has been admitted." ) frappe.throw(msg, title=_("Invalid Healthcare Service Unit"))