1919from hms_tz .nhif .doctype .nhif_scheme .nhif_scheme import add_scheme
2020from hms_tz .nhif .doctype .nhif_response_log .nhif_response_log import add_log
2121from 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
2323from hms_tz .hms_tz .doctype .patient .patient import create_customer
2424from 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):
204203def 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" ,
0 commit comments