Skip to content

Commit fb4ed93

Browse files
authored
Merge pull request #972 from aakvatech/mergify/bp/version-14-hotfix/pr-971
chore: include follow up consultation for NHIF patients of the following schemes 1001, 4001, 5001, 6001, 8001 (backport #971)
2 parents 225badf + b7c871a commit fb4ed93

5 files changed

Lines changed: 213 additions & 121 deletions

File tree

hms_tz/nhif/api/patient_appointment.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,6 @@ frappe.ui.form.on('Patient Appointment', {
107107
frm.toggle_display(['referral_no'], false);
108108
frm.toggle_display(['remarks'], false);
109109

110-
const insurance_company = frm.doc.insurance_company;
111-
const coverage_plan_name = frm.doc.coverage_plan_name;
112-
const appointment_type = frm.doc.appointment_type;
113-
if (
114-
insurance_company && coverage_plan_name &&
115-
insurance_company.includes("NHIF") &&
116-
!appointment_type.includes("Follow") &&
117-
(coverage_plan_name.includes("Option") || coverage_plan_name.includes("NMB"))
118-
) {
119-
frm.toggle_display("apply_fasttrack_charge", true);
120-
frm.toggle_enable("apply_fasttrack_charge", true);
121-
frm.set_value("apply_fasttrack_charge", 1);
122-
} else {
123-
frm.toggle_display('apply_fasttrack_charge', false);
124-
frm.toggle_enable('apply_fasttrack_charge', false);
125-
frm.set_value("apply_fasttrack_charge", 0);
126-
}
127-
128110
if (frm.doc.appointment_type == "NHIF External Referral") {
129111
if (frm.doc.insurance_subscription) {
130112
frm.toggle_display(['referral_no'], true);
@@ -231,9 +213,9 @@ frappe.ui.form.on('Patient Appointment', {
231213
args: {
232214
'appointment_type': frm.doc.appointment_type,
233215
'practitioner': frm.doc.practitioner,
234-
"insurance_company": frm.doc.insurance_company,
235216
"inpatient_record": frm.doc.inpatient_record,
236-
"apply_fasttrack_charge": frm.doc.apply_fasttrack_charge,
217+
"insurance_company": frm.doc.insurance_company,
218+
"insurance_subscription": frm.doc.insurance_subscription,
237219
},
238220
callback: function (data) {
239221
if (data.message) {

hms_tz/nhif/api/patient_appointment.py

Lines changed: 97 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from hms_tz.nhif.doctype.nhif_scheme.nhif_scheme import add_scheme
2020
from hms_tz.nhif.doctype.nhif_response_log.nhif_response_log import add_log
2121
from hms_tz.nhif.api.healthcare_utils import get_item_rate
22-
from frappe.utils import date_diff, getdate, nowdate
22+
from frappe.utils import date_diff, getdate, nowdate, cint
2323
from hms_tz.hms_tz.doctype.patient.patient import create_customer
2424
from csf_tz import console
2525

@@ -46,8 +46,7 @@ def get_insurance_amount(
4646
has_no_consultation_charges=False,
4747
):
4848
# SHM Rock: 202
49-
if frappe.utils.cint(has_no_consultation_charges) == 1:
50-
49+
if cint(has_no_consultation_charges) == 1:
5150
return 0, 0
5251

5352
item_price = get_item_rate(
@@ -73,7 +72,7 @@ def get_mop_amount(
7372
patient=None,
7473
has_no_consultation_charges=False,
7574
):
76-
if frappe.utils.cint(has_no_consultation_charges) == 1:
75+
if cint(has_no_consultation_charges) == 1:
7776
return 0
7877

7978
price_list = None
@@ -204,16 +203,18 @@ def invoice_appointment(name):
204203
def get_consulting_charge_item(
205204
appointment_type,
206205
practitioner,
207-
insurance_company=None,
208206
inpatient_record=None,
209-
apply_fasttrack_charge=False,
207+
insurance_company=None,
208+
insurance_subscription=None,
210209
):
211210
charge_item = ""
212211
app_type_details = frappe.get_cached_value(
213212
"Appointment Type",
214213
appointment_type,
215214
[
216-
"follow_up_item",
215+
"gp_followup_item",
216+
"specialist_followup_item",
217+
"super_specialist_followup_item",
217218
"gp_fasttrack_item",
218219
"specialist_fasttrack_item",
219220
"super_specialist_fasttrack_item",
@@ -232,24 +233,44 @@ def get_consulting_charge_item(
232233

233234
charge_item = cons_item
234235

235-
if (
236-
appointment_type == "Follow up Visit"
237-
and insurance_company
238-
and "NHIF" in insurance_company
239-
):
240-
charge_item = app_type_details.get("follow_up_item")
236+
scheme_id = None
237+
if "NHIF" in insurance_company:
238+
plan_name = frappe.get_cached_value(
239+
"Healthcare Insurance Subscription",
240+
insurance_subscription,
241+
"healthcare_insurance_coverage_plan",
242+
)
243+
scheme_id = frappe.get_cached_value(
244+
"Healthcare Insurance Coverage Plan", plan_name, "nhif_scheme_id"
245+
)
241246

242-
if (
243-
frappe.utils.cint(apply_fasttrack_charge) == 1
244-
and insurance_company
245-
and "NHIF" in insurance_company
246-
):
247-
if "General Practitioner" in cons_item:
248-
charge_item = app_type_details.get("gp_fasttrack_item")
249-
elif "Super Specialist" in cons_item:
250-
charge_item = app_type_details.get("super_specialist_fasttrack_item")
251-
elif "Specialist" in cons_item:
252-
charge_item = app_type_details.get("specialist_fasttrack_item")
247+
if insurance_company and "NHIF" in insurance_company and scheme_id:
248+
if appointment_type == "Follow up Visit" and cint(scheme_id) in [
249+
1001,
250+
4001,
251+
5001,
252+
6001,
253+
8001,
254+
]:
255+
if "General Practitioner" in cons_item:
256+
charge_item = app_type_details.get("gp_followup_item")
257+
elif "Super Specialist" in cons_item:
258+
charge_item = app_type_details.get("super_specialist_followup_item")
259+
elif "Specialist" in cons_item:
260+
charge_item = app_type_details.get("specialist_followup_item")
261+
262+
elif cint(scheme_id) in [4001, 5001, 6001, 8001] and appointment_type in [
263+
"Outpatient Visit",
264+
"Normal Visit",
265+
"Emergency",
266+
"NHIF External Referral",
267+
]:
268+
if "General Practitioner" in cons_item:
269+
charge_item = app_type_details.get("gp_fasttrack_item")
270+
elif "Super Specialist" in cons_item:
271+
charge_item = app_type_details.get("super_specialist_fasttrack_item")
272+
elif "Specialist" in cons_item:
273+
charge_item = app_type_details.get("specialist_fasttrack_item")
253274

254275
return charge_item
255276

@@ -293,22 +314,41 @@ def make_vital(appointment_doc, method):
293314

294315
set_follow_up(appointment_doc, "invoice_appointment")
295316
# SHM Rock: 202
296-
if "NHIF" in appointment_doc.insurance_company and appointment_doc.appointment_type:
297-
appointment_doc.has_no_consultation_charges = frappe.get_cached_value(
298-
"Appointment Type",
299-
appointment_doc.appointment_type,
300-
"has_no_consultation_charges",
301-
)
302-
if appointment_doc.has_no_consultation_charges:
303-
if appointment_doc.paid_amount > 0:
304-
appointment_doc.paid_amount = 0
317+
if appointment_doc.insurance_company and appointment_doc.appointment_type:
318+
# Helpdesk: https://support.aakvatech.com/helpdesk/tickets/239
319+
# NHIF introduce follow up item and its price, therefore not need to set has not consultation charges for NHIF patient
320+
# 2024-07-19
321+
scheme_id = None
322+
if "NHIF" in appointment_doc.insurance_company:
323+
plan_name = frappe.get_cached_value(
324+
"Healthcare Insurance Subscription",
325+
appointment_doc.insurance_subscription,
326+
"healthcare_insurance_coverage_plan",
327+
)
328+
scheme_id = frappe.get_cached_value(
329+
"Healthcare Insurance Coverage Plan", plan_name, "nhif_scheme_id"
330+
)
305331

306-
frappe.msgprint(
307-
_(
308-
f"This appointment type: <b>{appointment_doc.appointment_type}</b> has no consultation charges."
309-
),
310-
alert=True,
332+
if not (
333+
"NHIF" in appointment_doc.insurance_company
334+
and scheme_id
335+
and cint(scheme_id) in [1001, 4001, 5001, 6001, 8001]
336+
):
337+
appointment_doc.has_no_consultation_charges = frappe.get_cached_value(
338+
"Appointment Type",
339+
appointment_doc.appointment_type,
340+
"has_no_consultation_charges",
311341
)
342+
if appointment_doc.has_no_consultation_charges:
343+
if appointment_doc.paid_amount > 0:
344+
appointment_doc.paid_amount = 0
345+
346+
frappe.msgprint(
347+
_(
348+
f"This appointment type: <b>{appointment_doc.appointment_type}</b> has no consultation charges."
349+
),
350+
alert=True,
351+
)
312352

313353
if (not appointment_doc.ref_vital_signs) and (
314354
appointment_doc.invoiced
@@ -566,21 +606,21 @@ def set_follow_up(appointment_doc, method):
566606
if appointment and appointment_doc.appointment_date:
567607
diff = date_diff(appointment_doc.appointment_date, appointment.appointment_date)
568608
if appointment_doc.mode_of_payment:
569-
valid_days = int(
609+
valid_days = cint(
570610
frappe.get_cached_value(
571611
"Healthcare Settings", "Healthcare Settings", "valid_days"
572612
)
573613
)
574614
else:
575-
valid_days = int(
615+
valid_days = cint(
576616
frappe.get_cached_value(
577617
"Healthcare Insurance Coverage Plan",
578618
{"coverage_plan_name": appointment_doc.coverage_plan_name},
579619
"no_of_days_for_follow_up",
580620
)
581621
)
582622
if valid_days == 0:
583-
valid_days = int(
623+
valid_days = cint(
584624
frappe.get_cached_value(
585625
"Healthcare Insurance Company",
586626
appointment_doc.insurance_company,
@@ -641,9 +681,9 @@ def make_next_doc(doc, method, from_hook=True):
641681
doc.billing_item = get_consulting_charge_item(
642682
doc.appointment_type,
643683
doc.practitioner,
644-
insurance_company=doc.insurance_company,
645684
inpatient_record=doc.inpatient_record,
646-
apply_fasttrack_charge=doc.apply_fasttrack_charge,
685+
insurance_company=doc.insurance_company,
686+
insurance_subscription=doc.insurance_subscription,
647687
)
648688
if not doc.billing_item:
649689
frappe.throw(
@@ -668,8 +708,21 @@ def make_next_doc(doc, method, from_hook=True):
668708
# Helpdesk: https://support.aakvatech.com/helpdesk/tickets/239
669709
# NHIF introduce follow up item and its price, therefore not need to set has not consultation charges for NHIF patient
670710
# 2024-07-19
711+
scheme_id = None
712+
if "NHIF" in doc.insurance_company:
713+
plan_name = frappe.get_cached_value(
714+
"Healthcare Insurance Subscription",
715+
doc.insurance_subscription,
716+
"healthcare_insurance_coverage_plan",
717+
)
718+
scheme_id = frappe.get_cached_value(
719+
"Healthcare Insurance Coverage Plan", plan_name, "nhif_scheme_id"
720+
)
721+
671722
if not (
672-
"NHIF" in doc.insurance_company and "Follow" in doc.appointment_type
723+
"NHIF" in doc.insurance_company
724+
and scheme_id
725+
and cint(scheme_id) in [1001, 4001, 5001, 6001, 8001]
673726
):
674727
doc.has_no_consultation_charges = frappe.get_cached_value(
675728
"Appointment Type",

hms_tz/patches.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ hms_tz.patches.custom_fields.auto_sales_order_creation_from_encounter
5959
hms_tz.patches.custom_fields.nhif_restricted_therapy_for_service_approval_number
6060
hms_tz.patches.custom_fields.sessions_cancelled_custom_field_on_therapy_plan_detail
6161
hms_tz.patches.property_setter.status_options_for_therapy_plan
62-
hms_tz.patches.custom_fields.fasttrack_consultation_custom_fields
62+
hms_tz.patches.custom_fields.fasttrack_and_follow_up_consultation_custom_fields
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import frappe
2+
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
3+
4+
5+
def execute():
6+
removed_type_custom_field()
7+
8+
fields = {
9+
"Appointment Type": [
10+
{
11+
"fieldname": "source_sec",
12+
"fieldtype": "Section Break",
13+
"insert_after": "items",
14+
},
15+
{
16+
"fieldname": "source",
17+
"label": "Source",
18+
"fieldtype": "Data",
19+
"insert_after": "source_sec",
20+
"translatable": 1,
21+
},
22+
{
23+
"fieldname": "has_no_consultation_charges",
24+
"fieldtype": "Check",
25+
"label": "Has No Consultation Charge",
26+
"insert_after": "source",
27+
"description": "If checked, Consultation Charges will not be applied for Insurance appointments",
28+
},
29+
{
30+
"fieldname": "visit_type_id",
31+
"label": "Visit Type ID",
32+
"fieldtype": "Select",
33+
"insert_after": "has_no_consultation_charges",
34+
"translatable": 1,
35+
"options": """\n1-Normal Visit\n2-Emergency\n3-Referral\n4-Follow up Visit\n5-Investigation Only\n6-Occupational Visit\n7-Medicine Only""",
36+
},
37+
{
38+
"fieldname": "followup_cb",
39+
"fieldtype": "Column Break",
40+
"insert_after": "visit_type_id",
41+
},
42+
{
43+
"fieldname": "gp_followup_item",
44+
"fieldtype": "Link",
45+
"options": "Item",
46+
"label": "GP Followup Item",
47+
"insert_after": "followup_cb",
48+
},
49+
{
50+
"fieldname": "specialist_followup_item",
51+
"fieldtype": "Link",
52+
"options": "Item",
53+
"label": "Specialist Followup Item",
54+
"insert_after": "gp_followup_item",
55+
},
56+
{
57+
"fieldname": "super_specialist_followup_item",
58+
"fieldtype": "Link",
59+
"options": "Item",
60+
"label": "Super Specialist Followup Item",
61+
"insert_after": "specialist_followup_item",
62+
},
63+
{
64+
"fieldname": "fasttrack_cb",
65+
"fieldtype": "Column Break",
66+
"insert_after": "super_specialist_followup_item",
67+
},
68+
{
69+
"fieldname": "gp_fasttrack_item",
70+
"fieldtype": "Link",
71+
"options": "Item",
72+
"label": "GP Fasttrack Item",
73+
"insert_after": "fasttrack_cb",
74+
},
75+
{
76+
"fieldname": "specialist_fasttrack_item",
77+
"fieldtype": "Link",
78+
"options": "Item",
79+
"label": "Specialist Fasttrack Item",
80+
"insert_after": "gp_fasttrack_item",
81+
},
82+
{
83+
"fieldname": "super_specialist_fasttrack_item",
84+
"fieldtype": "Link",
85+
"options": "Item",
86+
"label": "Super Specialist Fasttrack Item",
87+
"insert_after": "specialist_fasttrack_item",
88+
},
89+
],
90+
}
91+
92+
create_custom_fields(fields, update=True)
93+
94+
95+
def removed_type_custom_field():
96+
fields = [
97+
{
98+
"Appointment Type": ["follow_up_item"],
99+
},
100+
{
101+
"Patient Appointment": ["apply_fasttrack_charge"],
102+
},
103+
]
104+
for row in fields:
105+
for key, value in row.items():
106+
for fieldname in value:
107+
custom_field = frappe.get_value(
108+
"Custom Field", {"fieldname": fieldname, "dt": key}, "name"
109+
)
110+
if custom_field:
111+
frappe.delete_doc("Custom Field", custom_field)
112+
113+
frappe.db.commit()

0 commit comments

Comments
 (0)