diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 38d8a62f07f..5a5c448026e 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -132,16 +132,10 @@ def allow_regional(fn):
return caller
-def get_last_membership():
+def get_last_membership(member):
'''Returns last membership if exists'''
last_membership = frappe.get_all('Membership', 'name,to_date,membership_type',
- dict(member=frappe.session.user, paid=1), order_by='to_date desc', limit=1)
+ dict(member=member, paid=1), order_by='to_date desc', limit=1)
- return last_membership and last_membership[0]
-
-def is_member():
- '''Returns true if the user is still a member'''
- last_membership = get_last_membership()
- if last_membership and getdate(last_membership.to_date) > getdate():
- return True
- return False
+ if last_membership:
+ return last_membership[0]
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 5435d3b21e6..3a6dbeb51c2 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -1861,23 +1861,6 @@ class TestSalesInvoice(unittest.TestCase):
def test_einvoice_json(self):
from erpnext.regional.india.e_invoice.utils import make_einvoice
- customer_gstin = '27AACCM7806M1Z3'
- customer_gstin_dtls = {
- 'LegalName': '_Test Customer', 'TradeName': '_Test Customer', 'AddrLoc': '_Test City',
- 'StateCode': '27', 'AddrPncd': '410038', 'AddrBno': '_Test Bldg',
- 'AddrBnm': '100', 'AddrFlno': '200', 'AddrSt': '_Test Street'
- }
- company_gstin = '27AAECE4835E1ZR'
- company_gstin_dtls = {
- 'LegalName': '_Test Company', 'TradeName': '_Test Company', 'AddrLoc': '_Test City',
- 'StateCode': '27', 'AddrPncd': '401108', 'AddrBno': '_Test Bldg',
- 'AddrBnm': '100', 'AddrFlno': '200', 'AddrSt': '_Test Street'
- }
- # set cache gstin details to avoid fetching details which will require connection to GSP servers
- frappe.local.gstin_cache = {}
- frappe.local.gstin_cache[customer_gstin] = customer_gstin_dtls
- frappe.local.gstin_cache[company_gstin] = company_gstin_dtls
-
si = make_sales_invoice_for_ewaybill()
si.naming_series = 'INV-2020-.#####'
si.items = []
@@ -1930,12 +1913,12 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEqual(value_details['SgstVal'], total_item_sgst_value)
self.assertEqual(value_details['IgstVal'], total_item_igst_value)
- self.assertEqual(
- value_details['TotInvVal'],
- value_details['AssVal'] + value_details['CgstVal']
- + value_details['SgstVal'] + value_details['IgstVal']
+ calculated_invoice_value = \
+ value_details['AssVal'] + value_details['CgstVal'] \
+ + value_details['SgstVal'] + value_details['IgstVal'] \
+ value_details['OthChrg'] - value_details['Discount']
- )
+
+ self.assertTrue(value_details['TotInvVal'] - calculated_invoice_value < 0.1)
self.assertEqual(value_details['TotInvVal'], si.base_grand_total)
self.assertTrue(einvoice['EwbDtls'])
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index a36e7f8581f..eeb5140bbe2 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -53,8 +53,8 @@ def _execute(filters=None, additional_table_columns=None, additional_query_colum
row = {
'item_code': d.item_code,
- 'item_name': item_record.item_name,
- 'item_group': item_record.item_group,
+ 'item_name': item_record.item_name if item_record else d.item_name,
+ 'item_group': item_record.item_group if item_record else d.item_group,
'description': d.description,
'invoice': d.parent,
'posting_date': d.posting_date,
@@ -316,6 +316,7 @@ def get_items(filters, additional_query_columns):
`tabPurchase Invoice`.posting_date, `tabPurchase Invoice`.credit_to, `tabPurchase Invoice`.company,
`tabPurchase Invoice`.supplier, `tabPurchase Invoice`.remarks, `tabPurchase Invoice`.base_net_total,
`tabPurchase Invoice Item`.`item_code`, `tabPurchase Invoice Item`.description,
+ `tabPurchase Invoice Item`.`item_name`, `tabPurchase Invoice Item`.`item_group`,
`tabPurchase Invoice Item`.`project`, `tabPurchase Invoice Item`.`purchase_order`,
`tabPurchase Invoice Item`.`purchase_receipt`, `tabPurchase Invoice Item`.`po_detail`,
`tabPurchase Invoice Item`.`expense_account`, `tabPurchase Invoice Item`.`stock_qty`,
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index e3aac9aba85..81f0ad3fed1 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -655,6 +655,34 @@ def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql(query, filters)
+@frappe.whitelist()
+@frappe.validate_and_sanitize_search_inputs
+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)
+
+
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def get_tax_template(doctype, txt, searchfield, start, page_len, filters):
diff --git a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json
index 9f996d9e2be..0ee9317c852 100644
--- a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json
+++ b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json
@@ -8,12 +8,12 @@
"is_mandatory": 0,
"is_single": 0,
"is_skipped": 0,
- "modified": "2020-05-14 17:38:27.496696",
+ "modified": "2021-01-21 15:28:52.483839",
"modified_by": "Administrator",
"name": "Create Opportunity",
"owner": "Administrator",
"reference_document": "Opportunity",
- "show_full_form": 0,
+ "show_full_form": 1,
"title": "Create Opportunity",
"validate_action": 1
}
\ No newline at end of file
diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py
index e55a1433a51..c3242284674 100644
--- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py
+++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py
@@ -100,7 +100,6 @@ class ClinicalProcedure(Document):
allow_start = self.set_actual_qty()
if allow_start:
self.db_set('status', 'In Progress')
- insert_clinical_procedure_to_medical_record(self)
return 'success'
return 'insufficient stock'
@@ -247,21 +246,3 @@ def make_procedure(source_name, target_doc=None):
}, target_doc, set_missing_values)
return doc
-
-
-def insert_clinical_procedure_to_medical_record(doc):
- subject = frappe.bold(_("Clinical Procedure conducted: ")) + cstr(doc.procedure_template) + "
"
- if doc.practitioner:
- subject += frappe.bold(_('Healthcare Practitioner: ')) + doc.practitioner
- if subject and doc.notes:
- subject += '
' + doc.notes
-
- medical_record = frappe.new_doc('Patient Medical Record')
- medical_record.patient = doc.patient
- medical_record.subject = subject
- medical_record.status = 'Open'
- medical_record.communication_date = doc.start_date
- medical_record.reference_doctype = 'Clinical Procedure'
- medical_record.reference_name = doc.name
- medical_record.reference_owner = doc.owner
- medical_record.save(ignore_permissions=True)
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
index bba521313df..e7319085e46 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
@@ -264,7 +264,7 @@ def get_filters(entry):
def get_current_healthcare_service_unit(inpatient_record):
ip_record = frappe.get_doc('Inpatient Record', inpatient_record)
- if ip_record.inpatient_occupancies:
+ if ip_record.status in ['Admitted', 'Discharge Scheduled'] and ip_record.inpatient_occupancies:
return ip_record.inpatient_occupancies[-1].service_unit
return
diff --git a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py
index 10990d412d8..8a918b02751 100644
--- a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py
+++ b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py
@@ -142,11 +142,15 @@ def create_inpatient(patient):
return inpatient_record
-def get_healthcare_service_unit():
- service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1})
+def get_healthcare_service_unit(unit_name=None):
+ if not unit_name:
+ service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1})
+ else:
+ service_unit = frappe.db.exists("Healthcare Service Unit", {"healthcare_service_unit_name": unit_name})
+
if not service_unit:
service_unit = frappe.new_doc("Healthcare Service Unit")
- service_unit.healthcare_service_unit_name = "Test Service Unit Ip Occupancy"
+ service_unit.healthcare_service_unit_name = unit_name or "Test Service Unit Ip Occupancy"
service_unit.company = "_Test Company"
service_unit.service_unit_type = get_service_unit_type()
service_unit.inpatient_occupancy = 1
diff --git a/erpnext/healthcare/doctype/lab_test/lab_test.json b/erpnext/healthcare/doctype/lab_test/lab_test.json
index edf1d911aac..ac61fea3ad7 100644
--- a/erpnext/healthcare/doctype/lab_test/lab_test.json
+++ b/erpnext/healthcare/doctype/lab_test/lab_test.json
@@ -359,6 +359,7 @@
{
"fieldname": "normal_test_items",
"fieldtype": "Table",
+ "label": "Normal Test Result",
"options": "Normal Test Result",
"print_hide": 1
},
@@ -380,6 +381,7 @@
{
"fieldname": "sensitivity_test_items",
"fieldtype": "Table",
+ "label": "Sensitivity Test Result",
"options": "Sensitivity Test Result",
"print_hide": 1,
"report_hide": 1
@@ -529,6 +531,7 @@
{
"fieldname": "descriptive_test_items",
"fieldtype": "Table",
+ "label": "Descriptive Test Result",
"options": "Descriptive Test Result",
"print_hide": 1,
"report_hide": 1
@@ -549,13 +552,14 @@
{
"fieldname": "organism_test_items",
"fieldtype": "Table",
+ "label": "Organism Test Result",
"options": "Organism Test Result",
"print_hide": 1
}
],
"is_submittable": 1,
"links": [],
- "modified": "2020-07-30 18:18:38.516215",
+ "modified": "2020-11-30 11:04:17.195848",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Lab Test",
diff --git a/erpnext/healthcare/doctype/lab_test/lab_test.py b/erpnext/healthcare/doctype/lab_test/lab_test.py
index 2db77438653..4b57cd073d0 100644
--- a/erpnext/healthcare/doctype/lab_test/lab_test.py
+++ b/erpnext/healthcare/doctype/lab_test/lab_test.py
@@ -17,11 +17,9 @@ class LabTest(Document):
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):
self.db_set('status', 'Cancelled')
- delete_lab_test_from_medical_record(self)
self.reload()
def on_update(self):
@@ -330,60 +328,6 @@ def get_employee_by_user_id(user_id):
return frappe.get_doc('Employee', emp_id)
return None
-def insert_lab_test_to_medical_record(doc):
- table_row = False
- subject = cstr(doc.lab_test_name)
- if doc.practitioner:
- subject += frappe.bold(_('Healthcare Practitioner: '))+ doc.practitioner + '
'
- if doc.normal_test_items:
- item = doc.normal_test_items[0]
- comment = ''
- if item.lab_test_comment:
- comment = str(item.lab_test_comment)
- table_row = frappe.bold(_('Lab Test Conducted: ')) + item.lab_test_name
-
- if item.lab_test_event:
- table_row += frappe.bold(_('Lab Test Event: ')) + item.lab_test_event
-
- if item.result_value:
- table_row += ' ' + frappe.bold(_('Lab Test Result: ')) + item.result_value
-
- if item.normal_range:
- table_row += ' ' + _('Normal Range: ') + item.normal_range
- table_row += ' ' + comment
-
- elif doc.descriptive_test_items:
- item = doc.descriptive_test_items[0]
-
- if item.lab_test_particulars and item.result_value:
- table_row = item.lab_test_particulars + ' ' + item.result_value
-
- elif doc.sensitivity_test_items:
- item = doc.sensitivity_test_items[0]
-
- if item.antibiotic and item.antibiotic_sensitivity:
- table_row = item.antibiotic + ' ' + item.antibiotic_sensitivity
-
- if table_row:
- subject += '
' + table_row
- if doc.lab_test_comment:
- subject += '
' + cstr(doc.lab_test_comment)
-
- medical_record = frappe.new_doc('Patient Medical Record')
- medical_record.patient = doc.patient
- medical_record.subject = subject
- medical_record.status = 'Open'
- medical_record.communication_date = doc.result_date
- medical_record.reference_doctype = 'Lab Test'
- medical_record.reference_name = doc.name
- medical_record.reference_owner = doc.owner
- 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))
-
- if medical_record_id and medical_record_id[0][0]:
- frappe.delete_doc('Patient Medical Record', medical_record_id[0][0])
@frappe.whitelist()
def get_lab_test_prescribed(patient):
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
index 79e1775b9db..3d5073b13e7 100644
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js
@@ -31,12 +31,12 @@ frappe.ui.form.on('Patient Appointment', {
};
});
- frm.set_query('service_unit', function(){
+ frm.set_query('service_unit', function() {
return {
+ query: 'erpnext.controllers.queries.get_healthcare_service_units',
filters: {
- 'is_group': false,
- 'allow_appointments': true,
- 'company': frm.doc.company
+ company: frm.doc.company,
+ inpatient_record: frm.doc.inpatient_record
}
};
});
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
index dc820cb464e..b05c673d84c 100755
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
@@ -18,6 +18,7 @@ from erpnext.healthcare.utils import check_fee_validity, get_service_item_and_pr
class PatientAppointment(Document):
def validate(self):
self.validate_overlaps()
+ self.validate_service_unit()
self.set_appointment_datetime()
self.validate_customer_created()
self.set_status()
@@ -68,6 +69,19 @@ class PatientAppointment(Document):
overlaps[0][1], overlaps[0][2], overlaps[0][3], overlaps[0][4])
frappe.throw(overlapping_details, title=_('Appointments Overlapping'))
+ 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)) + '
'
+ 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 set_appointment_datetime(self):
self.appointment_datetime = "%s %s" % (self.appointment_date, self.appointment_time or "00:00:00")
diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py
index b681ed1a226..f7ec6f58fc5 100644
--- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py
+++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
import unittest
import frappe
from erpnext.healthcare.doctype.patient_appointment.patient_appointment import update_status, make_encounter
-from frappe.utils import nowdate, add_days
+from frappe.utils import nowdate, add_days, now_datetime
from frappe.utils.make_random import get_random
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
@@ -78,6 +78,59 @@ class TestPatientAppointment(unittest.TestCase):
sales_invoice_name = frappe.db.get_value('Sales Invoice Item', {'reference_dn': appointment.name}, 'parent')
self.assertEqual(frappe.db.get_value('Sales Invoice', sales_invoice_name, 'status'), 'Cancelled')
+ def test_appointment_booking_for_admission_service_unit(self):
+ from erpnext.healthcare.doctype.inpatient_record.inpatient_record import admit_patient, discharge_patient, schedule_discharge
+ from erpnext.healthcare.doctype.inpatient_record.test_inpatient_record import \
+ create_inpatient, get_healthcare_service_unit, mark_invoiced_inpatient_occupancy
+
+ frappe.db.sql("""delete from `tabInpatient Record`""")
+ patient, medical_department, practitioner = create_healthcare_docs()
+ patient = create_patient()
+ # Schedule Admission
+ ip_record = create_inpatient(patient)
+ ip_record.expected_length_of_stay = 0
+ ip_record.save(ignore_permissions = True)
+
+ # Admit
+ service_unit = get_healthcare_service_unit('Test Service Unit Ip Occupancy')
+ admit_patient(ip_record, service_unit, now_datetime())
+
+ appointment = create_appointment(patient, practitioner, nowdate(), service_unit=service_unit)
+ self.assertEqual(appointment.service_unit, service_unit)
+
+ # Discharge
+ schedule_discharge(frappe.as_json({'patient': patient}))
+ ip_record1 = frappe.get_doc("Inpatient Record", ip_record.name)
+ mark_invoiced_inpatient_occupancy(ip_record1)
+ discharge_patient(ip_record1)
+
+ def test_invalid_healthcare_service_unit_validation(self):
+ from erpnext.healthcare.doctype.inpatient_record.inpatient_record import admit_patient, discharge_patient, schedule_discharge
+ from erpnext.healthcare.doctype.inpatient_record.test_inpatient_record import \
+ create_inpatient, get_healthcare_service_unit, mark_invoiced_inpatient_occupancy
+
+ frappe.db.sql("""delete from `tabInpatient Record`""")
+ patient, medical_department, practitioner = create_healthcare_docs()
+ patient = create_patient()
+ # Schedule Admission
+ ip_record = create_inpatient(patient)
+ ip_record.expected_length_of_stay = 0
+ ip_record.save(ignore_permissions = True)
+
+ # Admit
+ service_unit = get_healthcare_service_unit('Test Service Unit Ip Occupancy')
+ admit_patient(ip_record, service_unit, now_datetime())
+
+ appointment_service_unit = get_healthcare_service_unit('Test Service Unit Ip Occupancy for Appointment')
+ appointment = create_appointment(patient, practitioner, nowdate(), service_unit=appointment_service_unit, save=0)
+ self.assertRaises(frappe.exceptions.ValidationError, appointment.save)
+
+ # Discharge
+ schedule_discharge(frappe.as_json({'patient': patient}))
+ ip_record1 = frappe.get_doc("Inpatient Record", ip_record.name)
+ mark_invoiced_inpatient_occupancy(ip_record1)
+ discharge_patient(ip_record1)
+
def create_healthcare_docs():
patient = create_patient()
@@ -125,7 +178,7 @@ def create_encounter(appointment):
encounter.submit()
return encounter
-def create_appointment(patient, practitioner, appointment_date, invoice=0, procedure_template=0):
+def create_appointment(patient, practitioner, appointment_date, invoice=0, procedure_template=0, service_unit=None, save=1):
item = create_healthcare_service_items()
frappe.db.set_value('Healthcare Settings', None, 'inpatient_visit_charge_item', item)
frappe.db.set_value('Healthcare Settings', None, 'op_consulting_charge_item', item)
@@ -136,12 +189,15 @@ def create_appointment(patient, practitioner, appointment_date, invoice=0, proce
appointment.appointment_date = appointment_date
appointment.company = '_Test Company'
appointment.duration = 15
+ if service_unit:
+ appointment.service_unit = service_unit
if invoice:
appointment.mode_of_payment = 'Cash'
appointment.paid_amount = 500
if procedure_template:
appointment.procedure_template = create_clinical_procedure_template().get('name')
- appointment.save(ignore_permissions=True)
+ if save:
+ appointment.save(ignore_permissions=True)
return appointment
def create_healthcare_service_items():
@@ -152,6 +208,7 @@ def create_healthcare_service_items():
item.item_name = 'Consulting Charges'
item.item_group = 'Services'
item.is_stock_item = 0
+ item.stock_uom = 'Nos'
item.save()
return item.name
diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json
index 15675f4673f..b646ff9ebe6 100644
--- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json
+++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.json
@@ -210,7 +210,7 @@
{
"fieldname": "drug_prescription",
"fieldtype": "Table",
- "label": "Items",
+ "label": "Drug Prescription",
"options": "Drug Prescription"
},
{
@@ -328,7 +328,7 @@
],
"is_submittable": 1,
"links": [],
- "modified": "2020-05-16 21:00:08.644531",
+ "modified": "2020-11-30 10:39:00.783119",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Patient Encounter",
diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py
index 87f42491fce..cc2141790f7 100644
--- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py
+++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py
@@ -17,10 +17,6 @@ class PatientEncounter(Document):
def on_update(self):
if self.appointment:
frappe.db.set_value('Patient Appointment', self.appointment, 'status', 'Closed')
- update_encounter_medical_record(self)
-
- def after_insert(self):
- insert_encounter_to_medical_record(self)
def on_submit(self):
if self.therapies:
@@ -33,8 +29,6 @@ class PatientEncounter(Document):
if self.inpatient_record and self.drug_prescription:
delete_ip_medication_order(self)
- delete_medical_record(self)
-
def set_title(self):
self.title = _('{0} with {1}').format(self.patient_name or self.patient,
self.practitioner_name or self.practitioner)[:100]
@@ -102,61 +96,7 @@ def create_therapy_plan(encounter):
frappe.msgprint(_('Therapy Plan {0} created successfully.').format(frappe.bold(doc.name)), alert=True)
-def insert_encounter_to_medical_record(doc):
- subject = set_subject_field(doc)
- medical_record = frappe.new_doc('Patient Medical Record')
- medical_record.patient = doc.patient
- medical_record.subject = subject
- medical_record.status = 'Open'
- medical_record.communication_date = doc.encounter_date
- medical_record.reference_doctype = 'Patient Encounter'
- medical_record.reference_name = doc.name
- medical_record.reference_owner = doc.owner
- medical_record.save(ignore_permissions=True)
-
-
-def update_encounter_medical_record(encounter):
- medical_record_id = frappe.db.exists('Patient Medical Record', {'reference_name': encounter.name})
-
- if medical_record_id and medical_record_id[0][0]:
- subject = set_subject_field(encounter)
- frappe.db.set_value('Patient Medical Record', medical_record_id[0][0], 'subject', subject)
- else:
- insert_encounter_to_medical_record(encounter)
-
-
-def delete_medical_record(encounter):
- record = frappe.db.exists('Patient Medical Record', {'reference_name', encounter.name})
- if record:
- frappe.delete_doc('Patient Medical Record', record, force=1)
-
def delete_ip_medication_order(encounter):
record = frappe.db.exists('Inpatient Medication Order', {'patient_encounter': encounter.name})
if record:
- frappe.delete_doc('Inpatient Medication Order', record, force=1)
-
-
-def set_subject_field(encounter):
- subject = frappe.bold(_('Healthcare Practitioner: ')) + encounter.practitioner + '
'
- if encounter.symptoms:
- subject += frappe.bold(_('Symptoms: ')) + '
'
- for entry in encounter.symptoms:
- subject += cstr(entry.complaint) + '
'
- else:
- subject += frappe.bold(_('No Symptoms')) + '
'
-
- if encounter.diagnosis:
- subject += frappe.bold(_('Diagnosis: ')) + '
'
- for entry in encounter.diagnosis:
- subject += cstr(entry.diagnosis) + '
'
- else:
- subject += frappe.bold(_('No Diagnosis')) + '
'
-
- if encounter.drug_prescription:
- subject += '
' + _('Drug(s) Prescribed.')
- if encounter.lab_test_prescription:
- subject += '
' + _('Test(s) Prescribed.')
- if encounter.procedure_prescription:
- subject += '
' + _('Procedure(s) Prescribed.')
-
- return subject
+ frappe.delete_doc('Inpatient Medication Order', record, force=1)
\ No newline at end of file
diff --git a/erpnext/healthcare/doctype/patient_history_custom_document_type/__init__.py b/erpnext/healthcare/doctype/patient_history_custom_document_type/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/erpnext/healthcare/doctype/patient_history_custom_document_type/patient_history_custom_document_type.json b/erpnext/healthcare/doctype/patient_history_custom_document_type/patient_history_custom_document_type.json
new file mode 100644
index 00000000000..3025c7b06d7
--- /dev/null
+++ b/erpnext/healthcare/doctype/patient_history_custom_document_type/patient_history_custom_document_type.json
@@ -0,0 +1,55 @@
+{
+ "actions": [],
+ "creation": "2020-11-25 13:40:23.054469",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+ "document_type",
+ "date_fieldname",
+ "add_edit_fields",
+ "selected_fields"
+ ],
+ "fields": [
+ {
+ "fieldname": "document_type",
+ "fieldtype": "Link",
+ "in_list_view": 1,
+ "label": "Document Type",
+ "options": "DocType",
+ "reqd": 1
+ },
+ {
+ "fieldname": "selected_fields",
+ "fieldtype": "Code",
+ "label": "Selected Fields",
+ "read_only": 1
+ },
+ {
+ "fieldname": "add_edit_fields",
+ "fieldtype": "Button",
+ "in_list_view": 1,
+ "label": "Add / Edit Fields"
+ },
+ {
+ "fieldname": "date_fieldname",
+ "fieldtype": "Data",
+ "in_list_view": 1,
+ "label": "Date Fieldname",
+ "reqd": 1
+ }
+ ],
+ "index_web_pages_for_search": 1,
+ "istable": 1,
+ "links": [],
+ "modified": "2020-11-30 13:54:37.474671",
+ "modified_by": "Administrator",
+ "module": "Healthcare",
+ "name": "Patient History Custom Document Type",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/healthcare/doctype/patient_history_custom_document_type/patient_history_custom_document_type.py b/erpnext/healthcare/doctype/patient_history_custom_document_type/patient_history_custom_document_type.py
new file mode 100644
index 00000000000..f0a1f929f45
--- /dev/null
+++ b/erpnext/healthcare/doctype/patient_history_custom_document_type/patient_history_custom_document_type.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+# import frappe
+from frappe.model.document import Document
+
+class PatientHistoryCustomDocumentType(Document):
+ pass
diff --git a/erpnext/healthcare/doctype/patient_history_settings/__init__.py b/erpnext/healthcare/doctype/patient_history_settings/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
new file mode 100644
index 00000000000..453da6a12bf
--- /dev/null
+++ b/erpnext/healthcare/doctype/patient_history_settings/patient_history_settings.js
@@ -0,0 +1,133 @@
+// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Patient History Settings', {
+ refresh: function(frm) {
+ frm.set_query('document_type', 'custom_doctypes', () => {
+ return {
+ filters: {
+ custom: 1,
+ is_submittable: 1,
+ module: 'Healthcare',
+ }
+ };
+ });
+ },
+
+ field_selector: function(frm, doc, standard=1) {
+ let document_fields = [];
+ if (doc.selected_fields)
+ document_fields = (JSON.parse(doc.selected_fields)).map(f => f.fieldname);
+
+ frm.call({
+ method: 'get_doctype_fields',
+ doc: frm.doc,
+ args: {
+ document_type: doc.document_type,
+ fields: document_fields
+ },
+ freeze: true,
+ callback: function(r) {
+ if (r.message) {
+ let doctype = 'Patient History Custom Document Type';
+ if (standard)
+ doctype = 'Patient History Standard Document Type';
+
+ frm.events.show_field_selector_dialog(frm, doc, doctype, r.message);
+ }
+ }
+ });
+ },
+
+ show_field_selector_dialog: function(frm, doc, doctype, doc_fields) {
+ let d = new frappe.ui.Dialog({
+ title: __('{0} Fields', [__(doc.document_type)]),
+ fields: [
+ {
+ label: __('Select Fields'),
+ fieldtype: 'MultiCheck',
+ fieldname: 'fields',
+ options: doc_fields,
+ columns: 2
+ }
+ ]
+ });
+
+ d.$body.prepend(`
+
{%= __("Select Patient") %}