/**************************************************************************** # $RCSfile: prepare_coverage.sc,v $ #**************************************************************************** # This is a component of rtif - a hitsrc controlled package # developed by the Medical Centers Information Systems # at the University of Washington Academic Medical Centers # # Author: Jeff Martin, www.morningglorytech.com # jeffreymartinj@yahoo.com # # Purpose: # This is prepare_coverage called from prepareA08_reg.sc # or handleA08.tcl during Reg hl7_rcv processing. # prepare_coverage receives the following arguments: # # My_upd_msg hl7_union_t * copy of update msg from prepareA08_reg # MODE char * MODE or TCL flag. # BITMASK char * describes what segment(s) # set the supplied TCL flag. # prepare_coverage has external references to forward messages # created in prepareA08_reg.sc. # # prepare_coverage operates in two modes: VALIDATE and UPDATE. # # VALIDATE MODE # ------------- # if argument 'MODE' is set to the string "VALIDATE", # prepare_coverage then excersizes the processing logic # detailed in CVG Reg_rcv.doc directing I/O at the update # and forward messages while setting TCL flags that store # what tables need updating and what message segment has the # update data. VALIDATE mode also configures the various # forward messages and enables a corresponding TCL flag. # No actual database update activity occurs during VALIDATE mode. # # TCL flags: # prepare_coverage manages flags INS_COVERAGE and # UPD_PERS_PLAN_REL in function coverage_validation. # # prepare_coverage sets flag UPD_SUB_PATIENT in functions # prepare_patient_medicare/caid. # # prepare_coverage calls prepare_subscriber which # manages flags INS_SUB_PERS_SYN, UPD_SUB_PERS_SYN. # # if generic payor_plan processing is enabled, then # create_mfn_message is called in order to create a # MFN event and set TCL flag FORWARD_MFN1, 2 or 3. # TCL symbol UPD_UNL_PPL is also set in this case # in order to update the UNLISTED_PAYOR_PLAN table. # # prepare_coverage.config_fwd_msg popluates data in # the A08 foward message. If a pers_syn insert/update # has been enabled, create_cvg_message is called to # configure either an A28/A31 and set TCL flag # FORWARD_CVG1,2 or 3. # # TCL flag enables # -------- ------- # INS_COVERAGE prepare_coverage.upd_coverage # UPD_PERS_PLAN_REL prepare_coverage.upd_pers_plan_rel # UPD_SUB_PATIENT prepare_coverage.upd_patient # INS_SUB_PERS_SYN prepare_coverage.upd_pers_syn # UPD_SUB_PERS_SYN prepare_coverage.upd_pers_syn # UPD_UNL_PPL prepare_coverage.upd_unl_ppl # FORWARD_CVG1 handleA08.tcl.forward (A28/A31 primary) # FORWARD_CVG2 handleA08.tcl.forward (A28/A31 secondary) # FORWARD_CVG3 handleA08.tcl.forward (A28/A31 tertinary) # FORWARD_MFN1 handleA08.tcl.forward (MFN primary) # FORWARD_MFN2 handleA08.tcl.forward (MFN secondary) # FORWARD_MFN3 handleA08.tcl.forward (MFN tertinary) # # UPDATE MODE # ----------- # If argument 'MODE' is not set to the string "VALIDATE", # prepare_coverage bypasses any validation functions. # Instead, a TCL flag is supplied in argument 'MODE' and # an appropriate database update procedure is called using # argument 'BITMASK' to get the corresponding update data # from the message (see handleA08.tcl). # # VALIDATE mode stores which segment set a given flag in # the flag itself. The flag can then be used to hold two # types of information: what flag is set, what segs set it. # # This mode is implemented in order to separate message # validation and database update activity in time. # # prepare_coverage processing flow: # --------------------------------- # # incoming A08 # ------------ # | process_rcv # -------------- # |handlA08.tcl # ------------- # |prepareA08_reg # --------------- # | |prepare_coverage VALIDATE # | -------------------------- # | |prepare_subscriber # | ------------------- # | |config_fwd_msg # | ---------------- # |prepare_coverage UPDATE # ------------------------ # |axon_forward # ------------- # # Returns: 0 if success, -1 if not. # #**************************************************************************** # # $Source: /homes/hit/interfac/packages/rtif/./common/src/RCS/prepare_coverage.sc,v $ # #**************************************************************************** # $Log: prepare_coverage.sc,v $ # Revision 1.14 2000/12/27 21:25:24 martinj # added payor_plan processing # # Revision 1.13 2000/12/27 21:23:22 martinj # added enhanced medicaid eff date processing # # Revision 1.10 2000/08/18 21:13:02 martinj # added ignore_amc_list() # added strip_all_IN1() # added name_suffix to get_stripped_name() # # Revision 1.9 2000/06/06 23:29:00 martinj # get_sub_pat_no_dsp cores while printing person_no with %s # # Revision 1.8 2000/06/06 22:48:59 martinj # validate subscriber names for each IN1 processing cycle # # Revision 1.7 2000/06/02 21:28:36 martinj # # Revision 1.6 2000/05/27 17:59:33 martinj # *** empty log message *** # # Revision 1.5 2000/05/26 21:25:13 martinj # populated first_entry_dt/by, policy_no for fwd message in config_fwd_msg # # Revision 1.4 2000/05/24 22:25:09 martinj # fixed read_from_pers_plan_rel # # Revision 1.3 2000/05/24 21:29:41 martinj # No longer support PERS_ADDR # fix pers_plan_rel_addr forwarding # # Revision 1.2 2000/05/23 22:49:28 martinj # added cvg_message1 and cvg_message2 # # Revision 1.1 2000/04/21 23:20:36 feattest # Initial revision # # Revision 1.2 2000/03/15 02:55:40 martinj # started by jeff # # Revision 1.1 2000/03/06 22:23:44 martinj # Initial revision # #***************************************************************************/ static char rcsid[] = "$Id: prepare_coverage.sc,v 1.14 2000/12/27 21:25:24 martinj Exp $"; EXEC SQL include sqlca; /* Include SQL structs */ #include #include #include #include #include #include "event.h" #include "ingerr.h" #include "error_stdout.h" #include "prepare_msgs_reg.h" #include "hl7_getset.h" #include "copyseg.h" #include "parse.h" /* gate prepare_patient_medicare 6.0/6.1 processing */ #define IGNORE_MCARE_THRU_D 1 /* define U/H unlisted PPL constants */ #define U_UNL_PPL 66600 #define H_UNL_PPL 66603 /* tcl_action.c */ extern Tcl_Interp *interp; /* function prototypes */ char *hl7_format_dt(char *); int fix_medicaid_dates(hl7_union_t *, hl7_union_t *); EXEC SQL BEGIN DECLARE SECTION; /* message data */ char msg_msh_ctl_id[21]; char msg_assign_benefits[2]; char msg_cob_cd[2]; char msg_eff_from_dt[26]; char msg_eff_thru_dt[26]; char msg_fin_class[5]; char msg_group_name[25]; char msg_group_no[18]; char msg_hosp[2]; char msg_sub_hosp[2]; char msg_sub_pat_no[8]; char msg_in1_set_id[8]; char msg_ins_co_contact_per[49]; char msg_ins_co_phone_no[41]; char msg_ins_company_addr_1[31]; char msg_ins_company_addr_2[31]; char msg_ins_company_city[18]; char msg_ins_company_st[3]; char msg_ins_company_zip[10]; char msg_ins_company_for_zip[10]; char msg_ins_company_country[7]; char msg_ins_company_id[11]; char msg_ins_company_name[41]; char msg_ip_op_de_cd[4]; char msg_mcaid_case_no[13]; char msg_mcaid_pic_no[15]; char msg_mcaid_1st_elig_d[26]; char msg_mcaid_elig_thru_d[26]; char msg_mcare_b_elig_from_d[26]; char msg_mcare_b_elig_thru_d[26]; char msg_mcare_elig[2]; char msg_mcare_no[13]; char msg_net_sec_upd_by[9]; char msh_msg_ctl_id[20]; char msg_pat_no[8]; char msg_pat_rel_to_ins[3]; char msg_payor_desc[41]; char msg_plan_id[25]; char msg_policy_id[17]; char msg_release_info[2]; char msg_spons_cd[4]; char msg_spec_spons_cd[4]; char msg_ssn_stat[2]; char msg_stripped_name[66]; char msg_sub_addr_1[31]; char msg_sub_addr_2[31]; char msg_sub_birth_d[26]; char msg_sub_city[18]; char msg_sub_country_cd[7]; char msg_sub_first_name[16]; char msg_sub_last_name[26]; char msg_sub_middle_name[16]; char msg_sub_name_suffix[7]; char msg_sub_pat_no_dsp[11]; char msg_sub_sex[2]; char msg_sub_ssn[12]; char msg_sub_st[3]; char msg_sub_zip[10]; char msg_upd_area[3]; char msg_upd_by[4]; char msg_evn_timestamp[26]; char msg_zi2_mail_stop[7]; char msg_zi2_cov_a_c_d_cd[8]; char msg_zi2_plan_name[41]; char msg_ZI2_ssn_stat[2]; char pid_first_name[16]; char pid_last_name[26]; char pid_middle_name[16]; char pid_name_suffix[7]; char mother_maiden_name[26]; char zp2_fthr_name[26]; char zp2_stripped_name[26]; int msg_person_no; int msg_sub_person_no; /* DB attributes */ int db_cvg_payor_plan_no; /* COVERAGE ppl no */ int db_unl_ppl_no; /* UNLISTED_PAYOR_PLAN */ int db_sub_person_no; /* COVERAGE person_no */ int intPerson_no; /* SEQUENCE.person_no */ char uwmc_pat_no[8]; char hmc_pat_no[8]; char race[3]; char microfiche_rec[2]; char bypass_rs[2]; char soundex_cd[11]; char db_pat_rel_to_ins[3]; char db_assign_benefits[2]; char db_release_info[2]; char db_eff_from_dt[26]; char db_eff_thru_dt[26]; char db_group_no[18]; char db_group_name[25]; char db_upd_dt[26]; int def_addr_seq_no; /* current PAYOR_PLAN */ int last_addr_seq_no; char def_group_no[18]; char def_group_name[25]; int plan_no; char spons_cd[4]; char eff_from_dt[26]; char eff_thru_dt[26]; int payor_no; char generic_flag[2]; char db_ppr_eff_from_dt[26]; /* PERS_PLAN_REL */ char db_ppr_first_entry_dt[26]; char db_ppr_first_entry_by[4]; char db_mcare_eligible[2]; /* PATIENT */ char db_mcare_no[13]; char db_mcare_b_elig_from_d[26]; char db_mcare_b_elig_thru_d[26]; char db_mcaid_1st_elig_d[26]; char db_mcaid_elig_thru_d[26]; char db_mcaid_pic_no[15]; char db_mcaid_case_no[13]; char db_ins_policy_id[17]; /* current policy ID */ int payor_plan_no; /* PAYOR_PLAN/XREF */ int orig_ppl_no; int generic_ppl_no; int GENERIC_PPL; /* set in IsPlanCurrent */ int GENERIC_GENERIC_PPL; char payor_desc[41]; /* PAYOR_N/CLAIM_ADDRESS */ char addr_1[31]; char addr_2[31]; char city[18]; char st[3]; char zip[6]; char zip_suffix[5]; char foreign_zip[7]; char country_cd[7]; char upd_dt[26]; char ins_company_zip[12]; /* misc local host var */ int cov_default_plan_no = 0; char REG_HIGH_DT[] = {"31-dec-2099 23:59:59"}; int OP_A_FLIP = 0; int OP_B_FLIP = 0; int plan_found = 0; int plan_xref_found = 0; int pers_plan_rel_found = 0; int coverage_found = 0; int found = 0; EXEC SQL END DECLARE SECTION; /* defined in axon_HL7_references.c */ extern spec_t MSH_send_app; extern spec_t MSH_send_facility; extern spec_t MSH_dest_app; extern spec_t MSH_dest_facility; extern spec_t MSH_hl7_version; extern spec_t MSH_sequence_id; extern spec_t PID_patient_id; extern spec_t PID_name_last; extern spec_t PID_name_first; extern spec_t PID_name_middle; extern spec_t PID_name_suffix; extern spec_t ZP2_person_no; extern spec_t ZP2_ssn_stat; extern spec_t ZP2_stripped_name; extern spec_t ZVN_upd_by; extern spec_t ZVN_upd_area; extern spec_t ZVN_screen_id; extern spec_t EVN_timestamp; extern spec_t EVN_operator_id; /* net_sec_upd_by */ extern spec_t PV1_fin_class; /* { "PV1", 20, 0, 0 } */ /* not defined in axon_HL7_references.c */ spec_t PID_mother_name = { "PID", 6, 0, 0 }; spec_t IN1_set_id = { "IN1", 1, 0, 0 }; spec_t IN1_plan_id = { "IN1", 2, 0, 0 }; spec_t IN1_ins_company_id = { "IN1", 3, 0, 0 }; spec_t IN1_ins_company_name = { "IN1", 4, 0, 0 }; spec_t IN1_ins_company_addr_1 = { "IN1", 5, 0, 0 }; spec_t IN1_ins_company_addr_2 = { "IN1", 5, 1, 0 }; spec_t IN1_ins_company_city = { "IN1", 5, 2, 0 }; spec_t IN1_ins_company_st = { "IN1", 5, 3, 0 }; spec_t IN1_ins_company_zip = { "IN1", 5, 4, 0 }; spec_t IN1_ins_company_country = { "IN1", 5, 5, 0 }; spec_t IN1_ins_co_contact_per = { "IN1", 6, 0, 0 }; spec_t IN1_ins_co_phone_no = { "IN1", 7, 0, 0 }; spec_t IN1_group_no = { "IN1", 8, 0, 0 }; spec_t IN1_group_name = { "IN1", 9, 0, 0 }; spec_t IN1_eff_from_dt = { "IN1", 12, 0, 0 }; spec_t IN1_eff_thru_dt = { "IN1", 13, 0, 0 }; spec_t IN1_fin_class = { "IN1", 15, 0, 0 }; spec_t IN1_sub_last_name = { "IN1", 16, 0, 0 }; spec_t IN1_sub_first_name = { "IN1", 16, 1, 0 }; spec_t IN1_sub_middle_name = { "IN1", 16, 2, 0 }; spec_t IN1_sub_name_suffix = { "IN1", 16, 3, 0 }; spec_t IN1_pat_rel_to_ins = { "IN1", 17, 0, 0 }; spec_t IN1_sub_birth_d = { "IN1", 18, 0, 0 }; spec_t IN1_sub_addr_1 = { "IN1", 19, 0, 0 }; spec_t IN1_sub_addr_2 = { "IN1", 19, 1, 0 }; spec_t IN1_sub_city = { "IN1", 19, 2, 0 }; spec_t IN1_sub_st = { "IN1", 19, 3, 0 }; spec_t IN1_sub_zip = { "IN1", 19, 4, 0 }; spec_t IN1_sub_country_cd = { "IN1", 19, 5, 0 }; spec_t IN1_assign_benefits = { "IN1", 20, 0, 0 }; spec_t IN1_cob_cd = { "IN1", 21, 0, 0 }; spec_t IN1_release_info = { "IN1", 27, 0, 0 }; spec_t IN1_policy_id = { "IN1", 36, 0, 0 }; spec_t IN1_sub_sex = { "IN1", 43, 0, 0 }; spec_t IN2_sub_ssn = { "IN2", 2, 0, 0 }; spec_t ZI2_mail_stop = { "ZI2", 2, 0, 0 }; spec_t ZI2_mcare_b_elig_from_d = { "ZI2", 4, 0, 0 }; spec_t ZI2_mcare_b_elig_thru_d = { "ZI2", 5, 0, 0 }; spec_t ZI2_ip_op_de_cd = { "ZI2", 7, 0, 0 }; spec_t ZI2_mcaid_1st_elg_dt = { "ZI2", 9, 0, 0 }; spec_t ZI2_mcaid_elg_thru_dt = { "ZI2", 10, 0, 0 }; spec_t ZI2_payor_desc = { "ZI2", 18, 0, 0 }; spec_t ZI2_spons_cd = { "ZI2", 21, 0, 0 }; spec_t ZI2_cov_a_c_d_cd = { "ZI2", 26, 0, 0 }; spec_t ZI2_plan_a_c_d_cd = { "ZI2", 27, 0, 0 }; spec_t ZI2_person_no = { "ZI2", 33, 0, 0 }; spec_t ZI2_pat_to_pers = { "ZI2", 34, 0, 0 }; spec_t ZI2_stripped_name = { "ZI2", 45, 0, 0 }; spec_t ZI2_cov_eff_from_dt = { "ZI2", 46, 0, 0 }; spec_t ZI2_cov_eff_thru_dt = { "ZI2", 47, 0, 0 }; spec_t ZI2_ssn_stat = { "ZI2", 53, 0, 0 }; spec_t ZI2_ins_id_int = { "ZI2", 55, 0, 0 }; spec_t ZI2_first_entry_dt = { "ZI2", 57, 0, 0 }; spec_t ZI2_first_entry_by = { "ZI2", 58, 0, 0 }; spec_t ZI2_plan_rel_eff_date = { "ZI2", 59, 0, 0 }; spec_t ZI2_plan_rel_exp_date = { "ZI2", 60, 0, 0 }; spec_t ZI2_pay_plan_no = { "ZI2", 61, 0, 0 }; spec_t ZI2_addr_seq_no = { "ZI2", 62, 0, 0 }; spec_t ZI2_plan_name = { "ZI2", 65, 0, 0 }; spec_t ZP2_mcaid_case_no = { "ZP2", 27, 0, 0 }; spec_t ZP2_mcaid_pic_no = { "ZP2", 28, 0, 0 }; spec_t ZP2_fthr_name = { "ZP2", 43, 0, 0 }; spec_t ZP2_mcare_no = { "ZP2", 74, 0, 0 }; spec_t ZP2_spec_spnsr_cd = { "ZP2", 80, 0, 0 }; spec_t ZP2_mcare_elig = { "ZP2",108, 0, 0 }; spec_t PV1_set_id = { "PV1", 1, 0, 0 }; spec_t ZV2_set_id = { "ZV2", 1, 0, 0 }; int PrevRowId = 0; /* last random tie_breaker */ int address_valid = 1; /* set/cleared in validate_addr */ extern int verbose_level; /* set in axon_parameters.c */ int in1_count = 0; /* number of IN1 segments */ int in1_no = 0; /* current IN1 segment */ int CHANGE_SUB = 0; /* set in prepare_subscriber.sc */ int INS_SUB_PERS_SYN = 0; int UPD_SUB_PERS_SYN = 0; /* set in prepare_patient_medicXX */ int UPD_SUB_PATIENT = 0; /* set in prepare_patient_medicXX */ int INS_COVERAGE = 0; /* set in prepare_coverage.sc */ int UPD_PERS_PLAN_REL = 0; /* set in prepare_coverage.sc */ int UPD_UNL_PPL = 0; /* set in prepare_coverage.sc */ int PERFORM_INSERT = 0; /* set in do_db_updates */ char buf[BUFSIZ]; /* buffer for log writes */ char *strHl7_date; /* gets char * from hl7_format_dt */ char strDate[26]; /* generic date buffer */ /* prepareA08_reg.vfy_A08_identifiers */ extern char glob_pat_id[LEN_HOSP_AND_PAT_NO]; extern char glob_id_type[LEN_PERS_XREF_TYPE]; char *msg_pat_id[64]; /* current PID3 from amc_list[] */ /*********************** main *****************************************/ int prepare_coverage(hl7_union_t *My_upd_msg, char *MODE, char *BITMASK) { /* prepareA08_reg.sc */ extern hl7_union_t *fwd_message; extern hl7_union_t *cvg_message1; extern hl7_union_t *cvg_message2; extern hl7_union_t *cvg_message3; extern hl7_union_t *mfn_message1; extern hl7_union_t *mfn_message2; extern hl7_union_t *mfn_message3; sprintf(buf,"\n**** Running prepare_coverage in %s mode ****\n", strcmp(MODE,"VALIDATE") ? "UPDATE" : "VALIDATE"); error_notify(__FILE__,__LINE__,buf,NOTIFY_DEBUG); /* count IN1 segment groups */ in1_count = count_segs(My_upd_msg, "IN1"); /* no IN1 in UPDATE mode is fatal */ if( in1_count <= 0 ) { error_notify(__FILE__,__LINE__, "\n\tmessage has no IN1 segments", strcmp(MODE,"VALIDATE") ? NOTIFY_FATAL : NOTIFY_UPDATE); return(strcmp(MODE,"VALIDATE") ? -1 : 0); } /* service VALIDATE mode (set TCL flags) */ if( !strcmp(MODE,"VALIDATE") && in1_count >= 1) { /* only process original service center idr */ if( ignore_amc_list(My_upd_msg, fwd_message)) { error_notify(__FILE__,__LINE__, "\n**** Finished with prepare_coverage ****\n", NOTIFY_DEBUG); return(0); } /* 7.1 Coverage Flip */ if(in1_count >= 2 ) { if( prepare_spons_coverage_flip(My_upd_msg, fwd_message) == -1 ) return(-1); } /* 7.2 Coverage Validation */ if(in1_count >= 1 ) { if( coverage_validation(My_upd_msg, fwd_message) == -1 ) return(-1); } } /* if( !strcmp(MODE,"VALIDATE")) */ /* service UPDATE mode (get TCL flags) */ if( strcmp(MODE,"VALIDATE") && in1_count >= 1) { if( do_db_updates(My_upd_msg,fwd_message,MODE,BITMASK) == -1 ) return(-1); } /* if( strcmp(MODE,"VALIDATE")) */ /*********************************************************************/ error_notify(__FILE__,__LINE__, "\n**** Finished with prepare_coverage ****\n", NOTIFY_DEBUG); return(0); }/**************** end of prepare_coverage ********************************/ /************************************************************************* * function: coverage_validation * args: hl7_union_t *My_upd_msg, *My_fwd_msg * returns: 0 if normal completion, -1 if fatal error. * usage info: validates My_upd_msg using rules detailed in CVG Reg_rcv.doc * and coverage_validation.vsd by T. Rozmyn, et al. * * modifies messages. * * calls functions to preform medicare/caid processing, * subscriber processing and set TCL flags. * * this function is currently intended to be called from * prepare_coverage.sc and relies on globals declared there. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 19-Oct-2000 * Mod: added code to manage UPD_UNL_PPL and FORWARD_MFN flags. * added functions 'upd_unl_ppl' and 'create_MFN_msg' * * Programmer: Jeff Martin * Date: 13-Apr-2000 * Mod: set bits in TCL flags. * * Programmer: Jeff Martin * Date: 04-Apr-2000 * Mod: implement new UPD_PERS_PLAN_REL rules. * * Programmer: Jeff Martin * Date: 23-Feb-2000 * Started. A copy of coverage_validation.vsd is * reccommended in hand before reading this code * (the comments refer to Visio blocks in the drawing). *************************************************************************/ int coverage_validation(hl7_union_t *My_upd_msg, hl7_union_t *My_fwd_msg) { /* bit fields that describe which segment set the flag */ int bitINS_COVERAGE = 0; int bitUPD_SUB_PATIENT = 0; int bitUPD_PERS_PLAN_REL = 0; int bitUPD_SUB_PERS_SYN = 0; int bitINS_SUB_PERS_SYN = 0; int bitUPD_UNL_PPL = 0; int bitBIT = 0; /* seg count immune to strip_seg */ char strBitField[8]; /* string for Tcl_SetVar */ /* skips IN1 segment groups */ int SKIP_IN1 = 0; /* 7.2 Coverage Validation */ error_notify(__FILE__,__LINE__, "\tRunning coverage_validation()",NOTIFY_UPDATE); /* reset TCL global flags */ Tcl_SetVar(interp,"INS_COVERAGE","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_PERS_PLAN_REL","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"INS_SUB_PERS_SYN","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_SUB_PATIENT","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_UNL_PPL","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_CVG1","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_CVG2","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_CVG3","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_MFN1","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_MFN2","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_MFN3","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); /* count IN1's */ in1_count = count_segs(My_upd_msg, "IN1"); /* for each IN1 segment */ for(in1_no=1; in1_no<=in1_count; in1_no++) { /* reset coverage segment flags */ INS_COVERAGE = 0; UPD_PERS_PLAN_REL = 0; UPD_SUB_PATIENT = 0; UPD_UNL_PPL = 0; GENERIC_PPL = 0; GENERIC_GENERIC_PPL = 0; /* 1.0 Read message data */ if( read_from_msg(My_upd_msg) == -1) return(-1); /* validate msg_pat_rel_to_ins before any further DB activity */ switch( validate_rel_cd(My_upd_msg, My_fwd_msg)) { case 1: break; /* valid rel_cd */ case 0: return(0); /* invalid rel_cd */ break; case -1: return(-1); /* fatal (msg/db I/O)? */ break; } /* 2.0 Is Plan ID in payor_plan_xref? */ if( IsPlanMapped(0) == -1 ) return(-1); /* 2.1 Is Plan Current? */ if( plan_xref_found == 1 ) { if( IsPlanCurrent() == -1 ) return(-1); } /* 2.2 Is Plan not mapped or not current */ if( plan_xref_found == 0 || plan_found == 0 ) { sprintf(buf, "|8000|WARNING: Plan Not Found|n/a|%s%s|OP/%s|%s|%s|%d|", msg_hosp,msg_pat_no,msg_cob_cd,msg_plan_id, msg_upd_by,msg_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_WARNING); /* 2.5 Delete IN1, IN2, ZI2 segments */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tStripping IN1, IN2, ZI2 data because\n" "\tplan '%s' in group %d is not mapped or not current.", msg_plan_id, in1_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } strip_all_IN1(My_upd_msg, My_fwd_msg); return(0); /* ignore any remaining IN1's */ }/* if( plan_xref_found == 0 || plan_found == 0 ) */ /* Plan is mapped and current */ if( plan_xref_found == 1 && plan_found == 1 ) { /* 3.0 Fin Class = 'CARE' ? */ if( strcmp(msg_fin_class,"CARE") == 0 ) { /* 3.1 Call prepare_patient_medicare */ if( prepare_patient_medicare(My_upd_msg, My_fwd_msg) == -1) return(-1); } /* 4.0 Fin Class = 'CAID' ? */ if( strcmp(msg_fin_class,"CAID") == 0 ) { /* 4.1 Call prepare_patient_medicaid */ if( prepare_patient_medicaid(My_upd_msg, My_fwd_msg) == -1) return(-1); } /* 5.2 is Name valid? */ switch( validate_subscriber_name(My_upd_msg, My_fwd_msg) ) { case -1: return(-1); break; /* fatal (message I/O) */ case 0: return(0); break; /* warning (is not valid) */ default: break; /* normal (is valid) */ } /* is Insurance Company Address valid? */ if( GENERIC_PPL + GENERIC_GENERIC_PPL > 0 ) { switch( validate_addr(My_upd_msg, My_fwd_msg) ) { case -1: return(-1); break; /* fatal (message I/O) */ case 0: return(0); break; /* warning (is not valid) */ default: break; /* normal (is valid) */ } /* enable GENERIC PLAN updates */ if( address_valid ) { UPD_UNL_PPL = 1; INS_COVERAGE = 1; } } /* GENERIC_PPL or GENERIC_GENERIC_PPL */ /* 5.0 READ from DB: current COVERAGE */ if( read_from_coverage(My_upd_msg, My_fwd_msg) == -1 ) return(-1); /* 6.0 READ from DB: current PERS_PLAN_REL */ if( read_from_pers_plan_rel() == -1 ) return(-1); /*********************************************************** * 7.0 Call prepare_subscriber * ***********************************************************/ if( prepare_subscriber(My_upd_msg, My_fwd_msg) == -1) return(-1); error_notify(__FILE__,__LINE__, "\nBack from prepare_subscriber()",NOTIFY_DEBUG); /* 10.0 Do msg, DB Cvgs Differ? */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tCHANGE_SUB: %d, \n" "\tdb_assign_benefits: '%s' msg_assign_benefits: '%s'\n" "\tdb_release_info: '%s' msg_release_info: '%s'\n" "\tdb_group_no: '%s' msg_group_no: '%s'\n" "\tdb_group_name: '%s' msg_group_name: '%s'\n" "\tdb_cvg_payor_plan_no: %d payor_plan_no: %d\n", CHANGE_SUB, db_assign_benefits, msg_assign_benefits, db_release_info, msg_release_info, db_group_no, msg_group_no, db_group_name, msg_group_name, db_cvg_payor_plan_no, payor_plan_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } if( CHANGE_SUB || (strcmp(db_assign_benefits, msg_assign_benefits) ) || (strcmp(db_release_info, msg_release_info) ) || (strcmp(db_group_no, msg_group_no) ) || (strcmp(db_group_name, msg_group_name) ) || (db_cvg_payor_plan_no != payor_plan_no) ) { INS_COVERAGE = 1; } /* CHANGE_SUB */ sprintf(buf,"\tUPD_UNL_PPL %c 0\n", UPD_UNL_PPL ? '>' : '='); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); sprintf(buf,"\tINS_COVERAGE %c 0\n", INS_COVERAGE ? '>' : '='); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); /* 11.0 Do msg, DB Policy ids Differ? */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tCHANGE_SUB: %d\n" "\tmsg_policy_id: '%s'\n\tdb_policy_id: '%s'\n" "\tdb_cvg_payor_plan_no: %d, payor_plan_no: %d\n", CHANGE_SUB,msg_policy_id,db_ins_policy_id, db_cvg_payor_plan_no, payor_plan_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } if( strcmp(msg_policy_id,"") && (strcmp(msg_policy_id,db_ins_policy_id) || CHANGE_SUB == 1 || db_cvg_payor_plan_no != payor_plan_no )) { UPD_PERS_PLAN_REL = 1; } sprintf(buf,"\tUPD_PERS_PLAN_REL %c 0\n", UPD_PERS_PLAN_REL ? '>' : '='); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); /* store segment numbers in TCL flags for database updates */ if( INS_COVERAGE ) { bitINS_COVERAGE |= 1<<(bitBIT); sprintf(strBitField,"%d",bitINS_COVERAGE); Tcl_SetVar(interp,"INS_COVERAGE",strBitField, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); } if( UPD_SUB_PATIENT ) { bitUPD_SUB_PATIENT |= 1<<(bitBIT); sprintf(strBitField,"%d",bitUPD_SUB_PATIENT); Tcl_SetVar(interp,"UPD_SUB_PATIENT",strBitField, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); } if( UPD_PERS_PLAN_REL ) { bitUPD_PERS_PLAN_REL |= 1<<(bitBIT); sprintf(strBitField,"%d",bitUPD_PERS_PLAN_REL); Tcl_SetVar(interp,"UPD_PERS_PLAN_REL",strBitField, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); } if( INS_SUB_PERS_SYN ) { bitINS_SUB_PERS_SYN |= 1<<(bitBIT); sprintf(strBitField,"%d",bitINS_SUB_PERS_SYN); Tcl_SetVar(interp,"INS_SUB_PERS_SYN",strBitField, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); } if( UPD_SUB_PERS_SYN ) { bitUPD_SUB_PERS_SYN |= 1<<(bitBIT); sprintf(strBitField,"%d",bitUPD_SUB_PERS_SYN); Tcl_SetVar(interp,"UPD_SUB_PERS_SYN",strBitField, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); } if( UPD_UNL_PPL ) { bitUPD_UNL_PPL |= 1<<(bitBIT); sprintf(strBitField,"%d",bitUPD_UNL_PPL); Tcl_SetVar(interp,"UPD_UNL_PPL",strBitField, TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); } /* this works only if setting a TCL flag means no strip_seg/collaspe occurred (why would you want to enable a seg (TCL flag) after you stripped it?) else, strip/collaspe will misalign the bitmask with the actual seg count when I get the message back. For this reason if somebody else deletes IN1/ZI2 outside of prepare_coverage, please adjust these TCL coverage flags in handleA08.tcl. Thank you. -Jeff */ if( INS_COVERAGE || UPD_PERS_PLAN_REL || INS_SUB_PERS_SYN || UPD_SUB_PERS_SYN || UPD_SUB_PATIENT || UPD_UNL_PPL ) { bitBIT++; /* next segment in mask */ /* assign a person_no now for the fwd messages */ if( INS_SUB_PERS_SYN) { error_notify(__FILE__, __LINE__, "\tINS_SUB_PERS_SYN > 0",NOTIFY_UPDATE); if( upd_seq_no(My_upd_msg, My_fwd_msg) == -1) return(-1); } /* configure fwd messages */ if( config_fwd_msg(My_upd_msg, My_fwd_msg) == -1 ) return(-1); } if( INS_COVERAGE + UPD_PERS_PLAN_REL + INS_SUB_PERS_SYN + UPD_SUB_PERS_SYN + UPD_SUB_PATIENT + UPD_UNL_PPL == 0 ) { sprintf(buf, "\tStripping IN1, IN2, ZI2 segment %d data\n" "\tbecause message represents no update activity.", in1_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); /* del_seg.c */ strip_seg(My_upd_msg, "IN1", in1_no, 0, 0); strip_seg(My_upd_msg, "IN2", in1_no, 0, 0); strip_seg(My_upd_msg, "ZI2", in1_no, 0, 0); strip_seg(My_fwd_msg, "IN1", in1_no, 0, 0); strip_seg(My_fwd_msg, "IN2", in1_no, 0, 0); strip_seg(My_fwd_msg, "ZI2", in1_no, 0, 0); } }/* if( plan_xref_found == 1 && plan_found == 1 ) */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tcurrent bitmasks\n\t----------------\n" "\tINS_COVERAGE = 0x%04X\n" "\tUPD_PERS_PLAN_REL = 0x%04X\n" "\tINS_SUB_PERS_SYN = 0x%04X\n" "\tUPD_SUB_PERS_SYN = 0x%04X\n" "\tUPD_SUB_PATIENT = 0x%04X\n" "\tUPD_UNL_PPL = 0x%04X\n", bitINS_COVERAGE, bitUPD_PERS_PLAN_REL, bitINS_SUB_PERS_SYN, bitUPD_SUB_PERS_SYN, bitUPD_SUB_PATIENT, bitUPD_UNL_PPL); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } /* remove IN2 from the forward message */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tStripping IN2 segment %d data from the fwd msg", in1_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } strip_seg(My_fwd_msg, "IN2", in1_no, 0, 0); sprintf(buf,"\tFinished with IN1 segment %d for %s%s\n", in1_no,msg_hosp,msg_pat_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } /* for(in1_no=1; in1_no<=in1_count; in1_no++) */ return(0); }/*************** end of coverage_validation ****************************/ /*************************************************************************** * function: ignore_amc_list * args: hl7_union_t *upd_msg, *fwd_msg. * returns: -1 if an error occured, 1 if this amc_list idr * should not be processed. * usage info: This function was added after go-live to get * around the portion of the spec that required * coverage processing for all related AMC idrs. * * HISTORY: * -------- * Programmer: * Date: * Mod: * ***************************************************************************/ int ignore_amc_list(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { char *c3; /*************************************************************************/ /* get the current amc_list idr */ c3 = (char *) hl7_get(upd_msg, &PID_patient_id, 1, 0, NULL, 0, 0); strncpy(msg_pat_id, ( c3 ? c3 : ""),63); sprintf(buf,"\tignore_amc_list: %s assigned '%s', current '%s'", glob_id_type,glob_pat_id,msg_pat_id); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); /* glob_pat_id is populated in prepareA08_reg before MSH pat_id gets clobbered with amc_list[] data */ if( strcmp(glob_pat_id,msg_pat_id) ) { error_notify(__FILE__, __LINE__, "\tstripping IN1/IN2/ZI2 segment data.",NOTIFY_UPDATE); /* strip all IN1/IN2/ZI2 from these messages */ strip_all_IN1(upd_msg, fwd_msg); return(1); /* force main to return */ } /* strcmp(glob_pat_id,msg_pat_id) */ return(0); }/********************* end of ignore_amc_list ****************************/ /*************************************************************************** * function: prepare_spons_coverage_flip * args: hl7_union_t * to current upd_msg, fwd_msg. * returns: -1 if an error occured, 0 if none. * usage info: This function validates each IN1 segment in the current * upd_msg using logic detailed in CVG Reg_rcv.doc section 7.1 * If there are two IN1 segments eligible for swapping, * then the cob_cds (IN1.21) are exchanged in both messages. * * This function is currently intended to be called from * prepare_coverage.sc and relies on globals declared there. * * This function acts on messages that contain pairs of * IN1 segments only and the cob_cd's in each must contain * either the string "A" or "B". * * HISTORY: * -------- * Programmer: Jeff Martin * Date: 29-Mar-2000 * Mod: A/B or B/A cob_cd flipping is permitted if supported * in SPONS_COVERAGE_FLIP. * * * Programmer: Jeff Martin, from concepts by T. Rozmyn, et al. * Date: 18-Feb-2000 * Started. A copy of spons_coverage_flip.vsd is * reccommended in hand before reading this code. * ****************************************************************************/ int prepare_spons_coverage_flip(hl7_union_t *My_upd_msg, hl7_union_t *My_fwd_msg ) { EXEC SQL BEGIN DECLARE SECTION; char cob_cd_A[2]; char cob_cd_B[2]; EXEC SQL END DECLARE SECTION; /***************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning prepare_spons_coverage_flip()", NOTIFY_UPDATE); /* 1.01/1.02 */ OP_A_FLIP = OP_B_FLIP = 0; cob_cd_A[0]=cob_cd_B[0]='\0'; /* for each IN1 segment group */ for(in1_no=1; in1_no<=in1_count; in1_no++) { /* 2.01 Read message data */ if( read_from_msg(My_upd_msg) == -1) return(-1); /* M60 and M61 spons_cd cannot flip cob_cd's */ if( !strncmp(msg_spons_cd,"M60",4) || !strncmp(msg_spons_cd,"M61",4)) { if( verbose_level >= VERBOSE_MADDENING ) { sprintf(buf, "\t%s is not eligible for swapping\n", msg_spons_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); } return(0); } /* restrain cob_cd's to between A and B */ if( strcmp(msg_cob_cd,"A") && strcmp(msg_cob_cd,"B") ) { sprintf(buf, "\tcob_cd %s, %s is not eligible for swapping\n", spons_cd, msg_cob_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); return(0); } sprintf(buf, "\tQualifing %s%s, cob_cd: %s, plan_id: %s", msg_hosp, msg_pat_no, msg_cob_cd, msg_plan_id); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); /* 2.02 Is Plan ID Mapped? */ if( IsPlanMapped(1) == -1 ) return(-1); if( plan_xref_found == 0 ) return(0); /* 2.03 Is Plan Current */ if( IsPlanCurrent() == -1) return(-1); if( plan_found == 0) return(0); /* 2.04 Is Spons Cd flippable */ if( !strcmp(msg_cob_cd,"A") ) { if( verbose_level >= VERBOSE_MADDENING) printf("\nSELECT 1\n" " FROM SPONS_COVERAGE_FLIP\n" " WHERE spons_cd = '%s'\n" " AND cob_cd = '%s'\n\n", spons_cd, msg_cob_cd); EXEC SQL REPEATED SELECT 1 INTO :OP_A_FLIP FROM SPONS_COVERAGE_FLIP WHERE spons_cd = :spons_cd AND cob_cd = :msg_cob_cd; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING) sprintf(buf, "\tcob_cd %s, %s is eligible for swapping\n", spons_cd, msg_cob_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); /* find which segment in the pair */ if(in1_no & 0x01) strcpy(cob_cd_A,msg_cob_cd); /* odd */ else strcpy(cob_cd_B,msg_cob_cd); /* even */ break; case 100: sprintf(buf, "\tcob_cd %s, %s is not eligible for swapping\n", spons_cd, msg_cob_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); return(0); break; default: printf("\nCan't select against SPONS_COVERAGE_FLIP\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ } /* if( !strcmp(msg_cob_cd,"A") */ /* 2.05 is Spons Cd flippable */ if( !strcmp(msg_cob_cd,"B") ) { if( verbose_level >= VERBOSE_MADDENING) printf("\nSELECT 1 \n" " FROM SPONS_COVERAGE_FLIP\n" " WHERE spons_cd = '%s'\n" " AND cob_cd = '%s'\n\n", spons_cd, msg_cob_cd); EXEC SQL REPEATED SELECT 1 INTO :OP_B_FLIP FROM SPONS_COVERAGE_FLIP WHERE spons_cd = :spons_cd AND cob_cd = :msg_cob_cd; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tcob_cd %s, %s is eligible for swapping\n", spons_cd, msg_cob_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); } /* find which segment in the pair */ if(in1_no & 0x01) strcpy(cob_cd_A,msg_cob_cd); /* odd */ else strcpy(cob_cd_B,msg_cob_cd); /* even */ break; case 100: sprintf(buf, "\tcob_cd %s, %s is not eligible for swapping\n", spons_cd, msg_cob_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); return(0); break; default: printf("\nCan't select against SPONS_COVERAGE_FLIP\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ } /* if( !strcmp(msg_cob_cd,"B") */ /* 3.0 Determine whether both coverages are flippable */ if(OP_A_FLIP == 1 && OP_B_FLIP == 1) { OP_A_FLIP = OP_B_FLIP = 0; /* support multiple A/B groups */ /* 4.0 flip coordination of benefits priority */ sprintf(buf,"\tSwapping COB_CD's in IN1 segment %d and %d", in1_no-1,in1_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); /* process A segment */ if( hl7_set(My_upd_msg, &IN1_cob_cd, in1_no-1, 0, 0, 0, cob_cd_B)) { sprintf(buf,"\nCan't swap cob_cd segment %d in upd_msg", in1_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg, &IN1_cob_cd, in1_no-1, 0, 0, 0, cob_cd_B)) { sprintf(buf,"\nCan't swap cob_cd segment %d in fwd_msg", in1_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_FATAL); return(-1); } /* process B segment */ if( hl7_set(My_upd_msg, &IN1_cob_cd, in1_no, 0, 0, 0, cob_cd_A)) { sprintf(buf,"\nCan't swap cob_cd segment %d in upd_msg", in1_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg, &IN1_cob_cd, in1_no, 0, 0, 0, cob_cd_B)) { sprintf(buf,"\nCan't swap cob_cd segment %d in fwd_msg", in1_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_FATAL); return(-1); } } /* if(OP_A_FLIP == 1 && OP_B_FLIP == 1) */ /* must have pairs of IN1's to continue */ if( (in1_count-in1_no) == 1 && in1_count > 2) return(0); } /* for(in1_no=1; in1_no<=in1_count; in1_no++) */ return(0); }/******** end of prepare_spons_coverage_flip ***************************/ /************************************************************************ * function: do_db_updates * args: hl7_union_t *My_upd_msg, *fwd_msg, * char *strFlag, char *strMask * returns: -1 if a fatal error occurred. * usage info: gets a flag name and a bit mask. * flag name tells what database update * function to call. bit mask tells what * segment in the message has the data. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 19-Oct-2000 * Mod: Service flag UPD_UNL_PPL * * Programmer: Jeff Martin * Date: 12-Apr-2000 * Mod: started. *************************************************************************/ int do_db_updates(hl7_union_t *upd_msg, hl7_union_t *fwd_msg, char *strFlag, char *strMask) { int intMask = 0; /* bit field of segs that set a flag */ int intMaxBits = 0; int counter = 0; int NO_HANDLER = 1; /* cleared if a handler was called */ /************************************************************************/ if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning do_db_updates()", NOTIFY_UPDATE); intMask = atoi(strMask); if( !intMask) { sprintf(buf,"\nFLAG <%s> = <%s>\n" "bit mask contains no bits or not numeric?",strFlag,strMask); error_notify(__FILE__,__LINE__,buf,NOTIFY_SERIOUS); return(0); } /* count IN1 segment groups */ in1_count = count_segs(upd_msg, "IN1"); /* only this many bits can be set */ for( counter=1; counter<=in1_count; counter++) intMaxBits |= 1 << (counter-1); if( intMask > intMaxBits ) { sprintf(buf,"\n\nBit Mask: %d\t\tIN1 count: %d\n" "bit mask specifies more segments than in message.\n" "These will be ignored, but probably mean bit mask\n" "mis-alignment has occurred.\n", intMask, in1_count); error_notify(__FILE__,__LINE__,buf,NOTIFY_SERIOUS); } if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tdo_db_updates() got <%s> = <%08X>", strFlag, intMask); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } /* check bits */ for( in1_no=1; in1_no<=in1_count; in1_no++) { /* this segment set a TCL flag during VALIDATE processing */ if( intMask & 1<<(in1_no-1) ) { sprintf(buf,"\n\tIN1 segment %d set flag %s",in1_no,strFlag); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); /* get in1_no segment data */ if( read_from_msg(upd_msg) == -1) return(-1); /* get payor_plan_no and GENERIC status */ if( IsPlanMapped(0) == -1 ) return(-1); if( IsPlanCurrent() == -1 ) return(-1); /* this is REALLY strange since it was mapped during VALIDATE? */ if( plan_xref_found == 0 ) { sprintf(buf,"\ndo_db_updates: " "EPIC plan_id %s is NO LONGER mapped for %s%s", msg_plan_id, msg_hosp, msg_pat_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); return(-1); } /* perform coverage updates */ if( strcmp(strFlag,"INS_COVERAGE") == 0) { if( upd_coverage(upd_msg) == -1 ) return(-1); NO_HANDLER=0; } /* perform patient updates */ if( strcmp(strFlag,"UPD_SUB_PATIENT") == 0) { if( upd_patient(upd_msg, fwd_msg) == -1 ) return(-1); NO_HANDLER=0; } /* perform pers_syn updates */ if( strcmp(strFlag,"INS_SUB_PERS_SYN") == 0) { PERFORM_INSERT=1; if( upd_pers_syn(upd_msg,fwd_msg) == -1 ) return(-1); NO_HANDLER=0; } if( strcmp(strFlag,"UPD_SUB_PERS_SYN") == 0) { PERFORM_INSERT=0; if( upd_pers_syn(upd_msg,fwd_msg) == -1 ) return(-1); NO_HANDLER=0; } /* perform pers_plan_rel updates */ if( strcmp(strFlag,"UPD_PERS_PLAN_REL") == 0) { PERFORM_INSERT=0; if( upd_pers_plan_rel(upd_msg,fwd_msg) == -1 ) return(-1); NO_HANDLER=0; } /* perform unlisted_payor_plan updates */ if( strcmp(strFlag,"UPD_UNL_PPL") == 0) { if( upd_unl_ppl(upd_msg,fwd_msg) == -1 ) return(-1); NO_HANDLER=0; } } /* if( intMask & 1<<(in1_no-1) ) */ } /* for(in1_no=1; in1_no<=in1_count; in1_no++) */ if( NO_HANDLER ) { sprintf(buf,"\nNo handler configured for FLAG <%s>",strFlag); error_notify(__FILE__,__LINE__,buf,NOTIFY_SERIOUS); } return(0); }/********************** end of do_db_updates ****************************/ /************************************************************************ * function: prepare_patient_medicare * args: hl7_union_t *My_upd_msg, my_fwd_msg * returns: 0 if normal completion, -1 if a fatal discovery occured. * usage info: Implements logic documented in CVG Reg_rcv.doc section 7.3 * and medicare_validation.vsd by T. Rozmyn, et al. * Relies on previously declared or popluated globals. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 20-Apr-2000 * Mod: 6.0/6.1 processing is gating with global * IGNORE_MCARE_THRU_D * * Programmer: Jeff Martin * Date: 20-Apr-2000 * Mod: * set tcl flag MEDICAxx_SEG_NO * * Programmer: Jeff Martin * Date: 29-Feb-2000 * Mod: started. medicare_validation.vsd is recommended in * order to effectively complete a review of this function. **********************************************************************/ int prepare_patient_medicare(hl7_union_t *My_upd_msg, hl7_union_t *My_fwd_msg) { /********************************************************************/ /* 7.3 Medicare Validation */ error_notify(__FILE__,__LINE__, "\tRunning prepare_patient_medicare()", NOTIFY_UPDATE); /* 2.0 Read Database Data */ if( read_from_patient() == -1) return(-1); /* 3.0 is DB mcare_eligible */ if( strcmp(db_mcare_eligible,"Y") != 0) { /* 3.1 Populate update, foward msg with mcare_eligible = 'Y' */ error_notify(__FILE__, __LINE__, "\tSetting zp2-mcare-elig to 'Y' in upd/fwd messages", NOTIFY_UPDATE); if( hl7_set(My_upd_msg,&ZP2_mcare_elig,1,0,0,0,"Y")) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.108.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZP2_mcare_elig,1,0,0,0,"Y")) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.108.0.0 in forward message\n", NOTIFY_FATAL); return(-1); } UPD_SUB_PATIENT = 1; } /* if( strcmp(db_mcare_eligible,"Y") != 0 */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tmsg_mcare_elig: '%s'\n" "\tmsg_mcare_no: '%s'\n" "\tmsg_mcare_b_elig_from_d: '%s'\n" "\tmsg_mcare_b_elig_thru_d: '%s'\n", msg_mcare_elig, msg_mcare_no, msg_mcare_b_elig_from_d, msg_mcare_b_elig_thru_d); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } /* 4.0 Do msg, DB mcare_no Differ? */ if( strlen(msg_mcare_no)) { if( strcmp(msg_mcare_no,db_mcare_no) != 0) UPD_SUB_PATIENT = 1; else { /* 4.1 Blank mcare_no from update, forward msgs */ /* (blanking excludes segments/columns from IDD sources) */ error_notify(__FILE__, __LINE__, "\tSetting zp2-mcare-pic-no to NULL in upd/fwd messages", NOTIFY_UPDATE); if( hl7_set(My_upd_msg,&ZP2_mcare_no,1,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.74.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZP2_mcare_no,1,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.74.0.0 in forward message\n", NOTIFY_FATAL); return(-1); } } /* if( strcmp(msg_mcare_no,db_mcare_no) == 0) */ } /* if( strlen(msg_mcare_no)) */ /* 5.0 Do msg, DB mcare_b_elig_from_dts Differ */ if( strlen(msg_mcare_b_elig_from_d)) { if( strcmp(msg_mcare_b_elig_from_d, db_mcare_b_elig_from_d) != 0) UPD_SUB_PATIENT = 1; else { /* 5.1 Blank mcare_b_elig_from_d from update, forward msgs */ error_notify(__FILE__, __LINE__, "\tSetting zi2-med-b-elg-dt to NULL in upd/fwd messages", NOTIFY_UPDATE); if( hl7_set(My_upd_msg,&ZI2_mcare_b_elig_from_d,in1_no,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.4.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZI2_mcare_b_elig_from_d,in1_no,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.4.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } } /* if( strcmp(msg_mcare_b_elig_from_d,db_mcare_b_elig_from_d) */ } /* if( strlen(msg_mcare_b_elig_from_d)) */ /* 6.0 Do msg, DB mcare_b_elig_thru_dts differ */ if( strlen(msg_mcare_b_elig_thru_d) && !IGNORE_MCARE_THRU_D) { if( strcmp(msg_mcare_b_elig_thru_d, db_mcare_b_elig_thru_d) != 0) UPD_SUB_PATIENT = 1; else { /* 6.1 Blank mcare_b_elig_thru_d from update, forward msgs */ error_notify(__FILE__, __LINE__, "\tSetting zi2-med-b-elg-till to NULL in upd/fwd messages", NOTIFY_UPDATE); if( hl7_set(My_upd_msg,&ZI2_mcare_b_elig_thru_d,in1_no,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.5.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZI2_mcare_b_elig_thru_d,in1_no,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.5.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } } /* if( strcmp(msg_mcare_b_elig_thru_d,db_mcare_b_elig_from_d)) */ } /* strlen(msg_mcare_b_elig_thru_d) */ if( UPD_SUB_PATIENT) error_notify(__FILE__, __LINE__,"\tUPD_SUB_PATIENT > 0",NOTIFY_UPDATE); return(0); }/*********** end of prepare_patient_medicare ****************************/ /************************************************************************* * function: prepare_patient_medicaid * args: hl7_union_t *My_upd_msg, my_fwd_msg * returns: 0 if normal completion, -1 fatal * usage info: Implements logic documented in CVG Reg_rcv.doc section 7.4 * and medicaid_validation.vsd by T. Rozmyn. * Relies on previously declared or popluated globals. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 21-Mar-2000 * Mod: * re-wrote it because it was not very readable * (sources MUST support patches in production). * * moved 'NO PROCESSING' trap (msg_pic/case_no NULL) * to top so that patient table is only hit if needed. * * Programmer: Jeff Martin * Date: 29-Feb-2000 * Mod: started. medicaid_validation.vsd is recommended in * order to effectively complete a review of this function. **********************************************************************/ int prepare_patient_medicaid(hl7_union_t *My_upd_msg, hl7_union_t *My_fwd_msg) { /********************************************************************/ /* 7.4 Medicaid Validation */ error_notify(__FILE__,__LINE__, "\tRunning prepare_patient_medicaid()", NOTIFY_UPDATE); /* log it if this function is called, but no processing will occur if (strlen(msg_mcaid_case_no) == 0 && strlen(msg_mcaid_pic_no) == 0) { error_notify(__FILE__, __LINE__, "\tprepare_patient_medicaid: No action required.", NOTIFY_UPDATE); return(0); } */ /* 2.0 Read Database Data */ if( read_from_patient() == -1) return(-1); /* 3.0 Do msg, DB mcaid_pic_nos differ ? */ if( strlen(msg_mcaid_pic_no)) { if( strcmp(msg_mcaid_pic_no,db_mcaid_pic_no) != 0) { /* 3.1 poplulate upd, fwd msg with mcaid_pic_no */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tSetting zp2-mdcaid-pic-no to %s in upd/fwd messages", msg_mcaid_pic_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } if( hl7_set(My_upd_msg,&ZP2_mcaid_pic_no,1,0,0,0,msg_mcaid_pic_no)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.28.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZP2_mcaid_pic_no,1,0,0,0,msg_mcaid_pic_no)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.28.0.0 in update message\n", NOTIFY_FATAL); return(-1); } /* 5.0 set Global flag */ UPD_SUB_PATIENT=1; } if( strcmp(msg_mcaid_pic_no,db_mcaid_pic_no) == 0) { /* 3.2 poplulate upd, fwd msg with NULL */ error_notify(__FILE__, __LINE__, "\tSetting zp2-mdcaid-pic-no to " "NULL in upd/fwd messages", NOTIFY_UPDATE); if( hl7_set(My_upd_msg,&ZP2_mcaid_pic_no,1,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.28.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZP2_mcaid_pic_no,1,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.28.0.0 in update message\n", NOTIFY_FATAL); return(-1); } } } /* if( strlen(msg_mcaid_pic_no)) */ /* 4.0 Do msg, DB mcaid_case_nos differ ? */ if( strlen(msg_mcaid_case_no)) { if( strcmp(msg_mcaid_case_no,db_mcaid_case_no) != 0) { /* 4.1 poplulate upd, fwd msg with mcaid_case_no */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tSetting zp2-mdcaid-case-no to %s in upd/fwd messages", msg_mcaid_case_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } if( hl7_set(My_upd_msg,&ZP2_mcaid_case_no,1,0,0,0,msg_mcaid_case_no)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.27.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZP2_mcaid_case_no,1,0,0,0,msg_mcaid_case_no)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.27.0.0 in update message\n", NOTIFY_FATAL); return(-1); } /* 5.0 set Global flag */ UPD_SUB_PATIENT=1; } if( strcmp(msg_mcaid_case_no,db_mcaid_case_no) == 0) { /* 4.2 poplulate upd, fwd msg with NULL */ error_notify(__FILE__, __LINE__, "\tSetting zp2-mdcaid-case-no to " "NULL in upd/fwd messages", NOTIFY_UPDATE); if( hl7_set(My_upd_msg,&ZP2_mcaid_case_no,1,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.27.0.0 in update message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&ZP2_mcaid_case_no,1,0,0,0,NULL)) { error_notify(__FILE__, __LINE__, "\nCan't set ZP2.27.0.0 in update message\n", NOTIFY_FATAL); return(-1); } } } /* if( strlen(msg_mcaid_case_no)) */ /* enable PATIENT updates if effective dates differ */ if( strncmp(msg_mcaid_1st_elig_d,db_mcaid_1st_elig_d,26) || strncmp(msg_mcaid_elig_thru_d,db_mcaid_elig_thru_d,26)) { UPD_SUB_PATIENT = 1; } if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tmsg_mcaid_pic_no: %s db_mcaid_pic_no: %s\n" "\tmsg_mcaid_case_no: %s db_mcaid_case_no: %s\n" "\tmcaid_1st_elig_d: %s db_mcaid_1st_elig_d: %s\n" "\tmcaid_elig_thru_d: %s db_mcaid_elig_thru_d: %s\n", msg_mcaid_pic_no, db_mcaid_pic_no, msg_mcaid_case_no, db_mcaid_case_no, msg_mcaid_1st_elig_d, db_mcaid_1st_elig_d, msg_mcaid_elig_thru_d, db_mcaid_elig_thru_d); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } if( UPD_SUB_PATIENT) error_notify(__FILE__, __LINE__,"\tUPD_SUB_PATIENT > 0",NOTIFY_UPDATE); return(0); }/*********** end of prepare_patient_medicaid ****************************/ /************************************************************************* * function: IsPlanCurrent() * args: none. * returns: 0 normal successful completion, * -1 a fatal error occurred. * usage info: * sets global flag 'plan_found' if message * plan_id is found in PAYOR_PLAN and current. * * sets global flag 'GENERIC_PPL' if msg_plan_id * finds payor_plan.generic_flag = 'Y'. * * sets global flag GENERIC_GENERIC_PPL if GENERIC_PPL * and the plan is in mcis_parm.'UNLISTED PPL'. * * populates host varibles from PAYOR_PLAN. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 12-Oct-2000 * Mod: added GENERIC, GENERIC/GENERIC distinctions. * * Programmer: Jeff Martin * Date: 24-Feb-2000 * Mod: Started. **************************************************************************/ int IsPlanCurrent() { /*************************************************************************/ /* thank you karen */ GENERIC_GENERIC_PPL = GENERIC_PPL = 0; if(verbose_level >= VERBOSE_MADDENING) printf( "\nSELECT 1,\n" " spons_cd,\n" " eff_from_dt,\n" " eff_thru_dt,\n" " def_addr_seq_no,\n" " last_addr_seq_no,\n" " def_group_no,\n" " def_group_name,\n" " plan_no,\n" " payor_no,\n" " uppercase(generic_flag)\n" "FROM PAYOR_PLAN\n" "WHERE hosp = '%s'\n" "AND payor_plan_no = '%d'\n" "AND eff_from_dt <= 'now'\n" "AND (eff_thru_dt = '' or eff_thru_dt >= 'now')\n", msg_hosp, payor_plan_no); EXEC SQL REPEATED SELECT 1, SQUEEZE(spons_cd), SQUEEZE(varchar(eff_from_dt)), SQUEEZE(varchar(eff_thru_dt)), def_addr_seq_no, last_addr_seq_no, def_group_no, def_group_name, plan_no, payor_no, uppercase(generic_flag) INTO :plan_found, :spons_cd, :eff_from_dt, :eff_thru_dt, :def_addr_seq_no, :last_addr_seq_no, :def_group_no, :def_group_name, :plan_no, :payor_no, :generic_flag FROM PAYOR_PLAN WHERE hosp = :msg_hosp AND payor_plan_no = :payor_plan_no AND eff_from_dt <= 'now' AND (eff_thru_dt = '' or eff_thru_dt >= 'now'); EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( !strcmp(eff_thru_dt,"") || !strlen(eff_thru_dt)) { strncpy(eff_thru_dt,REG_HIGH_DT,25); } /* find payor_plan_no GENERIC status */ if( !strcmp(generic_flag, "Y")) { def_addr_seq_no = last_addr_seq_no; if( payor_plan_no == U_UNL_PPL || payor_plan_no == H_UNL_PPL ) { GENERIC_GENERIC_PPL = 1; GENERIC_PPL = 0; } else { GENERIC_GENERIC_PPL = 0; GENERIC_PPL = 1; } } /* if( !strcmp(generic_flag, "Y")) */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tIsPlanCurrent: spons_cd: '%s'\n" "\t addr_seq_no: %d\n" "\t eff_from_dt: '%s'\n" "\t eff_thru_dt: '%s'", spons_cd, def_addr_seq_no,eff_from_dt, eff_thru_dt); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } sprintf(buf,"\tIsPlanCurrent: Yes. "); if( GENERIC_GENERIC_PPL) strcat(buf,"(Generic/Generic Plan)"); if( GENERIC_PPL) strcat(buf,"(Generic Plan)"); error_notify(__FILE__, __LINE__, buf, NOTIFY_UPDATE); return(0); break; case 100: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tIsPlanCurrent: spons_cd: '%s'\n" "\t eff_from_dt: '%s'\n" "\t eff_thru_dt: '%s'", spons_cd, eff_from_dt, eff_thru_dt); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } error_notify(__FILE__, __LINE__, "\tIsPlanCurrent: NO.",NOTIFY_UPDATE); plan_found=0; return(0); break; default: printf("\nCan't select against PAYOR_PLAN\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/********************* end of IsPlanCurrent *****************************/ /************************************************************************* * function: IsPlanMapped() * args: int ORIGINAL, 1 to use payor_plan_no * 0 to use payor_plan_no or * m60/m61_payor_plan_no * * returns: 0 normal successful completion, * -1 a fatal error occurred. * usage info: sets globals 'plan_xref_found' and 'payor_plan_no' * if message plan_id is found in PAYOR_PLAN_XREF using * logic documented in CVG Reg_rcv.doc sections 7.1/7.2. * called from: prepare_spons_coverage_flip(ORIGINAL) * coverage_validation(m60/m61) * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 19-Oct-2000 * Mod: MCIS_PARM is ignored. * 'UNLISTED PPL' plans are now permitted. * * Programmer: Jeff Martin * Date: 16-Apr-2000 * Mod: payor_plan_xref query now includes a sub query * against MCIS_PARM in order to preclude 'UNLISTED PPL'. * * Programmer: Jeff Martin * Date: 24-Feb-2000 * Mod: Started. I first tried using SQLDA. * Anyway, the where clause is always the same and the * column list is small so get all the possible columns. **************************************************************************/ int IsPlanMapped(int ORIGINAL) { EXEC SQL BEGIN DECLARE SECTION; int m60_payor_plan_no; int m61_payor_plan_no; EXEC SQL END DECLARE SECTION; /*************************************************************************/ if(verbose_level >= VERBOSE_MADDENING) printf("\nSELECT 1,\n" " payor_plan_no,\n" " m60_payor_plan_no,\n" " m61_payor_plan_no\n" "FROM PAYOR_PLAN_XREF\n" "WHERE id = '%s'\n" "AND uppercase(id_domain) = 'EPIC'\n" "AND hosp = '%s'\n", msg_plan_id, msg_hosp); EXEC SQL REPEATED SELECT 1, payor_plan_no, m60_payor_plan_no, m61_payor_plan_no, upd_dt INTO :plan_xref_found, :payor_plan_no, :m60_payor_plan_no, :m61_payor_plan_no, :upd_dt FROM PAYOR_PLAN_XREF WHERE id = :msg_plan_id AND uppercase(id_domain) = 'EPIC' AND hosp = :msg_hosp; EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode) { case 0: break; case 100: error_notify(__FILE__, __LINE__, "\tIsPlanMapped: NO.",NOTIFY_UPDATE); plan_xref_found=0; return(0); break; default: printf("\nCan't select against PAYOR_PLAN_XREF\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tIsPlanMapped: msg_spons_cd = '%s'", msg_spons_cd); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); } if(ORIGINAL) { sprintf(buf,"\tIsPlanMapped: Yes. Using payor_plan_no %d", payor_plan_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); return(0); } if( !strcmp(msg_spons_cd,"M60")) { sprintf(buf,"\tIsPlanMapped: Yes. Using m60_payor_plan_no %d", m60_payor_plan_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); payor_plan_no=orig_ppl_no=m60_payor_plan_no; return(0); } if( !strcmp(msg_spons_cd,"M61")) { sprintf(buf,"\tIsPlanMapped: Yes. Using m61_payor_plan_no %d", m61_payor_plan_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); payor_plan_no=orig_ppl_no=m61_payor_plan_no; return(0); } /* !ORIGINAL && !m60 && !m61 */ sprintf(buf,"\tIsPlanMapped: Yes. Using payor_plan_no %d", payor_plan_no); orig_ppl_no = payor_plan_no; error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); return(0); }/********************* end of IsPlanMapped *****************************/ /************************************************************************* * function: read_from_msg * args: hl7_union_t *My_upd_msg * returns: 0 if normal completion * usage info: sets globals from upd_mgs or defaults. * gets IN1/IN2/ZI2 data by segment. * * HISTORY: * -------- * Programmer: Jeff Martin * Date: 03-May-2000 * Mod: * added IN1 ins company info. * * Programmer: Jeff Martin * Date: 21-Apr-2000 * Mod: * default ssn from IN2_sub_ssn is now "000-00-0000". * * ZI2_person_no (sub person_no) is now read by in1_no. * * Programmer: Jeff Martin * Date: 13-Apr-2000 * Mode: * got rid of in1_group reporting. * * Programmer: Jeff Martin * Date: 23-Feb-2000 * Mod: started. *************************************************************************/ int read_from_msg(hl7_union_t *My_upd_msg) { /* ZI2.62 atoi conversion */ char strDef_addr_seq_no[11]; char *c, *c1, *c2, *c3, /* discrete (non-generic) char pointers */ *c4, *c5, *c6, *c7, /* for hl7_get's */ *c8, *c9, *ca, *cb, *cc, *cd, *ce, *cf, *c01, *c02, *c03, *c04, *c05, *c06, *c07, *c08, *c09, *c0a, *c0b, *c0c, *c0d, *c0e, *c0f, *c10, *c11, *c12, *c13, *c14, *c15, *c16, *c17, *c18, *c19, *c20, *c21, *c22, *c23, *c24, *c25, *c26, *c27, *c28, *c29, *c30, *c31, *c32, *c33, *c34, *c35, *c36, *c37, *c38, *c39, *c40, *c41, *c42, *c43, *c44; /************************************************************************/ c=c1=c2=c3=c4=c5=c6=c7=c8=c9=ca=cb=cc=cd = (char )'\0'; ce=cf=c01=c02=c03=c04=c05=c06=c07=c08=c09 = (char )'\0'; c0a=c0b=c0c=c0d=c0e=c0f=c10=c11=c12=c13=c14 = (char )'\0'; c15=c16=c17=c18=c19=c20=c21=c22=c23=c24=c25 = (char )'\0'; c26=c27=c28=c29=c30=c31=c32=c34=c35=c36=c37 = (char )'\0'; c38=c39=c40=c41=c42=c43=c44 = (char )'\0'; /************ is there data? ******************************************/ if(!My_upd_msg) { error_notify(__FILE__,__LINE__, "\nread_from_msg: got a NULL message", NOTIFY_FATAL); return(-1); } if(in1_no <= 0 || in1_no > 0xffff ) { sprintf(buf, "\nread_from_msg: thinks %ld is an" "\n\tunreasonable segment number", in1_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); return(-1); } /******************* get data **************************************/ sprintf(buf, "\tread_from_msg: Getting message data for IN1 segment %d", in1_no); error_notify(__FILE__, __LINE__,buf, NOTIFY_UPDATE); /* annotate debug log */ c40 = (char *) hl7_get(My_upd_msg, &MSH_sequence_id, 1, 0, NULL, 0, 0); strncpy(msg_msh_ctl_id, ( c40 ? c40 : "" ),20); /* the following sizes refer to database attributes */ /* COVERAGE/PAYOR/PAYOR_PLAN_XREF/PERS_PLAN_REL data */ c = (char *) hl7_get(My_upd_msg, &IN1_plan_id, in1_no, 0, NULL, 0, 0); strncpy(msg_plan_id, ( c ? c : "" ),24); c23 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_id, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_id, ( c23 ? c23 : "" ),10); c24 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_name, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_name, ( c24 ? c24 : "" ),40); c25 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_addr_1, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_addr_1, ( c25 ? c25 : "" ),30); c33 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_addr_2, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_addr_2, ( c33 ? c33 : "" ),30); c34 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_city, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_city, ( c34 ? c34 : "" ),17); c35 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_st, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_st, ( c35 ? c35 : "" ),2); c36 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_zip, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_zip, ( c36 ? c36 : "" ),9); c37 = (char *) hl7_get(My_upd_msg, &IN1_ins_company_country, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_company_country, ( c37 ? c37 : "" ),9); c26 = (char *) hl7_get(My_upd_msg, &IN1_ins_co_contact_per, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_co_contact_per, ( c26 ? c26 : "" ),48); c27 = (char *) hl7_get(My_upd_msg, &IN1_ins_co_contact_per, in1_no, 0, NULL, 0, 0); strncpy(msg_ins_co_contact_per, ( c27 ? c27 : "" ),40); c1 = (char *) hl7_get(My_upd_msg, &IN1_cob_cd, in1_no, 0, NULL, 0, 0); strncpy(msg_cob_cd, ( c1 ? c1 : "" ),1); c38 = (char *) hl7_get(My_upd_msg, &ZI2_mail_stop, in1_no, 0, NULL, 0, 0); strncpy(msg_zi2_mail_stop, ( c38 ? c38 : "" ),6); c2 = (char *) hl7_get(My_upd_msg, &ZI2_ip_op_de_cd, in1_no, 0, NULL, 0, 0); strncpy(msg_ip_op_de_cd, ( c2 ? c2 : "" ),3); c07 = (char *) hl7_get(My_upd_msg, &ZI2_payor_desc, in1_no, 0, NULL, 0, 0); strncpy(msg_payor_desc, ( c07 ? c07 : "" ),40); c39 = (char *) hl7_get(My_upd_msg, &ZI2_plan_name, in1_no, 0, NULL, 0, 0); strncpy(msg_zi2_plan_name, ( c39 ? c39 : "" ),40); c3 = (char *) hl7_get(My_upd_msg, &PID_patient_id, 1, 0, NULL, 0, 0); strncpy(msg_pat_id, ( c3 ? c3 : ""),63); /* parse msg_hosp, msg_pat_no */ if(strlen(msg_pat_id)){ sscanf(msg_pat_id,"%c%s",msg_hosp,msg_pat_no); sprintf(msg_hosp,"%c",msg_pat_id[0]); } else { msg_hosp[0] = (char )'\0'; msg_pat_no[0] = (char )'\0'; } c4 = (char *) hl7_get(My_upd_msg, &IN1_policy_id, in1_no, 0, NULL, 0, 0); strncpy(msg_policy_id, ( c4 ? c4 : ""),16); /* patient person_no */ c5 = (char *) hl7_get(My_upd_msg, &ZP2_person_no, 1, 0, NULL, 0, 0); msg_person_no = atoi(c5 ? c5 : ""); /* sub person_no (derived from COVERAGE or SEQUENCE.person_no and stored in ZI2.33 during VALIDATE mode */ c19 = (char *) hl7_get(My_upd_msg, &ZI2_person_no, in1_no, 0, NULL, 0, 0); msg_sub_person_no = atoi(c19 ? c19 : ""); /* pid names for zp2_stripped_name in fwd msg */ c20 = (char *) hl7_get(My_upd_msg, &PID_name_last, 1, 0, NULL, 0, 0); strncpy(pid_last_name, ( c20 ? c20 : ""),25); c21 = (char *) hl7_get(My_upd_msg, &PID_name_first, 1, 0, NULL, 0, 0); strncpy(pid_first_name, ( c21 ? c21 : ""),15); c22 = (char *) hl7_get(My_upd_msg, &PID_name_middle, 1, 0, NULL, 0, 0); strncpy(pid_middle_name, ( c22 ? c22 : ""),15); c32 = (char *) hl7_get(My_upd_msg, &PID_name_suffix, 1, 0, NULL, 0, 0); strncpy(pid_name_suffix, ( c32 ? c32 : ""),6); get_stripped_name(zp2_stripped_name, pid_last_name, pid_first_name, pid_middle_name, pid_name_suffix); /* subscriber info */ c6 = (char *) hl7_get(My_upd_msg, &IN1_eff_from_dt, in1_no, 0, NULL, 0, 0); strncpy(msg_eff_from_dt, ( c6 ? c6 : ""),25); c7 = (char *) hl7_get(My_upd_msg, &IN1_eff_thru_dt, in1_no, 0, NULL, 0, 0); strncpy(msg_eff_thru_dt, ( c7 ? c7 : ""),25); c8 = (char *) hl7_get(My_upd_msg, &ZI2_spons_cd, in1_no, 0, NULL, 0, 0); strncpy(msg_spons_cd, ( c8 ? c8 : ""),3); c30 = (char *) hl7_get(My_upd_msg, &ZP2_spec_spnsr_cd, 1, 0, NULL, 0, 0); strncpy(msg_spec_spons_cd, ( c30 ? c30 : ""),3); c9 = (char *) hl7_get(My_upd_msg, &IN1_fin_class, in1_no, 0, NULL, 0, 0); strncpy(msg_fin_class, ( c9 ? c9 : ""),4); c09 = (char *) hl7_get(My_upd_msg, &IN1_pat_rel_to_ins, in1_no, 0, NULL, 0, 0); strncpy(msg_pat_rel_to_ins, ( c09 ? c09 : ""),2); ca = (char *) hl7_get(My_upd_msg, &IN1_assign_benefits, in1_no, 0, NULL, 0, 0); strncpy(msg_assign_benefits, ( ca ? ca : ""),1); cb = (char *) hl7_get(My_upd_msg, &IN1_release_info, in1_no, 0, NULL, 0, 0); strncpy(msg_release_info, ( cb ? cb : ""),1); cc = (char *) hl7_get(My_upd_msg, &IN1_group_no, in1_no, 0, NULL, 0, 0); strncpy(msg_group_no, ( cc ? cc : ""),17); cd = (char *) hl7_get(My_upd_msg, &IN1_group_name, in1_no, 0, NULL, 0, 0); strncpy(msg_group_name, ( cd ? cd : ""),24); c04 = (char *) hl7_get(My_upd_msg, &ZVN_upd_by, 1, 0, NULL, 0, 0); strncpy(msg_upd_by, ( c04 ? c04 : ""),3); c05 = (char *) hl7_get(My_upd_msg, &ZVN_upd_area, 1, 0, NULL, 0, 0); strncpy(msg_upd_area, ( c05 ? c05 : ""),2); c06 = (char *) hl7_get(My_upd_msg, &EVN_operator_id, 1, 0, NULL, 0, 0); strncpy(msg_net_sec_upd_by, ( c06 ? c06 : ""),8); c31 = (char *) hl7_get(My_upd_msg, &EVN_timestamp, 1, 0, NULL, 0, 0); strncpy(msg_evn_timestamp, ( c31 ? c31 : ""),26); /* MEDICAID data */ c43 = (char *) hl7_get(My_upd_msg, &ZI2_mcaid_1st_elg_dt, 1, 0, NULL, 0, 0); strncpy(msg_mcaid_1st_elig_d, ( c43 ? c43 : ""),25); c44 = (char *) hl7_get(My_upd_msg, &ZI2_mcaid_elg_thru_dt, 1, 0, NULL, 0, 0); strncpy(msg_mcaid_elig_thru_d, ( c44 ? c44 : ""),25); ce = (char *) hl7_get(My_upd_msg, &ZP2_mcaid_case_no, 1, 0, NULL, 0, 0); strncpy(msg_mcaid_case_no, ( ce ? ce : ""),12); cf = (char *) hl7_get(My_upd_msg, &ZP2_mcaid_pic_no, 1, 0, NULL, 0, 0); strncpy(msg_mcaid_pic_no, ( cf ? cf : ""),14); /* MEDICARE data */ c01 = (char *) hl7_get(My_upd_msg, &ZP2_mcare_no, 1, 0, NULL, 0, 0); strncpy(msg_mcare_no, ( c01 ? c01 : ""),12); c02 = (char *) hl7_get(My_upd_msg, &ZI2_mcare_b_elig_from_d, in1_no, 0, NULL, 0, 0); strncpy(msg_mcare_b_elig_from_d, ( c02 ? c02 : ""),20); /* currently ignored via IGNORE_MCARE_THRU_D define */ c03 = (char *) hl7_get(My_upd_msg, &ZI2_mcare_b_elig_thru_d, in1_no, 0, NULL, 0, 0); strncpy(msg_mcare_b_elig_thru_d, ( c03 ? c03 : ""),20); c08 = (char *) hl7_get(My_upd_msg, &ZP2_mcare_elig, 1, 0, NULL, 0, 0); strncpy(msg_mcare_elig, ( c08 ? c08 : ""),1); /* SUBSCRIBER data */ c0a = (char *) hl7_get(My_upd_msg, &IN1_sub_last_name, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_last_name, ( c0a? c0a : ""),25); c0b = (char *) hl7_get(My_upd_msg, &IN1_sub_first_name, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_first_name, ( c0b? c0b : ""),15); c0c = (char *) hl7_get(My_upd_msg, &IN1_sub_middle_name, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_middle_name, ( c0c? c0c : ""),15); c0d = (char *) hl7_get(My_upd_msg, &IN1_sub_name_suffix, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_name_suffix, ( c0d? c0d : ""),6); /* prepareA08_reg.sc */ if( strlen(msg_sub_name_suffix) ) { switch( IsNameSuffixValid(msg_sub_name_suffix)) { case 1: break; case 0: msg_sub_name_suffix[0] = '\0'; hl7_set(My_upd_msg, &IN1_sub_name_suffix, in1_no, 0, NULL, 0, NULL); break; default: return(-1); break; /* fatal */ } } c0e = (char *) hl7_get(My_upd_msg, &IN1_sub_birth_d, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_birth_d, ( c0e? c0e : ""),20); c0f = (char *) hl7_get(My_upd_msg, &IN1_sub_sex, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_sex, ( c0f? c0f : ""),1); c10 = (char *) hl7_get(My_upd_msg, &IN1_sub_addr_1, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_addr_1, ( c10? c10 : ""),30); c11 = (char *) hl7_get(My_upd_msg, &IN1_sub_addr_2, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_addr_2, ( c11? c11 : ""),30); c12 = (char *) hl7_get(My_upd_msg, &IN1_sub_city, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_city, ( c12? c12 : ""),17); c13 = (char *) hl7_get(My_upd_msg, &IN1_sub_st, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_st, ( c13? c13 : ""),2); c14 = (char *) hl7_get(My_upd_msg, &IN1_sub_zip, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_zip, ( c14? c14 : ""),9); c15 = (char *) hl7_get(My_upd_msg, &IN1_sub_country_cd, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_country_cd, ( c15? c15 : ""),6); c16 = (char *) hl7_get(My_upd_msg, &IN2_sub_ssn, in1_no, 0, NULL, 0, 0); strncpy(msg_sub_ssn, ( c16? c16 : "000-00-0000"),11); /* prepare_msgs_reg.sc */ if( strlen(msg_sub_ssn) == 11 || strlen(msg_sub_ssn) == 9 ) { ssn_valid(msg_sub_ssn); } c17 = (char *) hl7_get(My_upd_msg, &ZP2_ssn_stat, 1, 0, NULL, 0, 0); strncpy(msg_ssn_stat, ( c17? c17 : ""),1); c18 = (char *) hl7_get(My_upd_msg, &ZI2_ssn_stat, 1, 0, NULL, 0, 0); strncpy(msg_ZI2_ssn_stat, ( c18? c18 : ""),1); msg_stripped_name[0] = '\0'; /* prepare_msgs_reg.sc */ get_stripped_name(msg_stripped_name, msg_sub_last_name, msg_sub_first_name, msg_sub_middle_name, msg_sub_name_suffix); c28 = (char *) hl7_get(My_upd_msg, &ZP2_fthr_name, 1, 0, NULL, 0, 0); strncpy(zp2_fthr_name, ( c28 ? c28 : ""),1); c29 = (char *) hl7_get(My_upd_msg, &PID_mother_name, 1, 0, NULL, 0, 0); strncpy(mother_maiden_name, ( c29 ? c29 : ""),1); /******************************************************************/ if(verbose_level >= 32768) printf("\n" "\thosp: %s\n" "\tplan_id: %s\n" "\tpat_no: %s\n" "\tpayor_desc: %s\n" "\tperson_no: %d\n" "\tsub_person_no: %d\n" "\trelease_info: %s\n" "\tPID names: %s %s %s\n" "\teff_from_dt: %s\n" "\teff_thru_dt: %s\n" "\tip_op_de_cd: %s\n" "\tspons_cd: %s\n" "\tfin_class: %s\n" "\tmcaid_pic_no: %s\n" "\tassign_benefits: %s\n" "\tpolicy_id: %s\n" "\tmcare_b_elig_from_d: %s\n" "\tmcare_b_elig_thru_d: %s\n" "\tcob_cd: %s\n" "\tmcare_no: %s\n" "\tpat_rel_to_ins: %s\n" "\tmcare_elig: %s\n" "\tsub_last_name: %s\n" "\tsub_first_name: %s\n" "\tsub_middle_name: %s\n" "\tsub_name_suffix: %s\n" "\tsub_birth_d: %s\n" "\tsub_sex: %s\n" "\tsub_ssn: %s\n" "\tsub_addr_1: %s\n" "\tsub_addr_2: %s\n" "\tsub_city: %s\n" "\tsub_st: %s\n" "\tsub_zip: %s\n" "\tsub_country_cd: %s\n" "\tsub_stripped_name: %s\n" "\tins_company_id: %s\n" "\tins_company_name: %s\n" "\tins_company_addr: %s\n" "\tins_co_contact_per: %s\n" "\tmsg_ins_co_phone_no: %s\n" "\tgroup_no: %s\n" "\tmcaid_case_no: %s\n" "\tgroup_name: %s\n" "\tupd_by: %s\n" "\tupd_area: %s\n" "\tnet_sec_upd_by: %s\n" "\tZP2_ssn_stat: %s\n" "\tZI2_ssn_stat: %s\n", msg_hosp, msg_plan_id, msg_pat_no, msg_payor_desc, msg_person_no, msg_sub_person_no, msg_release_info, pid_last_name, pid_first_name, pid_middle_name, msg_eff_from_dt, msg_eff_thru_dt, msg_ip_op_de_cd, msg_spons_cd, msg_fin_class, msg_mcaid_pic_no, msg_assign_benefits, msg_policy_id, msg_mcare_b_elig_from_d, msg_mcare_b_elig_thru_d, msg_cob_cd, msg_mcare_no, msg_pat_rel_to_ins, msg_mcare_elig, msg_sub_last_name, msg_sub_first_name, msg_sub_middle_name, msg_sub_name_suffix, msg_sub_birth_d, msg_sub_sex, msg_sub_ssn, msg_sub_addr_1, msg_sub_addr_2, msg_sub_city, msg_sub_st, msg_sub_zip, msg_sub_country_cd, msg_stripped_name, msg_ins_company_id, msg_ins_company_name, msg_ins_company_addr_1, msg_ins_co_contact_per, msg_ins_co_phone_no, msg_group_no, msg_mcaid_case_no, msg_group_name, msg_upd_by, msg_upd_area, msg_net_sec_upd_by, msg_ssn_stat, msg_ZI2_ssn_stat); return(0); }/*********************** end of read_from_msg ***************************/ /************************************************************************* * function: read_from_coverage * args: hl7_union_t * upd_msg, *fwd_msg * returns: -1 if a fatal error occurred * usage info: sets global data from COVERAGE including :coverage_found * using sql documented in CVG Reg_rcv.doc Section 7.2, Step 5.0 * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 13-Apr-2000 * Mod: incorporate changes from first code review. * save person_no in ZI2_person_no for COVERAGE updates. * * Programmer: Jeff Martin * Date: 29-Feb-2000 * Mod: started. **************************************************************************/ int read_from_coverage(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { char strPerson_no[11]; /**************************************************************************/ if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning read_from_coverage()", NOTIFY_UPDATE); if( verbose_level >= VERBOSE_MADDENING) printf("\nSELECT 1,\n" " payor_plan_no,\n" " person_no,\n" " pat_rel_to_ins,\n" " assign_benefits,\n" " release_info,\n" " eff_from_dt,\n" " eff_thru_dt,\n" " group_no,\n" " group_name,\n" " upd_dt\n" "FROM COVERAGE\n" "WHERE ip_op_de_cd = '%s'\n" "AND hosp = '%s'\n" "AND pat_no = '%s'\n" "AND cob_cd = '%s'\n" "AND eff_thru_dt = '%s'\n" "ORDER BY upd_dt DESC\n\n", msg_ip_op_de_cd, msg_hosp, msg_pat_no, msg_cob_cd, REG_HIGH_DT); EXEC SQL REPEATED SELECT 1, payor_plan_no, person_no, SQUEEZE(pat_rel_to_ins), SQUEEZE(assign_benefits), SQUEEZE(release_info), eff_from_dt, eff_thru_dt, SQUEEZE(group_no), SQUEEZE(group_name), upd_dt INTO :coverage_found, :db_cvg_payor_plan_no, :db_sub_person_no, :db_pat_rel_to_ins, :db_assign_benefits, :db_release_info, :db_eff_from_dt, :db_eff_thru_dt, :db_group_no, :db_group_name, :db_upd_dt FROM COVERAGE WHERE ip_op_de_cd = :msg_ip_op_de_cd AND hosp = :msg_hosp AND pat_no = :msg_pat_no AND cob_cd = :msg_cob_cd AND eff_thru_dt = :REG_HIGH_DT ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tCOVERAGE query returned payor_plan_no %d,\n" "\tperson_no %d, pat_rel_to_ins '%s' for %s%s", db_cvg_payor_plan_no, db_sub_person_no, db_pat_rel_to_ins,msg_hosp,msg_pat_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } /* store db_sub_person_no for COVERAGE updates */ sprintf(strPerson_no,"%d",db_sub_person_no); if( hl7_set(upd_msg,&ZI2_person_no,in1_no,0,0,0, strPerson_no)) { error_notify(__FILE__, __LINE__,"read_from_coverage: " "Can't set zi2-person-no" ,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_person_no,in1_no,0,0,0, strPerson_no)) { error_notify(__FILE__, __LINE__,"read_from_coverage: " "Can't set zi2-person-no" ,NOTIFY_FATAL); return(-1); } break; case 100: error_notify(__FILE__,__LINE__, "\tCOVERAGE query returned no rows", NOTIFY_UPDATE); strcpy(db_pat_rel_to_ins, ""); strcpy(db_assign_benefits,""); strcpy(db_release_info, ""); strcpy(db_eff_from_dt, ""); strcpy(db_eff_thru_dt, ""); strcpy(db_group_no, ""); strcpy(db_group_name, ""); coverage_found =0; db_sub_person_no =0; db_cvg_payor_plan_no =0; break; default: printf("\nCan't select against COVERAGE\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/***************** end of read_from_coverage ***************************/ /************************************************************************* * function: read_from_pers_plan_rel * args: none. * returns: -1 if a fatal error occurred * usage info: sets global data from PERS_PLAN_REL using SQL documented * in CVG Reg_rcv.doc Section 7.2, Step 6.0 * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 13-Mar-2000 * Mod: incorporate changes from first code review. * * Programmer: Jeff Martin * Date: 01-Mar-2000 * Mod: started. **************************************************************************/ int read_from_pers_plan_rel() { if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning read_from_pers_plan_rel()",NOTIFY_UPDATE); if( verbose_level >= VERBOSE_MADDENING) printf("\nSELECT 1,\n" " ins_policy_id,\n" " eff_from_dt,\n" " entry_dt,\n" " entry_by,\n" " upd_dt\n" " FROM PERS_PLAN_REL\n" " WHERE person_no = %d\n" " AND payor_plan_no = %d\n" " ORDER BY upd_dt DESC\n\n", db_sub_person_no, db_cvg_payor_plan_no); EXEC SQL REPEATED SELECT 1, SQUEEZE(ins_policy_id), eff_from_dt, eff_thru_dt, SQUEEZE(varchar(entry_dt)), SQUEEZE(entry_by), upd_dt INTO :pers_plan_rel_found, :db_ins_policy_id, :db_ppr_eff_from_dt, :db_ppr_first_entry_dt, :db_ppr_first_entry_by, :db_upd_dt FROM PERS_PLAN_REL WHERE person_no = :db_sub_person_no AND payor_plan_no = :db_cvg_payor_plan_no ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tPERS_PLAN_REL query returned ins_policy_id: %s", db_ins_policy_id); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } break; case 100: if( verbose_level >= VERBOSE_MADDENING) { error_notify(__FILE__,__LINE__, "\tPERS_PLAN_REL query returned no rows", NOTIFY_UPDATE); } pers_plan_rel_found=0; strcpy(db_ins_policy_id,""); break; default: printf("\nCan't select against PERS_PLAN_REL\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/************ end of read_from_pers_plan_rel ***************************/ /************************************************************************* * function: read_from_patient * args: none. * returns: -1 if a fatal error occurred. * usage info: sets global data from PATIENT using SQL documented * in CVG Reg_rcv.doc Section 7.2-7.3, Step 2.0 * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 29-Feb-2000 * Mod: started. **************************************************************************/ int read_from_patient() { EXEC SQL BEGIN DECLARE SECTION; int from_years; /* DATE_PART decodes */ int thru_years; int from_months; int thru_months; int from_days; int thru_days; int thru_hours; int thru_minutes; int thru_seconds; int mcaid_from_years; int mcaid_thru_years; int mcaid_from_months; int mcaid_thru_months; int mcaid_from_days; int mcaid_thru_days; EXEC SQL END DECLARE SECTION; error_notify(__FILE__,__LINE__, "\tRunning read_from_patient()", NOTIFY_UPDATE); if( verbose_level >= VERBOSE_MADDENING) printf("\nSELECT mcaid_pic_no,\n" " mcaid_case_no,\n" " mcare_no,\n" " mcare_eligible,\n" " mcare_b_elig_from_d,\n" " mcare_b_elig_thru_d\n" "FROM PATIENT\n" "WHERE hosp = '%s'\n" "AND pat_no = '%s'\n\n", msg_hosp, msg_pat_no); EXEC SQL REPEATED SELECT SQUEEZE(mcaid_pic_no), SQUEEZE(mcaid_case_no), SQUEEZE(mcare_no), SQUEEZE(UPPERCASE(mcare_eligible)), DATE_PART('years', mcare_b_elig_from_d), DATE_PART('months', mcare_b_elig_from_d), DATE_PART('days', mcare_b_elig_from_d), DATE_PART('years', mcare_b_elig_thru_d), DATE_PART('months', mcare_b_elig_thru_d), DATE_PART('days', mcare_b_elig_thru_d), DATE_PART('years', mcaid_1st_elig_d), DATE_PART('months', mcaid_1st_elig_d), DATE_PART('days', mcaid_1st_elig_d), DATE_PART('years', mcaid_elig_thru_d), DATE_PART('months', mcaid_elig_thru_d), DATE_PART('days', mcaid_elig_thru_d) INTO :db_mcaid_pic_no, :db_mcaid_case_no, :db_mcare_no, :db_mcare_eligible, :from_years,:from_months,:from_days, :thru_years,:thru_months,:thru_days, :mcaid_from_years,:mcaid_from_months, :mcaid_from_days, :mcaid_thru_years,:mcaid_thru_months, :mcaid_thru_days FROM PATIENT WHERE hosp = :msg_hosp AND pat_no = :msg_pat_no; EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode) { case 0: sprintf(db_mcare_b_elig_from_d,"%04d%02d%02d", from_years,from_months,from_days); sprintf(db_mcare_b_elig_thru_d,"%04d%02d%02d", thru_years,thru_months,thru_days); if( strcmp(db_mcare_b_elig_from_d,"00000000")==0) strcpy(db_mcare_b_elig_from_d,""); if( strcmp(db_mcare_b_elig_thru_d,"00000000")==0) strcpy(db_mcare_b_elig_thru_d,""); sprintf(db_mcaid_1st_elig_d,"%04d%02d%02d", mcaid_from_years,mcaid_from_months, mcaid_from_days); sprintf(db_mcaid_elig_thru_d,"%04d%02d%02d", mcaid_thru_years,mcaid_thru_months, mcaid_thru_days); if( strcmp(db_mcaid_1st_elig_d,"00000000")==0) strcpy(db_mcaid_1st_elig_d,""); if( strcmp(db_mcaid_elig_thru_d,"00000000")==0) strcpy(db_mcaid_elig_thru_d,""); if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf, "\tPATIENT query returned mcare_eligible: '%s'\n" "\t mcare_no: '%s'\n" "\t mcare_b_elig_from_d: '%s'\n" "\t mcare_b_elig_thru_d: '%s'\n" "\t mcaid_1st_elig_d: '%s'\n" "\t mcaid_elig_thru_d: '%s'\n" "\t mcaid_pic_no: '%s'\n" "\t mcaid_case_no: '%s'", db_mcare_eligible, db_mcare_no, db_mcare_b_elig_from_d, db_mcare_b_elig_thru_d, db_mcaid_1st_elig_d, db_mcaid_elig_thru_d, db_mcaid_pic_no, db_mcaid_case_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } break; case 100: if( verbose_level >= VERBOSE_MADDENING) { error_notify(__FILE__,__LINE__, "\tPATIENT query returned no rows", NOTIFY_UPDATE); } strcpy(db_mcaid_pic_no,""); strcpy(db_mcaid_case_no,""); strcpy(db_mcare_eligible,""); strcpy(db_mcare_b_elig_from_d,""); strcpy(db_mcare_b_elig_thru_d,""); break; default: printf("\nCan't select against PATIENT\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/***************** end of read_from_patient ***************************/ /************************************************************************* * function: set_ins_company_addr * args: * returns: -1 if a fatal error occurred or 0. * usage info: sets insurance company address * info from PAYOR_N and CLAIM_ADDRESS * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 16-Oct-2000 * Mod: started. **************************************************************************/ int set_ins_company_addr(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { char strPlan_no[11] = (char )'\0'; char strDef_addr_seq_no[11] = (char )'\0'; char strPayor_no[11] = (char )'\0'; /**************************************************************************/ ins_company_zip[0] = (char )'\0'; payor_desc[0] = (char )'\0'; if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning set_ins_company_addr()", NOTIFY_UPDATE); if( verbose_level >= VERBOSE_MADDENING ) printf("\n\tSELECT\n" "\t addr_1,\n" "\t addr_2,\n" "\t city,\n" "\t st,\n" "\t zip,\n" "\t zip_suffix,\n" "\t foreign_zip,\n" "\t country_cd,\n" "\t upd_dt\n" "\tFROM CLAIM_ADDRESS\n" "\tWHERE payor_plan_no = %d\n" "\tAND addr_seq_no = %d\n" "\tORDER BY upd_dt DESC;\n", payor_plan_no, def_addr_seq_no); EXEC SQL REPEATED SELECT SQUEEZE(addr_1), SQUEEZE(addr_2), SQUEEZE(city), SQUEEZE(st), SQUEEZE(zip), SQUEEZE(zip_suffix), SQUEEZE(foreign_zip), SQUEEZE(country_cd), upd_dt INTO :addr_1, :addr_2, :city, :st, :zip, :zip_suffix, :foreign_zip, :country_cd, :upd_dt FROM CLAIM_ADDRESS WHERE payor_plan_no = :payor_plan_no AND addr_seq_no = :def_addr_seq_no ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( strlen(foreign_zip) && strcmp(foreign_zip,"") && !strcmp(country_cd,"USA")) { sprintf(ins_company_zip,"%s",foreign_zip); break; } if( strlen(zip_suffix) && strcmp(zip_suffix,"")) { sprintf(ins_company_zip,"%s-%s",zip,zip_suffix); } else sprintf(ins_company_zip,"%s",zip); if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tgot: %s\n\t%s %s %s", addr_1,city,st,ins_company_zip); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } break; case 100: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tCLAIM_ADDRESS query found no rows for %d %d", payor_plan_no, def_addr_seq_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } ins_company_zip[0] = (char )'\0'; break; default: printf("\nset_ins_company_addr: " "Can't select against CLAIM_ADDRESS\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ /* get payor_desc from PAYOR_N.PAYOR_NO */ if( verbose_level >= VERBOSE_MADDENING) printf("\n\tSELECT\n" "\t payor_desc,\n" "\t upd_dt\n" "\tFROM PAYOR_N\n" "\tWHERE payor_no = %d\n" "\tORDER BY upd_dt DESC;\n", payor_no); EXEC SQL REPEATED SELECT payor_desc, upd_dt INTO :payor_desc, :upd_dt FROM PAYOR_N WHERE payor_no = :payor_no ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tgot: %s", payor_desc); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } break; case 100: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tPAYOR_N query found no rows for %d", payor_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } payor_desc[0] = (char )'\0'; break; default: printf("\nset_ins_company_addr: Can't select against PAYOR_N\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ /* set message values */ if( hl7_set(fwd_msg,&IN1_ins_company_addr_1,in1_no,0,0,0, addr_1 )) { sprintf(buf,"\nCan't set IN1.5.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_addr_2,in1_no,0,0,0, addr_2)) { sprintf(buf,"\nCan't set IN1.5.1.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_city,in1_no,0,0,0, city )) { sprintf(buf,"\nCan't set IN1.5.2.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_st,in1_no,0,0,0, st )) { sprintf(buf,"\nCan't set IN1.5.3.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_zip,in1_no,0,0,0, ins_company_zip)) { sprintf(buf,"\nCan't set IN1.5.4.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_country,in1_no,0,0,0, country_cd )) { sprintf(buf,"\nCan't set IN1.5.5.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* in1_ins_company_name */ if( strlen(payor_desc) && strcmp(payor_desc,"")) { if( hl7_set(fwd_msg,&IN1_ins_company_name,in1_no,0,0,0, payor_desc )) { sprintf(buf,"\nCan't set IN1.4.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_payor_desc,in1_no,0,0,0, payor_desc )) { sprintf(buf,"\nCan't set ZI2.18 %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_plan_name,in1_no,0,0,0, payor_desc)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set ZI2.65.4.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } } /* payor_desc */ /* in1_ins_plan_no */ sprintf(strPlan_no,"%d",plan_no); /* NON_GENERIC plan_no */ if( hl7_set(fwd_msg,&IN1_plan_id,in1_no,0,0,0, strPlan_no)) { sprintf(buf,"\nCan't set IN1.2.0.0 segment %d fwd_msg\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2_addr_seq_no */ sprintf(strDef_addr_seq_no,"%d",def_addr_seq_no); if( hl7_set(fwd_msg,&ZI2_addr_seq_no,in1_no,0,0,0, strDef_addr_seq_no)) { sprintf(buf,"\nCan't set ZI2.62.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* in1_ins_company_id */ sprintf(strPayor_no,"%d",payor_no); if( hl7_set(fwd_msg,&IN1_ins_company_id,in1_no,0,0,0, strPayor_no)) { sprintf(buf,"\nCan't set IN1.3.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } return(0); }/*************** end of set_ins_company_addr ******************************/ /************************************************************************* * function: upd_coverage * args: none. * returns: -1 if a fatal error occurred. * usage info: end_dates (updates) current OP coverage of the same * filing order and inserts a new coverage record. * * relies on previously declared globals. * * calls stored procedure regprod.upd_coverage. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 13-Apr-2000 * Mod: incorporate changes from first code review. * * Programmer: Jeff Martin * Date: 02-Mar-2000 * Mod: started, using regprod.upd_coverage method * 'ENDINS' to perform remote end-dating. **************************************************************************/ int upd_coverage(hl7_union_t *upd_msg) { EXEC SQL BEGIN DECLARE SECTION; int row_count; int old_plan_no; /* upd_coverage args */ char old_pat_no[8]; char upd_cd[9]; char area_code_2[4]; char ph_prefix_2[4]; char ph_suffix_2[4]; char ph_ext_2[4]; int My_plan_no; char My_eff_from_dt[26]; char My_upd_dt[26]; EXEC SQL END DECLARE SECTION; char *strAddr_seq_no; /********************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning upd_coverage()",NOTIFY_UPDATE); /* init default values */ strcpy(upd_cd,"ENDINS"); /* upd_coverage command */ strcpy(old_pat_no,""); old_plan_no=0; strcpy(area_code_2,""); strcpy(ph_prefix_2,""); strcpy(ph_suffix_2,""); strcpy(ph_ext_2,""); My_plan_no=0; strcpy(My_eff_from_dt,"now"); strcpy(My_upd_dt,"now"); if( GENERIC_PPL + GENERIC_GENERIC_PPL > 0 ) { payor_plan_no = (strcmp(msg_hosp,"H") ? U_UNL_PPL : H_UNL_PPL); /* unlisted addr_seq_no */ strAddr_seq_no = (char *) hl7_get(upd_msg, &ZI2_addr_seq_no, in1_no, 0, NULL, 0, 0); def_addr_seq_no = atoi(strAddr_seq_no ? strAddr_seq_no :"" ); } /* call stored DBPROC upd_coverage to end_date/insert current coverage */ if(verbose_level >= VERBOSE_MADDENING) printf("\nEXECUTE PROCEDURE upd_coverage(\n" " old_pat_no = %s,\n" " old_plan_no = %d,\n" " upd_cd = %s,\n" " area_code_2 = %s,\n" " ph_prefix_2 = %s,\n" " ph_suffix_2 = %s,\n" " ph_ext_2 = %s,\n" " hosp = %s,\n" " pat_no = %s,\n" " person_no = %d,\n" " pat_rel_to_ins = %s,\n" " plan_no = %d,\n" " payor_plan_no = %d,\n" " addr_seq_no = %d,\n" " eff_from_dt = %s,\n" " eff_thru_dt = %s,\n" " assign_benefits = %s,\n" " ip_op_de_cd = %s,\n" " cob_cd = %s,\n" " release_info = %s,\n" " upd_dt = %s,\n" " upd_by = %s,\n" " upd_area = %s,\n" " net_sec_upd_by = %s,\n" " group_no = %s,\n" " group_name = %s)\n" " INTO :row_count\n", old_pat_no, old_plan_no, upd_cd, area_code_2, ph_prefix_2, ph_suffix_2, ph_ext_2, msg_hosp, msg_pat_no, msg_sub_person_no, msg_pat_rel_to_ins, My_plan_no, payor_plan_no, def_addr_seq_no, My_eff_from_dt, REG_HIGH_DT, msg_assign_benefits, msg_ip_op_de_cd, msg_cob_cd, msg_release_info, My_upd_dt, msg_upd_by, msg_upd_area, msg_net_sec_upd_by, msg_group_no, msg_group_name); EXEC SQL EXECUTE PROCEDURE upd_coverage( old_pat_no = :old_pat_no, old_plan_no = :old_plan_no, upd_cd = :upd_cd, area_code_2 = :area_code_2, ph_prefix_2 = :ph_prefix_2, ph_suffix_2 = :ph_suffix_2, ph_ext_2 = :ph_ext_2, hosp = :msg_hosp, pat_no = :msg_pat_no, person_no = :msg_sub_person_no, pat_rel_to_ins = :msg_pat_rel_to_ins, plan_no = :My_plan_no, payor_plan_no = :payor_plan_no, addr_seq_no = :def_addr_seq_no, eff_from_dt = :My_eff_from_dt, eff_thru_dt = :REG_HIGH_DT, assign_benefits = :msg_assign_benefits, ip_op_de_cd = :msg_ip_op_de_cd, cob_cd = :msg_cob_cd, release_info = :msg_release_info, upd_dt = :My_upd_dt, upd_by = :msg_upd_by, upd_area = :msg_upd_area, net_sec_upd_by = :msg_net_sec_upd_by, group_no = :msg_group_no, group_name = :msg_group_name ) INTO :row_count; switch(sqlca.sqlcode){ case 0: if(row_count >= 1) { error_notify(__FILE__,__LINE__, "\tupd_coverage: Successful.",NOTIFY_UPDATE); } else { sprintf(buf,"upd_coverage: BAD RETURN CODE: %d",row_count); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); return(-1); } break; default: /* sometimes DUP KEY (-30210) on UPDATE (ENDINS) or INSERT */ error_notify(__FILE__,__LINE__, "prepare_coverage: DBPROC upd_coverage failed." ,NOTIFY_FATAL); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/*************** end of upd_coverage ***********************************/ /************************************************************************* * function: upd_patient * args: hl7_union_t *upd_msg, *fwd_msg * returns: -1 if a fatal error occured. * usage info: updates or inserts into the PATIENT table. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 17-May-2000 * Mod: started. **************************************************************************/ int upd_patient(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning upd_patient()", NOTIFY_UPDATE); /* implement medicaid eff date rules */ if( fix_medicaid_dates(upd_msg,fwd_msg) == -1 ) return(-1); /* attempt an update using local sql or on insert using stored dbproc */ switch( do_patient_update() ) { case 0: return(0); break; case 100: if( do_patient_insert() == -1 ) return(-1); break; default: return(-1); break; }/* switch */ return(0); }/******************** end of upd_patient ********************************/ /************************************************************************* * function: upd_pers_plan_rel * args: hl7_union_t *upd_msg, *fwd_msg * returns: -1 if a fatal error occurred * usage info: Insert a new record if the subscriber changes * and the current coverage has a policy id. * * The existing PERS_PLAN_REL record is updated if * the policy_id changes but the payor_plan_no and * person_no remain unchanged. * * relies on previously declared globals. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 04-Mar-2000 * Mod: implement new insert/update rules * * Programmer: Jeff Martin * Date: 02-Mar-2000 * Mod: started. **************************************************************************/ int upd_pers_plan_rel(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { EXEC SQL BEGIN DECLARE SECTION; int row_count; int old_plan_no; char upd_cd[9]; char My_upd_dt[4]; EXEC SQL END DECLARE SECTION; error_notify(__FILE__,__LINE__, "\tRunning upd_pers_plan_rel()",NOTIFY_UPDATE); /* get db_cvg_payor_plan_no */ if( read_from_coverage(upd_msg, fwd_msg) == -1 ) return(-1); if( GENERIC_PPL + GENERIC_GENERIC_PPL > 0 ) { payor_plan_no = (strcmp(msg_hosp,"H") ? U_UNL_PPL : H_UNL_PPL); } /* Step 8.2, Scenario 3 */ if( strcmp(msg_policy_id,db_ins_policy_id) && strlen(msg_policy_id) && db_cvg_payor_plan_no == payor_plan_no ) { if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tCHANGE_SUB: %d\n" "\tmsg_policy_id: '%s' db_ins_policy_id: '%s'\n" "\tdb_cvg_payor_plan_no: '%d' payor_plan_no '%d'", CHANGE_SUB, msg_policy_id,db_ins_policy_id, db_cvg_payor_plan_no,payor_plan_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } if( verbose_level >= VERBOSE_MADDENING) printf("REPEATED UPDATE PERS_PLAN_REL\n" "SET ins_policy_id = '%s'\n" "WHERE person_no = %d\n" "AND payor_plan_no = %d\n", msg_policy_id, msg_sub_person_no, payor_plan_no); EXEC SQL REPEATED UPDATE PERS_PLAN_REL SET ins_policy_id = :msg_policy_id WHERE person_no = :msg_sub_person_no AND payor_plan_no = :payor_plan_no; switch(sqlca.sqlcode) { case 0: error_notify(__FILE__,__LINE__, "\tupd_pers_plan_rel: Successful.",NOTIFY_UPDATE); return(0); break; case 100: sprintf(buf,"\tTarget for PERS_PLAN_REL update not found:\n" "\t(%d %d)", msg_sub_person_no, payor_plan_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); break; case -30210: /* DUP KEY on UPDATE */ sprintf(buf,"PERS_PLAN_REL update creates DUP KEY\n" "policy_id: %s, person_no: %d, payor_plan_no: %d\n", msg_policy_id, msg_sub_person_no, payor_plan_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); return(0); break; default: printf("\nCan't update PERS_PLAN_REL\n" "policy_id: %s, person_no: %d, payor_plan_no: %d\n", msg_policy_id, msg_sub_person_no, payor_plan_no); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ } /* Step 8.2, Scenario 3 */ /* init default values */ old_plan_no=0; strcpy(My_upd_dt,"now"); strcpy(db_ppr_first_entry_dt,"now"); strcpy(db_ppr_first_entry_by,msg_upd_by); upd_cd[0] = '\0'; strcpy(upd_cd,"INS"); sprintf(buf,"\tupd_pers_plan_rel: upd_cd = %s",upd_cd); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); /* call stored DBPROC upd_pers_plan_rel */ if(verbose_level >= VERBOSE_MADDENING) printf("\nEXECUTE PROCEDURE upd_pers_plan_rel(\n" " old_plan_no = %d,\n" " upd_cd = %s,\n" " payor_plan_no = %d,\n" " plan_no = %d,\n" " person_no = %d,\n" " ins_policy_id = %s,\n" " eff_from_dt = %s,\n" " eff_thru_dt = %s,\n" " entry_dt = %s,\n" " entry_by = %s,\n" " upd_dt = %s,\n" " upd_by = %s,\n" " upd_area = %s,\n" " net_sec_upd_by = %s,\n" " ) INTO :row_count\n", old_plan_no, upd_cd, payor_plan_no, cov_default_plan_no, msg_sub_person_no, msg_policy_id, "now", REG_HIGH_DT, db_ppr_first_entry_dt, db_ppr_first_entry_by, My_upd_dt, msg_upd_by, msg_upd_area, msg_net_sec_upd_by); EXEC SQL EXECUTE PROCEDURE upd_pers_plan_rel ( old_plan_no = :old_plan_no, upd_cd = :upd_cd, payor_plan_no = :payor_plan_no, plan_no = :cov_default_plan_no, person_no = :msg_sub_person_no, ins_policy_id = :msg_policy_id, eff_from_dt = 'now', eff_thru_dt = :REG_HIGH_DT, entry_dt = :db_ppr_first_entry_dt, entry_by = :db_ppr_first_entry_by, upd_dt = :My_upd_dt, upd_by = :msg_upd_by, upd_area = :msg_upd_area, net_sec_upd_by = :msg_net_sec_upd_by ) INTO :row_count; switch(sqlca.sqlcode){ case 0: if(row_count >= 1) { error_notify(__FILE__,__LINE__, "\tupd_pers_plan_rel: Successful.",NOTIFY_UPDATE); } else { sprintf(buf,"upd_pers_plan_rel: BAD RETURN CODE: %d",row_count); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); return(-1); } break; case -30210: /* DUP KEY */ sprintf(buf,"PERS_PLAN_REL %d already exists for %d\n", payor_plan_no, msg_sub_person_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); return(0); break; default: error_notify(__FILE__,__LINE__, "Can't call DBPROC upd_pers_plan_rel",NOTIFY_FATAL); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/*************** end of upd_pers_plan_rel ****************************/ /************************************************************************* * function: upd_pers_syn * args: hl7_union_t *upd_msg, *fwd_msg * returns: -1 if a fatal error occurred. * usage info: sets existing U/H/P pers_syn records to non-current. * inserts new rows into pers_syn. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 29-Apr-2000 * Mod: started. **************************************************************************/ int upd_pers_syn(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning upd_pers_syn()", NOTIFY_UPDATE); /* used for row_id tie breaker */ srand( time(NULL) ); /* end date prior current records to noncurrent for updates */ if( !PERFORM_INSERT ) { switch( end_date_HUP_pers_syn("H")) { case -1: return(-1); /* fatal */ case 0: break; /* no person */ case 1: if(do_pers_syn_insert(upd_msg,fwd_msg)== -1) /* end date OK */ return(-1); default: break; } switch( end_date_HUP_pers_syn("U")) { case -1: return(-1); /* fatal */ case 0: break; /* no person */ case 1: if(do_pers_syn_insert(upd_msg,fwd_msg)== -1) /* end date OK */ return(-1); default: break; } switch( end_date_HUP_pers_syn("P")) { case -1: return(-1); /* fatal */ case 0: break; case 1: if(do_pers_syn_insert(upd_msg,fwd_msg)== -1) /* end date OK */ return(-1); default: break; } } /* if( !PERFORM_INSERT ) */ /* new person_no insert */ if( PERFORM_INSERT ) { /* store insert values */ strcpy(msg_sub_hosp," "); strcpy(msg_sub_pat_no," " ); strcpy(msg_sub_pat_no_dsp," "); intPerson_no = msg_sub_person_no; if (do_pers_syn_insert(upd_msg, fwd_msg) == -1) return(-1); } /* if( PERFORM_INSERT ) */ return(0); }/******************* end of upd_pers_syn *******************************/ /************************************************************************* * function: upd_seq_no * args: hl7_union_t *upd_msg, *fwd_msg * returns: -1 if a fatal error occured. * usage info: gets a person_no assigned from SEQUENCE table * using stored dbproc 'upd_seq_no' and stores * it in ZI2_person_no (ZI2.33) * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 15-May-2000 * Mod: started. *************************************************************************/ int upd_seq_no( hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { EXEC SQL BEGIN DECLARE SECTION; char id[20]; EXEC SQL END DECLARE SECTION; char strPerson_no[11]; /************************************************************************/ strcpy(id,"person_no"); EXEC SQL EXECUTE PROCEDURE upd_seq_no(id=:id) INTO :intPerson_no; EXEC SQL COMMIT; switch(sqlca.sqlcode){ case 0: sprintf(buf,"\tupd_seq_no assigned person_no: %d",intPerson_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); /* store new person_no for COVERAGE updates */ sprintf(strPerson_no,"%d",intPerson_no); if( hl7_set(upd_msg,&ZI2_person_no,in1_no,0,0,0, strPerson_no)) { error_notify(__FILE__, __LINE__,"upd_pers_syn: " "Can't set zi2-person-no" ,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_person_no,in1_no,0,0,0, strPerson_no)) { error_notify(__FILE__, __LINE__,"upd_pers_syn: " "Can't set zi2-person-no" ,NOTIFY_FATAL); return(-1); } break; default: printf("\nupd_seq_no can't assign a person_no\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); } return(0); } /*********************************************************************/ /************************************************************************* * function: end_date_HUP_pers_syn * args: gets indentifiers associated with subscriber person_no * and supplied identifier type (HUP) from PER_SYN and makes * them non-current. * returns: -1 if a fatal error occurred. * usage info: This function is currently called from upd_pers_syn * if the previous message validation pass set TCL flag * 'UPD_SUB_PERS_SYN'. upd_pers_syn then calls this * function 3 times to end date H, U and non-pat (P) * records (the H/U processing is combined here). * upd_pers_syn then enables a PERS_SYN insert for each. * * * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 19-Sep-2000 * Mod: don't populate msg_ZI2_ssn_stat from the database. * * Programmer: Jeff Martin * Date: 29-Apr-2000 * Mod: translated from cur_to_not.GUARHUP processing. *************************************************************************/ int end_date_HUP_pers_syn(char *HUP){ EXEC SQL BEGIN DECLARE SECTION; char HUP_pat_no[8]; char HUP_pat_no_dsp[11]; char HUP_hosp[2]; int sub_non_patient; EXEC SQL END DECLARE SECTION; /***********************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning end_date_HUP_pers_syn()", NOTIFY_UPDATE); if( strcmp(HUP,"H") && strcmp(HUP,"U") && strcmp(HUP,"P")) { sprintf(buf,"\nidentifer type '%s' is unknown.\n",HUP); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); return(-1); } /***********************************************************************/ /* end date H or U patients */ if( !strcmp(HUP,"H") || !strcmp(HUP,"U")) { strcpy(HUP_hosp,HUP); EXEC SQL REPEATED SELECT pat_no, pat_no_dsp, race, microfiche_rec, soundex_cd, stripped_name, bypass_rs, upd_dt INTO :HUP_pat_no, :HUP_pat_no_dsp, :race, :microfiche_rec, :soundex_cd, :msg_stripped_name, :bypass_rs, :db_upd_dt FROM pers_syn WHERE person_no = :msg_sub_person_no AND bypass_rs = 'N' AND current_name = 'Y' AND hosp = :HUP_hosp AND last_name not like 'AACANC%' ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode) { case 0: sprintf(buf,"\tFound %s idr's for subscriber person_no %d", HUP_hosp, msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); /* save H/U pat_no for NON-PAT updates */ if( strcmp(HUP_hosp,"H")) { hmc_pat_no[0]='\0'; strcpy(hmc_pat_no,HUP_pat_no); } if( strcmp(HUP_hosp,"U")) { uwmc_pat_no[0]='\0'; strcpy(uwmc_pat_no,HUP_pat_no); } /* store insert values */ strcpy(msg_sub_hosp,HUP_hosp); strcpy(msg_sub_pat_no,HUP_pat_no); strcpy(msg_sub_pat_no_dsp,HUP_pat_no_dsp); intPerson_no = msg_sub_person_no; break; case 100: sprintf(buf,"\tNo %s pat_no found for subscriber person_no %d", HUP_hosp, msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); return(0); break; default: printf("\nCan't select against PERS_SYN\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ /* end-date H/U subscriber pers_syn records */ /* (previous select found a row) */ EXEC SQL REPEATED UPDATE pers_syn SET current_name = 'N' WHERE person_no = :msg_sub_person_no AND hosp = :HUP_hosp AND pat_no = :HUP_pat_no AND stripped_name not like 'AACANC%'; switch(sqlca.sqlcode) { case 0: sprintf(buf,"\tEnded subscriber %s%s pers_syn records " "for person_no %d", HUP_hosp, (strcmp(HUP_hosp,"H") ? "WMC" : "MC"), msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); return(1); /* enable pers_syn insert */ break; case 100: sprintf(buf,"\tNo subscriber %s%s pers_syn records " "ended for person_no %d", HUP_hosp, (strcmp(HUP_hosp,"H") ? "WMC" : "MC"), msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); return(0); break; default: printf("\nCan't update PERS_SYN\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ } /* if( !strcmp(HUP,"H") || !strcmp(HUP,"U")) */ /* ** Is there a non-patient person record? Do not want to restrict ** by searching for bypass_rs = 'N' */ if( !strcmp(HUP,"P")) { sub_non_patient=0; EXEC SQL REPEATED SELECT sub_non_patient=1, race, microfiche_rec, bypass_rs, soundex_cd, stripped_name, upd_dt INTO :sub_non_patient, :race, :microfiche_rec, :bypass_rs, :soundex_cd, :msg_stripped_name, :db_upd_dt FROM pers_syn WHERE person_no = :msg_sub_person_no AND current_name = 'Y' AND (hosp = ' ' OR hosp is null) AND (pat_no = ' ' OR pat_no is null) AND last_name not like 'AACANC%' ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode) { case 0: sprintf(buf,"\tFound non-patient subscriber person %d", msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); /* store insert values */ strcpy(msg_sub_hosp," "); strcpy(msg_sub_pat_no," " ); strcpy(msg_sub_pat_no_dsp," "); intPerson_no = msg_sub_person_no; break; case 100: sprintf(buf,"\tNo NON-PATIENT found for subscriber person_no %d", msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); return(0); /* disable do_pers_syn_insert */ break; default: printf("\nCan't select against PERS_SYN\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ if (sub_non_patient == 1) { if ((!strlen(uwmc_pat_no) && !strlen(hmc_pat_no)) || (strlen(uwmc_pat_no) && !strlen(hmc_pat_no)) || (strlen(hmc_pat_no) && !strlen(uwmc_pat_no))) { /* end-date all the UWMC pers_syn records for the subscriber person */ EXEC SQL REPEATED UPDATE pers_syn SET current_name = 'N' WHERE person_no = :msg_sub_person_no AND (hosp is null or hosp = ' ') AND (pat_no is null or pat_no = ' ') AND stripped_name not like 'AACANC%'; switch(sqlca.sqlcode) { case 0: sprintf(buf,"\tEnded subscriber NON-PATIENT pers_syn records " "for person_no %d", msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); return(1); /* enable pers_syn insert */ break; case 100: sprintf(buf,"\tNo subscriber NON-PATIENT pers_syn records " "ended for person_no %d", msg_sub_person_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); return(0); /* disable do_pers_syn_insert */ break; default: printf("\nCan't update PERS_SYN\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ } /* uwmc/hmc strlen's */ } /* sub_non_patient */ } /* if( !strcmp(HUP,"P") */ return(0); }/**************** end_date_HUP_pers_syn *********************************/ /************************************************************************* * function: do_pers_syn_insert * args: hl7_union_t *upd_msg * returns: -1 if a fatal error occurred. * usage info: calls stored dbproc upd_pers_syn * * HISTORY: * -------- * * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 20-May-2000 * Mod: added tie-breaker. * * Programmer: Jeff Martin * Date: 11-May-2000 * Mod: set hosp and pat_no_dsp to ''. * * Programmer: Jeff Martin * Date: 30-Apr-2000 * Mod: Started. *************************************************************************/ int do_pers_syn_insert(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { EXEC SQL BEGIN DECLARE SECTION; char current_name[2]; char upd_dt[4]; char upd_cd[9]; int row_count; char tie_breaker[2]; /* increase row_id resolution */ EXEC SQL END DECLARE SECTION; int intRandom = 0; /* calculate tie breaker */ /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning do_pers_syn_insert()", NOTIFY_UPDATE); while( intRandom <= 'A' || intRandom >= 'Z' || intRandom == PrevRowId ) /* don't let 2 in a row */ /* clip off some MSB's */ intRandom = (rand() >> 4 ); sprintf(tie_breaker,"%c",intRandom); PrevRowId = intRandom; /* init default values */ strcpy(current_name,"Y"); strcpy(upd_dt,"now"); strcpy(upd_cd,"INS"); /* assign new insert defaults */ if( PERFORM_INSERT) { strcpy(race,"X"); strcpy(microfiche_rec,""); strcpy(bypass_rs,"N"); g_soundex_cd(msg_sub_last_name,soundex_cd); } /* confirm ssn values are correct format */ if( strlen(msg_sub_ssn) == 11 || strlen(msg_sub_ssn) == 9 ) { ssn_valid(msg_sub_ssn); } strcpy(msg_ZI2_ssn_stat, strcmp(msg_sub_ssn,"000-00-0000") ? "K" : "U"); if( verbose_level >= VERBOSE_MADDENING) printf("\n\tEXEC SQL EXECUTE PROCEDURE upd_pers_syn(\n" "\tupd_cd = %s,\n" "\tbypass_rs = %s,\n" "\thosp = %s,\n" "\tpat_no = %s,\n" "\tpat_no_dsp = %s,\n" "\tperson_no = %d,\n" "\tlast_name = %s,\n" "\tfirst_name = %s,\n" "\tmiddle_name = %s,\n" "\tname_suffix = %s,\n" "\tbirth_d = %s,\n" "\tsoc_sec_no_dsp = %s,\n" "\tssn_stat = %s,\n" "\trace = %s,\n" "\tsex = %s,\n" "\tstripped_name = %s,\n" "\tsoundex_cd = %s,\n" "\tcurrent_name = %s,\n" "\tmicrofiche_rec = %s,\n" "\tupd_dt = %s,\n" "\tupd_by = %s,\n" "\tupd_area = %s,\n" "\ttie_breaker = %s,\n" "\tnet_sec_upd_by = %s) INTO :row_count\n", upd_cd, bypass_rs, msg_sub_hosp, msg_sub_pat_no, msg_sub_pat_no_dsp, msg_sub_person_no, msg_sub_last_name, msg_sub_first_name, msg_sub_middle_name, msg_sub_name_suffix, msg_sub_birth_d, msg_sub_ssn, msg_ZI2_ssn_stat, race, msg_sub_sex, msg_stripped_name, soundex_cd, current_name, microfiche_rec, upd_dt, msg_upd_by, msg_upd_area, tie_breaker, msg_net_sec_upd_by); EXEC SQL EXECUTE PROCEDURE upd_pers_syn( upd_cd = :upd_cd, bypass_rs = :bypass_rs, hosp = :msg_sub_hosp, pat_no = :msg_sub_pat_no, pat_no_dsp = :msg_sub_pat_no_dsp, person_no = :msg_sub_person_no, last_name = :msg_sub_last_name, first_name = :msg_sub_first_name, middle_name = :msg_sub_middle_name, name_suffix = :msg_sub_name_suffix, birth_d = :msg_sub_birth_d, soc_sec_no_dsp = :msg_sub_ssn, ssn_stat = :msg_ZI2_ssn_stat, race = :race, sex = :msg_sub_sex, stripped_name = :msg_stripped_name, soundex_cd = :soundex_cd, current_name = :current_name, microfiche_rec = :microfiche_rec, upd_dt = :upd_dt, upd_by = :msg_upd_by, upd_area = :msg_upd_area, tie_breaker = :tie_breaker, net_sec_upd_by = :msg_net_sec_upd_by) INTO :row_count; switch(sqlca.sqlcode){ case 0: if(row_count == 1) { sprintf(buf,"\tInserted person_no %d \n\t%s %s %s into PERS_SYN", msg_sub_person_no, msg_sub_first_name, msg_sub_middle_name, msg_sub_last_name); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); return(0); } else { printf("\nupd_pers_syn: Bad return code %d\n",row_count); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); } break; case -30210: /* dup key on INSERT */ sprintf(buf,"\nPERS_SYN %s %s %s \nalready exists for %d (%s%s)\n", msg_sub_first_name, msg_sub_middle_name, msg_sub_last_name, msg_sub_person_no, msg_hosp, msg_pat_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; default: printf("\nCan't call DBPROC upd_pers_syn\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/******************* end of do_pers_syn_insert *************************/ /************************************************************************* * function: do_patient_update * args: none. * returns: -1 if a fatal error occurred, sqlcode otherwise. * usage info: issues local sql to update the patient table * using message values while preserving existing columns. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 04-May-2000 * Mod: started. **************************************************************************/ int do_patient_update() { EXEC SQL BEGIN DECLARE SECTION; char mcare_no[13]; char mcare_b_elig_from_d[26]; char mcare_b_elig_thru_d[26]; char mcare_eligible[2]; char mcaid_pic_no[15]; char mcaid_case_no[13]; char upd_dt[26]; char upd_by[4]; char upd_area[3]; char net_sec_upd_by[9]; EXEC SQL END DECLARE SECTION; /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning do_patient_update()", NOTIFY_UPDATE); /* select columns to preserve from the update */ EXEC SQL REPEATED SELECT mcare_no, mcare_b_elig_from_d, mcare_b_elig_thru_d, mcare_eligible, mcaid_pic_no, mcaid_case_no, upd_by, upd_dt, upd_area, net_sec_upd_by INTO :mcare_no, :mcare_b_elig_from_d, :mcare_b_elig_thru_d, :mcare_eligible, :mcaid_pic_no, :mcaid_case_no, :upd_by, :upd_dt, :upd_area, :net_sec_upd_by FROM patient WHERE hosp = :msg_hosp AND pat_no = :msg_pat_no ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode){ case 0: /* update target found, preserve all but these columns */ if( strlen(msg_mcare_no)) strncpy(mcare_no,msg_mcare_no,12); if( strlen(msg_mcare_b_elig_from_d)) strncpy(mcare_b_elig_from_d,msg_mcare_b_elig_from_d,25); if( strlen(msg_mcare_b_elig_thru_d)) strncpy(mcare_b_elig_thru_d,msg_mcare_b_elig_thru_d,25); if( strlen(msg_mcare_elig)) strncpy(mcare_eligible,msg_mcare_elig,1); if( strlen(msg_mcaid_case_no)) strncpy(mcaid_case_no,msg_mcaid_case_no,12); if( strlen(msg_mcaid_pic_no)) strncpy(mcaid_pic_no,msg_mcaid_pic_no,14); if( strlen(msg_upd_by)) strncpy(upd_by,msg_upd_by,3); if( strlen(msg_upd_area)) strncpy(upd_area,msg_upd_area,2); if( strlen(msg_net_sec_upd_by)) strncpy(net_sec_upd_by,msg_net_sec_upd_by,8); date_string(msg_mcaid_1st_elig_d); date_string(msg_mcaid_elig_thru_d); /* update PATIENT */ printf("\n\tUPDATE PATIENT SET\n" "\t mcare_no = '%s',\n" "\t mcare_b_elig_from_d = '%s',\n" "\t mcare_b_elig_thru_d = '%s',\n" "\t mcaid_1st_elig_d = '%s',\n" "\t mcaid_elig_thru_d = '%s',\n" "\t mcare_eligible = '%s',\n" "\t mcaid_pic_no = '%s',\n" "\t mcaid_case_no = '%s',\n" "\t upd_by = '%s',\n" "\t upd_dt = '%s',\n" "\t upd_area = '%s',\n" "\t net_sec_upd_by = '%s'\n" "\tWHERE hosp = '%s'\n" "\tAND pat_no = '%s'\n", mcare_no, mcare_b_elig_from_d, mcare_b_elig_thru_d, msg_mcaid_1st_elig_d, msg_mcaid_elig_thru_d, mcare_eligible, mcaid_pic_no, mcaid_case_no, upd_by, "now", upd_area, net_sec_upd_by, msg_hosp, msg_pat_no); EXEC SQL REPEATED UPDATE PATIENT SET mcare_no = :mcare_no, mcare_b_elig_from_d = :mcare_b_elig_from_d, mcare_b_elig_thru_d = :mcare_b_elig_thru_d, mcaid_1st_elig_d = :msg_mcaid_1st_elig_d, mcaid_elig_thru_d = :msg_mcaid_elig_thru_d, mcare_eligible = :mcare_eligible, mcaid_pic_no = :mcaid_pic_no, mcaid_case_no = :mcaid_case_no, upd_by = :upd_by, upd_dt = :upd_dt, upd_area = :upd_area, net_sec_upd_by = :net_sec_upd_by WHERE hosp = :msg_hosp AND pat_no = :msg_pat_no; switch(sqlca.sqlcode){ case 0: error_notify(__FILE__,__LINE__, "upd_patient: Successful",NOTIFY_UPDATE); return(0); default: printf("\nCan't update PATIENT \n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* update switch */ break; case 100: /* enable do_patient_insert */ sprintf(buf,"\tupdate target (%s%s) not found, enabling insert", msg_hosp,msg_pat_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); return(100); break; default: printf("\nCan't select against PATIENT\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* select switch */ return(0); }/******************* end of do_patient_update ***************************/ /************************************************************************* * function: do_patient_insert * args: none. * returns: -1 if a fatal error occurred. * usage info: calls stored dbproc upd_patient. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 04-May-2000 * Mod: started. **************************************************************************/ int do_patient_insert() { EXEC SQL BEGIN DECLARE SECTION; char upd_cd[9]; int row_count; int budget_no; char bill_handl_flag[3]; char fin_folder_stat[4]; char fmc_cd[2]; char disabled_flag[2]; char living_alone[2]; char pat_citizen[7]; char birth_place[8]; char organ_donor[2]; char vpa_consent[2]; char consent_signed[2]; char consent_expire_dt[26]; char ob_consent_signed[2]; char ob_consent_dt[26]; char addl_info_key[12]; char adopted_cd[2]; char dshs_app_needed[2]; char veteran[2]; char expired_pat_flag[2]; char no_info[2]; char valuables_flag[2]; char adv_directive_dt[26]; char adv_directive_fl[2]; char adv_dir_file[2]; char rbp_consent[2]; char pat_care_plan[2]; char de_review_dt[26]; char last_opd_svc_cd[3]; char opd_sp_rev_dt[26]; int clin_dest_com_key; char aka_name[25]; char pending_flag[2]; char upd_dt[26]; char upd_by[4]; EXEC SQL END DECLARE SECTION; /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning do_patient_insert()", NOTIFY_UPDATE); /* init defaults */ strcpy(upd_cd,"INS"); strcpy(upd_dt,"now"); /* budget_no = atoi(msg_group_no); */ budget_no = 0; clin_dest_com_key = 0; strcpy(adv_directive_fl,"N"); strcpy(adv_dir_file,"N"); strcpy(adv_directive_dt,REG_HIGH_DT); strcpy(no_info,"G"); strcpy(ob_consent_signed,"N"); strcpy(ob_consent_dt,""); date_string(msg_mcaid_1st_elig_d); date_string(msg_mcaid_elig_thru_d); /* call stored dbproc upd_patient */ if(verbose_level >= VERBOSE_MADDENING) printf("\t\nEXECUTE PROCEDURE upd_patient(\n" "\t upd_cd = '%s',\n" "\t hosp = '%s',\n" "\t pat_no = '%s',\n" "\t budget_no = %d,\n" "\t mother_maiden_name = '%s',\n" "\t fathers_name = '%s',\n" "\t mcare_no = '%s',\n" "\t mcare_a_elig_from_d = '%s',\n" "\t mcare_b_elig_from_d = '%s',\n" "\t mcare_b_elig_thru_d = '%s',\n" "\t mcare_eligible = '%s',\n" "\t mcaid_pic_no = '%s',\n" "\t mcaid_case_no = '%s',\n" "\t mcaid_1st_elig_d = '%s',\n" "\t mcaid_elig_thru_d = '%s',\n" "\t adv_directive_fl = '%s',\n" "\t adv_dir_file = '%s',\n" "\t adv_directive_dt = '%s',\n" "\t de_review_dt = '%s',\n" "\t opd_sp_rev_dt = '%s',\n" "\t no_info = '%s',\n" "\t ob_consent_signed = '%s',\n" "\t ob_consent_dt = '%s',\n" "\t clin_dest_com_key = %d,\n" "\t upd_dt = '%s',\n" "\t upd_by = '%s',\n" "\t upd_area = '%s',\n" "\t net_sec_upd_by = '%s',\n" " ) INTO :row_count\n", upd_cd, msg_hosp, msg_pat_no, budget_no, mother_maiden_name, zp2_fthr_name, msg_mcare_no, REG_HIGH_DT, msg_mcare_b_elig_from_d, "", msg_mcare_elig, msg_mcaid_pic_no, msg_mcaid_case_no, msg_mcaid_1st_elig_d, msg_mcaid_elig_thru_d, adv_directive_fl, adv_dir_file, adv_directive_dt, REG_HIGH_DT, REG_HIGH_DT, no_info, ob_consent_signed, ob_consent_dt, clin_dest_com_key, upd_dt, msg_upd_by, msg_upd_area, msg_net_sec_upd_by); EXEC SQL EXECUTE PROCEDURE upd_patient( upd_cd = :upd_cd, hosp = :msg_hosp, pat_no = :msg_pat_no, budget_no = :budget_no, mother_maiden_name = :mother_maiden_name, fathers_name = :zp2_fthr_name, mcare_no = :msg_mcare_no, mcare_a_elig_from_d = :REG_HIGH_DT, mcare_b_elig_from_d = :msg_mcare_b_elig_from_d, mcare_b_elig_thru_d = '', mcare_eligible = :msg_mcare_elig, mcaid_pic_no = :msg_mcaid_pic_no, mcaid_case_no = :msg_mcaid_case_no, mcaid_1st_elig_d = :msg_mcaid_1st_elig_d, mcaid_elig_thru_d = :msg_mcaid_elig_thru_d, adv_directive_fl = :adv_directive_fl, adv_dir_file = :adv_dir_file, adv_directive_dt = :adv_directive_dt, de_review_dt = :REG_HIGH_DT, opd_sp_rev_dt = :REG_HIGH_DT, no_info = :no_info, ob_consent_signed = :ob_consent_signed, ob_consent_dt = :ob_consent_dt, clin_dest_com_key = :clin_dest_com_key, upd_dt = :upd_dt, upd_by = :msg_upd_by, upd_area = :msg_upd_area, net_sec_upd_by = :msg_net_sec_upd_by ) INTO :row_count; switch(sqlca.sqlcode){ case 0: if(row_count == 1) { error_notify(__FILE__,__LINE__, "upd_patient: Successul",NOTIFY_UPDATE); return(0); } else { printf("\nupd_patient: Bad return code %d\n",row_count); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); } break; default: printf("\nCan't call DBPROC upd_patient\n"); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ return(0); }/******************* end of do_patient_insert ****************************/ /************************************************************************* * function: upd_unl_ppl * args: hl7_union_t *upd_msg, hl7_union_t *fwd_msg * returns: -1 if a fatal error occurred. * usage info: this function calls DBPROC 'upd_unlisted_ppl' in order * to insert a GENERIC plan into unlisted_payor_plan. * * HISTORY: * -------- * Programmer: * Date: * Mod: * **************************************************************************/ int upd_unl_ppl(hl7_union_t *upd_msg, hl7_union_t *fwd_msg ) { EXEC SQL BEGIN DECLARE SECTION; char upd_cd[9]; int row_count; char upd_dt[26]; EXEC SQL END DECLARE SECTION; char strLast_addr_seq_no[16]; /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning upd_unl_ppl()", NOTIFY_UPDATE); /* populate default values */ strcpy(upd_cd,"INS"); strcpy(upd_dt,"now"); /* blank plan_no for all GENERIC */ if( hl7_set(fwd_msg,&IN1_plan_id,in1_no,0,0,0, NULL)) { sprintf(buf,"\nCan't set IN1.2.0.0 segment %d in fwd_msg\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( GENERIC_PPL ) { /* copy IN1.4 to ZI2.65 */ if( hl7_set(upd_msg,&ZI2_plan_name,in1_no,0,0,0, msg_ins_company_name)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set ZI2.65.4.0.0 in upd message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_plan_name,in1_no,0,0,0, msg_ins_company_name)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set ZI2.65.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } strncpy(msg_zi2_plan_name, msg_ins_company_name,40); /* get new IN1.4 value */ EXEC SQL REPEATED SELECT payor_desc, upd_dt INTO :msg_ins_company_name, :upd_dt FROM PAYOR_N WHERE payor_no = :payor_no ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tPAYOR_N: %s",msg_ins_company_name); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } /* save msg_ins_company_name for UPDATE.upd_unl_ppl */ if( hl7_set(upd_msg,&IN1_ins_company_name,in1_no,0,0,0, msg_ins_company_name)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set IN1.4.0.0 in upd message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_name,in1_no,0,0,0, msg_ins_company_name)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set IN1.4.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } /* store generic plan name in ZI2.18 */ if( hl7_set(fwd_msg,&ZI2_payor_desc,in1_no,0,0,0, msg_ins_company_name )) { sprintf(buf,"\nCan't set ZI2.18 %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } break; case 100: if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tPAYOR_N query found no rows for %d", payor_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } /* save msg_ins_company_name for UPDATE.upd_unl_ppl */ if( hl7_set(upd_msg,&IN1_ins_company_name,in1_no,0,0,0, "")) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set IN1.4.0.0 in upd message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&IN1_ins_company_name,in1_no,0,0,0, "")) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set IN1.4.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } break; default: printf("\nupd_unl_ppl: Can't select against PAYOR_N\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ } /* if( GENERIC_PPL ) */ if( GENERIC_GENERIC_PPL ) { strcpy(spons_cd,"C01"); payor_no = 0; payor_plan_no = 0; /* copy IN1.4 to ZI2.65 */ if( hl7_set(upd_msg,&ZI2_plan_name,in1_no,0,0,0, msg_ins_company_name)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set ZI2.65.4.0.0 in upd message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_plan_name,in1_no,0,0,0, msg_ins_company_name)) { error_notify(__FILE__, __LINE__,"upd_unl_ppl: " "\nCan't set ZI2.65.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_payor_desc,in1_no,0,0,0, msg_ins_company_name )) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.18.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } strncpy(msg_zi2_plan_name, msg_ins_company_name,40); } /* if( GENERIC_GENERIC_PPL ) */ generic_ppl_no = (strcmp(msg_hosp,"H") ? U_UNL_PPL : H_UNL_PPL); EXEC SQL REPEATED SELECT last_addr_seq_no INTO :last_addr_seq_no FROM payor_plan WHERE payor_plan_no = :generic_ppl_no; EXEC SQL BEGIN; EXEC SQL ENDSELECT; EXEC SQL END; switch(sqlca.sqlcode) { case 0: if( verbose_level >= VERBOSE_MADDENING ) { sprintf(buf,"\tupd_unl_ppl: payor_plan_no " "%d last_addr_seq_no = %d", generic_ppl_no, last_addr_seq_no + 1); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } break; case 100: sprintf(buf,"\nupd_unl_ppl: " "can't find payor_plan %d", generic_ppl_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); return(-1); break; default: printf("\nupd_unl_ppl: can't select against PAYOR_PLAN\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ /* call the DB proc to update UNLISTED_PAYOR_PLAN */ if(verbose_level >= VERBOSE_MADDENING) printf("\t\nEXECUTE PROCEDURE upd_unlisted_ppl(\n" "\t upd_cd = '%s',\n" "\t payor_plan_no = %d,\n" "\t addr_seq_no = %d,\n" "\t ul_plan_no = %d,\n" "\t ul_plan_name = '%s',\n" "\t ul_payor_no = %d,\n" "\t ul_payor_desc = '%s',\n" "\t hosp = '%s',\n" "\t spons_cd = '%s',\n" "\t addr_1 = '%s',\n" "\t addr_2 = '%s',\n" "\t city = '%s',\n" "\t st = '%s',\n" "\t zip = '%s',\n" "\t zip_suffix = '%s',\n" "\t country_cd = '%s',\n" "\t foreign_zip = '%s',\n" "\t bill_attn = '%s',\n" "\t mail_stop = '%s',\n" "\t area_code = '%s',\n" "\t ph_prefix = '%s',\n" "\t ph_suffix = '%s',\n" "\t ph_ext = '%s',\n" "\t no_cov = '%s',\n" "\t status = '%s',\n" "\t generic_ppl_no = %d,\n" "\t upd_dt = '%s',\n" "\t upd_by = '%s',\n" "\t upd_area = '%s',\n" "\t net_sec_upd_by = '%s',\n" "\t) INTO :row_count\n", upd_cd, generic_ppl_no, last_addr_seq_no, 0, /* ul_plan_no */ msg_zi2_plan_name, payor_no, msg_ins_company_name, msg_hosp, spons_cd, msg_ins_company_addr_1, msg_ins_company_addr_2, msg_ins_company_city, msg_ins_company_st, msg_ins_company_zip, "", /* zip suffix */ msg_ins_company_country, msg_ins_company_for_zip, msg_ins_co_contact_per, msg_zi2_mail_stop, "", /* area code */ "", /* ph prefix */ "", /* ph suffix */ "", /* ph ext */ "", /* no cov */ "", /* status */ payor_plan_no, upd_dt, msg_upd_by, msg_upd_area, msg_net_sec_upd_by); EXEC SQL EXECUTE PROCEDURE upd_unlisted_ppl( upd_cd = :upd_cd, payor_plan_no = :generic_ppl_no, addr_seq_no = :last_addr_seq_no, ul_plan_no = 0, ul_plan_name = :msg_zi2_plan_name, ul_payor_no = :payor_no, ul_payor_desc = :msg_ins_company_name, hosp = :msg_hosp, spons_cd = :spons_cd, addr_1 = :msg_ins_company_addr_1, addr_2 = :msg_ins_company_addr_2, city = :msg_ins_company_city, st = :msg_ins_company_st, zip = :msg_ins_company_zip, zip_suffix = '', country_cd = :msg_ins_company_country, foreign_zip = :msg_ins_company_for_zip, bill_attn = :msg_ins_co_contact_per, mail_stop = :msg_zi2_mail_stop, area_code = '', ph_prefix = '', ph_suffix = '', ph_ext = '', no_cov = '', status = '', generic_ppl_no = :payor_plan_no, upd_dt = :upd_dt, upd_by = :msg_upd_by, upd_area = :msg_upd_area, net_sec_upd_by = :msg_net_sec_upd_by ) INTO :row_count; switch(sqlca.sqlcode){ case 0: if(row_count == 1) { error_notify(__FILE__,__LINE__, "\tupd_unl_ppl: Successful.",NOTIFY_UPDATE); } else { printf("\nupd_unl_ppl: Bad return code %d\n",row_count); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); } break; case -30210: /* dup key on insert */ sprintf(buf,"\nupd_unl_ppl: " "addr_seq_no %d already exists for payor_plan %d\n", last_addr_seq_no, generic_ppl_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); break; default: error_notify(__FILE__,__LINE__, "\nCan't call DBPROC upd_unl_ppl\n",NOTIFY_FATAL); ingerr(__FILE__, __LINE__,sqlca.sqlcode,DEFAULT_SEQ_NO); return(-1); break; } /* switch */ /* store last_addr_seq_no */ last_addr_seq_no++; /* dbproc increments payor_plan */ sprintf(strLast_addr_seq_no,"%d",last_addr_seq_no); if( verbose_level >= VERBOSE_MADDENING ) { sprintf(buf,"\tupd_unl_ppl: setting ZI2.62.0.0 segment %d to %s", in1_no, strLast_addr_seq_no ); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } if( hl7_set(upd_msg,&ZI2_addr_seq_no,in1_no,0,0,0, strLast_addr_seq_no)) { sprintf(buf,"\nCan't set ZI2.62.0.0 segment %d in upd_msg\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_addr_seq_no,in1_no,0,0,0, strLast_addr_seq_no)) { sprintf(buf,"\nCan't set ZI2.62.0.0 segment %d in fwd_msg\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* configure an MFN event */ if( create_MFN_message(upd_msg, fwd_msg) == -1) return(-1); return(0); }/********************* end of upd_unl_ppl ******************************/ /************************************************************************* * function: config_fwd_msg * args: hl7_union_t *upd_msg, hl7_union_t *fwd_msg * returns: -1 if a fatal error occurred. * usage info: called after coverage_validation() in VALIDATE mode. * configures a single fwd_msg that represents all the * database update activity needed by REG downstream system. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 25-Apr-2000 * Mod: started. **************************************************************************/ int config_fwd_msg(hl7_union_t *upd_msg, hl7_union_t *fwd_msg ) { int BLANK=0, SET=1; int Myin1_no, Myin1_count; char *strFwd_ssn, *c8; char strPayor_plan_no[11]; /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning config_fwd_msg()", NOTIFY_UPDATE); /* refresh any changes from validation */ if( read_from_msg(upd_msg) == -1) return(-1); /* popluate ZP2_stripped_name */ if( hl7_set(fwd_msg,&ZP2_stripped_name,1,0,0,0,zp2_stripped_name)) { error_notify(__FILE__, __LINE__,"config_fwd_msg: " "Can't set zp2-stripped-name in fwd msg", NOTIFY_FATAL); return(-1); } /* populate ZI2_stripped_name */ if( hl7_set(fwd_msg,&ZI2_stripped_name,in1_no,0,0,0, strlen(msg_stripped_name) ? msg_stripped_name : NULL)) { error_notify(__FILE__, __LINE__,"config_fwd_msg: " "Can't set zi2-stripped-name in fwd msg", NOTIFY_FATAL); return(-1); } /* set ins company info from the database */ if( GENERIC_PPL + GENERIC_GENERIC_PPL == 0 ) { if( set_ins_company_addr(upd_msg, fwd_msg) == -1) return(-1); } /* zi2_spons_cd */ if( !strlen(msg_spons_cd) || !strcmp(msg_spons_cd,"") ) { if( hl7_set(fwd_msg,&ZI2_spons_cd,in1_no,0,0,0, spons_cd )) { sprintf(buf,"\nCan't set ZI2.21.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } strncpy(msg_spons_cd,spons_cd,strlen(spons_cd)); } /* configure PV1_20 for this IN1/IN2/ZI2 group */ Myin1_count = count_segs(fwd_msg, "IN1"); for( Myin1_no=1; Myin1_no<=Myin1_count; Myin1_no++) { if( hl7_set_by_grp(fwd_msg,&PV1_fin_class,1,0,NULL,Myin1_no+1, hl7_get(fwd_msg, &ZI2_spons_cd, Myin1_no, 0, NULL, 0, 0) )) { error_notify(__FILE__, __LINE__, "Can't set PV1.20.0.0 in fwd msg", NOTIFY_FATAL); return(-1); } } /* configure PV1/ZV2 set_id */ if( hl7_set(fwd_msg,&PV1_set_id,1,0,0,0,"1")) { error_notify(__FILE__, __LINE__,"config_fwd_msg: " "Can't set pv1-set-id in fwd msg", NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZV2_set_id,1,0,0,0,"1")) { error_notify(__FILE__, __LINE__,"config_fwd_msg: " "Can't set zv2-set-id in fwd msg", NOTIFY_FATAL); return(-1); } /* configure ZI2_pat_to_pers */ if( hl7_set(fwd_msg,&ZI2_pat_to_pers,in1_no,0,0,0,msg_pat_rel_to_ins)) { error_notify(__FILE__, __LINE__,"config_fwd_msg: " "Can't set zi2-pat-to-pers in fwd msg", NOTIFY_FATAL); return(-1); } /* zi2_ins_id_int */ if( !strcmp(msg_pat_rel_to_ins,"SE")) sprintf(msg_sub_pat_no_dsp,"%s%s",msg_hosp,msg_pat_no); else { if( get_sub_pat_no_dsp() == -1) return(-1); } if( hl7_set(fwd_msg,&ZI2_ins_id_int,in1_no,0,0,0, msg_sub_pat_no_dsp )) { sprintf(buf,"\nCan't set ZI2_ins_id_int segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\tset ZI2.55.0.0 to '%s'", msg_sub_pat_no_dsp); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } /* format dates */ if( fwd_dates(fwd_msg, 1) == -1) return(-1); /************* table specific updates *********/ /* COVERAGE */ if( INS_COVERAGE ) { if( fwd_coverage(fwd_msg,SET) == -1) return(-1); } /* PATIENT */ if( UPD_SUB_PATIENT ) { if( fwd_patient(fwd_msg,SET) == -1) return(-1); } /* PERS_PLAN_REL */ if( UPD_PERS_PLAN_REL) { if( fwd_pers_plan_rel(fwd_msg,SET) == -1) return(-1); } /* PERS_SYN */ if( UPD_SUB_PERS_SYN || INS_SUB_PERS_SYN) { if( fwd_pers_syn(fwd_msg,SET) == -1) return(-1); if( create_cvg_message(fwd_msg) == -1) return(-1); } /* zi2-first-entry-dt */ if( hl7_set(fwd_msg,&ZI2_first_entry_dt,in1_no,0,0,0, msg_evn_timestamp)) { sprintf(buf,"\nCan't set ZI2.57.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2-first-entry-by */ if( !strlen(msg_upd_by)) strcpy(msg_upd_by,"hl7_rcv"); if( hl7_set(fwd_msg,&ZI2_first_entry_by,in1_no,0,0,0, msg_upd_by )) { sprintf(buf,"\nCan't set ZI2.58.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2_pay_plan_no (old=0, new=payor_plan_no) */ if( GENERIC_PPL + GENERIC_GENERIC_PPL > 0 ) { payor_plan_no = (strcmp(msg_hosp,"H") ? U_UNL_PPL : H_UNL_PPL); } sprintf(strPayor_plan_no,"%d",payor_plan_no); if( hl7_set(fwd_msg,&ZI2_pay_plan_no,in1_no,0,0,0, strPayor_plan_no )) { sprintf(buf,"\nCan't set ZI2.61.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( verbose_level >= VERBOSE_MADDENING) { sprintf(buf,"\t IN1_policy_no = '%s'\n" "\tSet IN1_ins_plan_id to '%s'\n" "\tSet ZI2_first_entry_by to '%s'\n" "\tSet ZI2_first_entry_dt to '%s'\n" "\tSet ZI2_person_no to '%d'\n" "\tSet ZI2_pay_plan_no to '%d'\n", msg_policy_id, msg_plan_id, msg_upd_by, msg_evn_timestamp, msg_sub_person_no, payor_plan_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_UPDATE); } return(0); }/********************* end of config_fwd_msg ****************************/ /************************************************************************* * function: fwd_coverage * args: hl7_union_t *fwd_msg, int SET * returns: -1 if a fatal error occurred. * usage info: * * HISTORY: * -------- * Programmer: Jeff Martin * Date: 09-May-2000 * Mod: * system test remediations. * * added SET arg that sets or blanks msg field. * * Programmer: Jeff Martin * Date: 04-May-2000 * Mod: * populate in1_ins_company_name, in1_ins_company_addr * if they exist in PLAN_N * * Programmer: Jeff Martin * Date: 25-Apr-2000 * Mod: started. **************************************************************************/ int fwd_coverage(hl7_union_t *fwd_msg, int SET) { /* in1_set_id defaults */ int coverage_type = 2; int prim_sec = 1; int current = 1; /* int to ascii conversions */ char strMsg_sub_person_no[11]; /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning fwd_coverage()", NOTIFY_UPDATE); /* in1_set_id */ if( !strncmp(msg_ip_op_de_cd,"IP",2)) coverage_type = 1; if( !strncmp(msg_ip_op_de_cd,"OP",2)) coverage_type = 2; if( !strncmp(msg_ip_op_de_cd,"DE",2)) coverage_type = 3; if( !strncmp(msg_cob_cd,"A",1)) prim_sec = 1; if( !strncmp(msg_cob_cd,"B",1)) prim_sec = 2; sprintf(msg_in1_set_id,"%d%d%d",coverage_type,prim_sec,current); if( hl7_set(fwd_msg,&IN1_set_id,in1_no,0,0,0, msg_in1_set_id )) { sprintf(buf,"\nCan't set IN1.1.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2_cov_a_c_d_cd (ZUFIN='C', all others 'A') */ if( hl7_set(fwd_msg,&ZI2_cov_a_c_d_cd,in1_no,0,0,0, "A")) { sprintf(buf,"\nCan't set ZI2.26.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } return(0); }/********************* end of fwd_coverage *****************************/ /************************************************************************* * function: fwd_pers_plan_rel * args: hl7_union_t *fwd_msg, int SET * returns -1 if a fatal error occurred. * usage info: * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 25-Apr-2000 * Mod: started. **************************************************************************/ int fwd_pers_plan_rel(hl7_union_t *fwd_msg, int SET) { char strHl7_acd_cd[2]; /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning fwd_pers_plan_rel()", NOTIFY_UPDATE); /* populate coverage fields */ if( !INS_COVERAGE) { if( fwd_coverage(fwd_msg, 1) == -1) return(-1); } /* Step 8.2, Scenario 3, CVG Reg_rcv.doc (update pers_plan_rel) */ if( strcmp(msg_policy_id,db_ins_policy_id) && strlen(msg_policy_id) && db_cvg_payor_plan_no == payor_plan_no ) { strcpy(strHl7_acd_cd,"C"); } else { strcpy(strHl7_acd_cd,"A"); } /* zi2-plan-a-c-d-cd (commented out during testing at MS/TAR direction) if( hl7_set(fwd_msg,&ZI2_plan_a_c_d_cd,in1_no,0,0,0, strHl7_acd_cd )) { sprintf(buf,"\nCan't set ZI2.27.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } */ return(0); }/********************** end of fwd_pers_plan_rel ***********************/ /************************************************************************* * function: fwd_pers_syn * args: hl7_union_t *fwd_msg, int SET * returns -1 if a fatal error occurred. * usage info: * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 25-Apr-2000 * Mod: started. **************************************************************************/ int fwd_pers_syn(hl7_union_t *fwd_msg, int SET) { /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning fwd_pers_syn()", NOTIFY_UPDATE); return(0); }/********************** end of fwd_pers_syn ******************************/ /************************************************************************* * function: fwd_patient * args: hl7_union_t *fwd_msg, SET * returns: -1 if a fatal error occurred. * usage info: * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 25-Apr-2000 * Mod: started. **************************************************************************/ int fwd_patient(hl7_union_t *fwd_msg, int SET) { /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning fwd_patient()", NOTIFY_UPDATE); return(0); }/************************* end of fwd_patient **************************/ /************************************************************************* * function: create_cvg_message * args: hl7_union _t *fwd_msg, cvg_msg * returns: -1 if a fatal error occurred. * usage info: creates a basic coverage forward message intended * enable PERS_SYN/PERS_ADDR updates on the A19. * If the inbound message represents an UPDATE, an A31 * is configured. If a new INSERT is enabled, an A28 * is configured. The message (A28 or A31) is pointed to * by extern hl7_union_t *cvg_msg declared in prepareA08_reg * and forwarded in handleA08.tcl via tcl_action.forward_msg. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 23-May-2000 * Mod: IN1 1 sets FORWARD_CVG1, IN1 2 sets FORWARD_CVG2 * * Programmer: Jeff Martin * Date: 14-May-2000 * Mod: started. this is gruesome because it dual uses the same * hl7_union_t object in prepareA08_reg.sc and tcl_action.c **************************************************************************/ int create_cvg_message(hl7_union_t *fwd_msg) { /* NK1 objects */ spec_t NK1_last_name = { "NK1", 2, 0, 0 }; spec_t NK1_first_name = { "NK1", 2, 1, 0 }; spec_t NK1_middle_name = { "NK1", 2, 2, 0 }; spec_t NK1_name_suffix = { "NK1", 2, 3, 0 }; spec_t NK1_addr_1 = { "NK1", 4, 0, 0 }; spec_t NK1_addr_2 = { "NK1", 4, 1, 0 }; spec_t NK1_city = { "NK1", 4, 2, 0 }; spec_t NK1_st = { "NK1", 4, 3, 0 }; spec_t NK1_zip = { "NK1", 4, 4, 0 }; spec_t NK1_country_cd = { "NK1", 4, 5, 0 }; /* properties for A31 stub */ char strDateTime[16]; int intDate; int intTime; char strMSH_send_app[64]; char strMSH_send_facility[64]; char strMSH_dest_app[64]; char strMSH_dest_facility[64]; char strMSH_Event[4]; char strMSH_hl7_version[64]; char soundex_cd[11]; char strMsg[MAX_HL7_MESSAGE_SIZE]; char *c; hl7_union_t *hl7Msg; /*************************************************************************/ if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning create_cvg_message()", NOTIFY_UPDATE); /* data for a MSH stub */ c = (char *) hl7_get(fwd_msg, &MSH_send_app, 1, 0, NULL, 0, 0); strcpy(strMSH_send_app, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_send_facility, 1, 0, NULL, 0, 0); strcpy(strMSH_send_facility, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_dest_app, 1, 0, NULL, 0, 0); strcpy(strMSH_dest_app, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_dest_facility, 1, 0, NULL, 0, 0); strcpy(strMSH_dest_facility, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_hl7_version, 1, 0, NULL, 0, 0); strcpy(strMSH_hl7_version, ( c ? c : "" )); /* timedate.c */ intDate = hl7_getdate(); intTime = gettime(); sprintf(strDateTime,"%d%d",intDate,intTime); /* prepare_msgs_reg.sc */ g_soundex_cd(msg_sub_last_name,soundex_cd); /* configure an event type */ if( UPD_SUB_PERS_SYN ) { strcpy(strMSH_Event,"A31"); } if( INS_SUB_PERS_SYN ) { strcpy(strMSH_Event,"A28"); } /* create a message stub */ sprintf(strMsg, "MSH|^~\\&||%s|%s|%s|%s||ADT^%s||P|%s|" "%cEVN|%s|%s|||%s" "%cZVN|%s|%s|" "%cNK1||%s^%s^%s^%s|" "%cZN2|||%d||||||||%s|%s|%s|%s|%s|%s|||%s|%s|%s|%s|" "%c", /* MSH */ strMSH_send_facility, strMSH_dest_app, strMSH_dest_facility, strDateTime, strMSH_Event, strMSH_hl7_version, /* EVN */ 13, strMSH_Event, strDateTime, msg_net_sec_upd_by, /* ZVN */ 13, msg_upd_by, msg_upd_area, /* NK1 */ 13, msg_sub_last_name, msg_sub_first_name, msg_sub_middle_name, msg_sub_name_suffix, /* ZN2 */ 13, msg_sub_person_no, msg_sub_birth_d, msg_sub_ssn, "X", /* ethnic group (ZN2.13) */ msg_sub_sex, soundex_cd, "N", /* microfich rec (ZN2.16) */ msg_stripped_name, "N", /* bypass rs (ZN2.20) */ msg_ZI2_ssn_stat, "Y", /* current name (ZN2.22) */ /* eom */ 13); /* store the cvg_message */ hl7Msg = (hl7_union_t *) str2mesg(strMsg); if( verbose_level >= 10000 ) { printf("\t\tCVG message:\n"); printmesg(hl7Msg); } if( in1_no == 1 ) cvg_message1 = (hl7_union_t *) copy_mesg(hl7Msg); if( in1_no == 2 ) cvg_message2 = (hl7_union_t *) copy_mesg(hl7Msg); if( in1_no == 3 ) cvg_message3 = (hl7_union_t *) copy_mesg(hl7Msg); if( hl7Msg) freemesg(hl7Msg); /* enable the TCL handler */ if( in1_no == 1) Tcl_SetVar(interp,"FORWARD_CVG1","1", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); if( in1_no == 2) Tcl_SetVar(interp,"FORWARD_CVG2","1", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); if( in1_no == 3) Tcl_SetVar(interp,"FORWARD_CVG3","1", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); sprintf(buf,"\tcreate_cvg_message: configured %s #%d for person %d", strMSH_Event, in1_no, msg_sub_person_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); return(0); }/******************** end of create_cvg_message ************************/ /************************************************************************* * function: create_MFN_message * args: hl7_union _t *fwd_msg * returns: -1 if a fatal error occurred. * usage info: configures a MFN message that is later * forwarded during UPDATE mode. * * HISTORY: * -------- * Programmer: * Date: * Mod: * **************************************************************************/ int create_MFN_message(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { /* properties for stub */ char strDateTime[16]; int intDate; int intTime; char strMSH_send_app[64]; char strMSH_send_facility[64]; char strMSH_dest_app[64]; char strMSH_dest_facility[64]; char strMSH_Event[4]; char strMSH_hl7_version[64]; char strMsg[MAX_HL7_MESSAGE_SIZE]; char *c; hl7_union_t *hl7Msg; /*************************************************************************/ if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning create_MFN_message()", NOTIFY_UPDATE); /* data for a MSH stub */ c = (char *) hl7_get(fwd_msg, &MSH_send_app, 1, 0, NULL, 0, 0); strcpy(strMSH_send_app, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_send_facility, 1, 0, NULL, 0, 0); strcpy(strMSH_send_facility, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_dest_app, 1, 0, NULL, 0, 0); strcpy(strMSH_dest_app, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_dest_facility, 1, 0, NULL, 0, 0); strcpy(strMSH_dest_facility, ( c ? c : "" )); c = (char *) hl7_get(fwd_msg, &MSH_hl7_version, 1, 0, NULL, 0, 0); strcpy(strMSH_hl7_version, ( c ? c : "" )); /* timedate.c */ intDate = hl7_getdate(); intTime = gettime(); sprintf(strDateTime,"%d%d",intDate,intTime); /* format Ingres now into HL7 DATE */ strHl7_date = (char *) hl7_format_dt("now"); strncpy(strDate,strHl7_date,25); strcpy(strMSH_Event,"MFN"); /* create a MFN string */ sprintf(strMsg, "MSH|^~\\&||%s|%s|%s|%s||ADT^%s||P|%s|" "%cEVN|%s|%s|||%s" "%cZVN|%s|%s" "%cIN1||||%s|%s^%s^%s^%s^%s^%s|%s" /* 12 3456789012345678901 */ "%cZI2||%s|||||||||||||||||||%s||||||||||||||||||" "||||||||||||||||||||||%d|%d|||%s" "%cMFI|%s||%s|%s|%s|%s" "%cMFE|%s||%s|%d^%d" "%c", /* MSH */ strMSH_send_facility, strMSH_dest_app, strMSH_dest_facility, strDateTime, strMSH_Event, strMSH_hl7_version, /* EVN */ 13, strMSH_Event, strDateTime, msg_net_sec_upd_by, /* ZVN */ 13, msg_upd_by, msg_upd_area, /* IN1 */ 13, msg_ins_company_name, msg_ins_company_addr_1, msg_ins_company_addr_2, msg_ins_company_city, msg_ins_company_st, msg_ins_company_zip, msg_ins_company_country, msg_ins_co_contact_per, /* ZI2 */ 13, msg_zi2_mail_stop, spons_cd, generic_ppl_no, last_addr_seq_no, msg_zi2_plan_name, /* MFI */ 13, "CADD", "UPD", strDate, strDate, "NE", /* MFE */ 13, "MAD", strDate, generic_ppl_no, last_addr_seq_no, /* eom */ 13); /* store the mfn_message */ hl7Msg = (hl7_union_t *) str2mesg(strMsg); if( verbose_level >= 10000 ) { printf("\t\tMFN message:\n"); printmesg(hl7Msg); } if( in1_no == 1 ) mfn_message1 = (hl7_union_t *) copy_mesg(hl7Msg); if( in1_no == 2 ) mfn_message2 = (hl7_union_t *) copy_mesg(hl7Msg); if( in1_no == 3 ) mfn_message3 = (hl7_union_t *) copy_mesg(hl7Msg); if( hl7Msg) freemesg(hl7Msg); /* enable the corresponding TCL flag */ if( in1_no == 1) Tcl_SetVar(interp,"FORWARD_MFN1","1", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); if( in1_no == 2) Tcl_SetVar(interp,"FORWARD_MFN2","1", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); if( in1_no == 3) Tcl_SetVar(interp,"FORWARD_MFN3","1", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); return(0); }/******************** end of create_MFN_message ************************/ /************************************************************************* * function: hl7_format_dt * args: char * * returns: char * to IDD.def HL7_FORMAT_DT or (char )'\0' * usage info: format taken from IDD.def.HL7_FORMAT_DT * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 02-May-2000 * Mod: started. **************************************************************************/ char * hl7_format_dt(char *_OLD) { EXEC SQL BEGIN DECLARE SECTION; char OLD[26]; int _year; /* DATE_PART decodes */ int _month; int _day; int _hour; int _min; int _sec; EXEC SQL END DECLARE SECTION; char *_NEW[26]; /*************************************************************************/ strncpy(OLD,_OLD,25); EXEC SQL SELECT DATE_PART('year', :OLD), DATE_PART('month', :OLD), DATE_PART('day', :OLD), DATE_PART('hour', :OLD), DATE_PART('min', :OLD), DATE_PART('sec', :OLD) INTO :_year, :_month, :_day, :_hour, :_min, :_sec; switch(sqlca.sqlcode) { case 0: sprintf(_NEW,"%04d%02d%02d%02d%02d%02d", _year, _month, _day, _hour, _min, _sec); break; default: _NEW[0] = (char )'\0'; break; } /* switch */ if( verbose_level >= 32768) { sprintf(buf,"\t\thl7_format_dt: got '%s'\n" "\t\t returning '%s' ",_OLD,_NEW); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } return( (char *)_NEW); }/*********************** end of hl7_format_dt **************************/ /************************************************************************* * function: fwd_dates * args: hl7_union_t *fwd_msg * returns: -1 if a fatal error occurred. * usage info: formats dates in fwd message that * are common for several Reg table updates * into IDD.def.HL7_FORMAT_DT * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 08-May-2000 * Mod: * eff_from/thru_dt are now from PAY0R_PLAN * * Programmer: Jeff Martin * Date: 07-May-2000 * Mod: started. **************************************************************************/ int fwd_dates(hl7_union_t *fwd_msg, int SET) { /*************************************************************************/ /* zi2-mcare-b-elig-from-d */ if( strlen(msg_mcare_b_elig_from_d) > 0 && strcmp(msg_mcare_b_elig_from_d,"")) { strHl7_date = (char *) hl7_format_dt(msg_mcare_b_elig_from_d); strncpy(strDate,(strHl7_date ? strHl7_date : ""),25); if( hl7_set(fwd_msg,&ZI2_mcare_b_elig_from_d,in1_no,0,0,0,strDate)) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.4.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } } /* zi2-mcare-b-elig-thru-d */ if( strlen(msg_mcare_b_elig_thru_d) > 0 && strcmp(msg_mcare_b_elig_thru_d,"")) { strHl7_date = (char *) hl7_format_dt(msg_mcare_b_elig_thru_d); strncpy(strDate,(strHl7_date ? strHl7_date : ""),25); if( hl7_set(fwd_msg,&ZI2_mcare_b_elig_thru_d,in1_no,0,0,0, strDate )) { error_notify(__FILE__, __LINE__, "\nCan't set ZI2.5.0.0 in fwd message\n", NOTIFY_FATAL); return(-1); } } /* zi2_cov_eff_from_dt */ strHl7_date = (char *) hl7_format_dt("now"); strncpy(strDate,strHl7_date,25); if( hl7_set(fwd_msg,&ZI2_cov_eff_from_dt,in1_no,0,0,0, strDate )) { sprintf(buf,"\nCan't set ZI2.46.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2_cov_thru_dt */ strHl7_date = (char *) hl7_format_dt(REG_HIGH_DT); strncpy(strDate,strHl7_date,25); if( hl7_set(fwd_msg,&ZI2_cov_eff_thru_dt,in1_no,0,0,0, strDate )) { sprintf(buf,"\nCan't set ZI2.47.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2-plan-rel-eff-date */ strHl7_date = (char *) hl7_format_dt("now"); strncpy(strDate,(strHl7_date ? strHl7_date : ""),25); if( hl7_set(fwd_msg,&ZI2_plan_rel_eff_date,in1_no,0,0,0, strDate )) { sprintf(buf,"\nCan't set ZI2.59.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* zi2-plan-rel-exp-date */ strHl7_date = (char *) hl7_format_dt(REG_HIGH_DT); strncpy(strDate,(strHl7_date ? strHl7_date : ""),25); if( hl7_set(fwd_msg,&ZI2_plan_rel_exp_date,in1_no,0,0,0, strDate )) { sprintf(buf,"\nCan't set ZI2.60.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } /* in1_plan_effect_date */ if( strlen(eff_from_dt) > 0 && strcmp(eff_from_dt,"")) { strHl7_date = (char *) hl7_format_dt(eff_from_dt); strncpy(strDate,(strHl7_date ? strHl7_date : ""),25); if( hl7_set(fwd_msg,&IN1_eff_from_dt,in1_no,0,0,0, strDate )) { sprintf(buf,"\nCan't set IN1.12.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } } /* in1_plan_expire_date */ if( strlen(eff_thru_dt) > 0 && strcmp(eff_thru_dt,"")) { strHl7_date = (char *) hl7_format_dt(eff_thru_dt); strncpy(strDate,(strHl7_date ? strHl7_date : ""),25); if( hl7_set(fwd_msg,&IN1_eff_thru_dt,in1_no,0,0,0, strDate )) { sprintf(buf,"\nCan't set IN1.13.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } } return(0); }/********************** end of fwd_dates ********************************/ /************************************************************************* * function: get_sub_pat_no_dsp * args: none. * returns: -1 * usage info: popluates global msg_sub_pat_no_dsp from pers_syn * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 19-May-2000 * Mod: stolen completely from M. Mahan's * prepareA08_reg.prepare_pers_pat_rel gt1 processing. * The names were changed to protect the guilty. **************************************************************************/ int get_sub_pat_no_dsp() { /*************************************************************************/ error_notify(__FILE__,__LINE__, "\tRunning get_sub_pat_no_dsp()", NOTIFY_UPDATE); /* get the subscriber's internal pat_no to populate zi2-55 */ /* populate with subscriber's pat_no from same hosp as patient */ /* if no subscriber pat_no exists from same hosp, check to see */ /* if other hosp has a pat_no for the subscriber, if none exists */ /* populate with 0 */ if( verbose_level >= VERBOSE_MADDENING ) printf("\n\tSELECT hosp, \n" "\t pat_no,\n" "\t upd_dt\n" "\t FROM pers_syn\n" "\t WHERE person_no = %d\n" "\t AND current_name = 'Y'\n" "\t AND last_name not like 'AACANC%'\n" "\t AND hosp = '%s'\n" "\t AND bypass_rs = 'N'\n" "\t ORDER BY upd_dt DESC\n", msg_sub_person_no, msg_hosp); EXEC SQL REPEATED SELECT hosp, pat_no, upd_dt INTO :msg_sub_hosp, :msg_sub_pat_no, :upd_dt FROM pers_syn WHERE person_no = :msg_sub_person_no AND current_name = 'Y' AND last_name not like 'AACANC%' AND hosp = :msg_hosp AND bypass_rs = 'N' ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode){ case 0: sprintf(msg_sub_pat_no_dsp,"%s%s",msg_sub_hosp,msg_sub_pat_no); sprintf(buf, "\tSubscriber has a patient number at same hosp as patient."); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); break; case 100: sprintf(buf, "\tNo Subscriber patient number at same hosp as patient."); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); sprintf(buf, "\tChecking if Subscriber has a patient number at the\n" "\tother hosp from the patient."); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); if( verbose_level >= VERBOSE_MADDENING) printf("\t SELECT hosp,\n" "\t pat_no,\n" "\t upd_dt\n" "\t FROM pers_syn\n" "\t WHERE person_no = '%d'\n" "\t AND current_name = 'Y'\n" "\t AND last_name not like 'AACANC%'\n" "\t AND hosp <> ''\n" "\t AND hosp is not null\n" "\t AND bypass_rs = 'N'\n" "\t ORDER BY upd_dt DESC\n", msg_sub_person_no); EXEC SQL REPEATED SELECT hosp, pat_no, upd_dt INTO :msg_sub_hosp, :msg_sub_pat_no, :upd_dt FROM pers_syn WHERE person_no = :msg_sub_person_no AND current_name = 'Y' AND last_name not like 'AACANC%' AND hosp <> '' AND hosp is not null AND bypass_rs = 'N' ORDER BY upd_dt DESC; EXEC SQL BEGIN; EXEC SQL ENDSELECT; /* get only the first row retrieved */ EXEC SQL END; switch(sqlca.sqlcode){ case 0: sprintf(msg_sub_pat_no_dsp,"%s%s",msg_sub_hosp,msg_sub_pat_no); sprintf(buf, "Subscriber has a patient number at other hosp as patient."); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); break; case 100: sprintf(buf,"Subscriber has no patient number at either hosp."); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); strcpy(msg_sub_pat_no_dsp,"0"); break; default: sprintf(buf,"get_sub_pat_no_dsp: Can't select against PERS_SYN\n"); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); ingerr(__FILE__, __LINE__, sqlca.sqlcode, NOTIFY_FATAL); return(-1); } break; default: sprintf(buf,"get_sub_pat_no_dsp: Can't select against PERS_SYN\n"); error_notify(__FILE__,__LINE__,buf,NOTIFY_FATAL); ingerr(__FILE__, __LINE__, sqlca.sqlcode, NOTIFY_FATAL); return(-1); } return(0); }/***************** end of get_sub_pat_no_dsp **********************/ /************************************************************************* * function: strip_all_IN1 * args: hl7_union_t *upd_msg, fwd_msg * returns: -1 if a fatal error occured * usage info: calls del_seg.strip_seg on each IN1 segment group * in both upd_msg and fwd_msg. resets all coverage TCL flags. * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 30-Oct-2000 * Mod: clear TCL flag UPD_SUB_PERS_SYN as well or UPDATE mode * aborts hl7_rcv. * **************************************************************************/ int strip_all_IN1(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { /* strip all IN1/IN2/ZI2 from these messages */ in1_count = count_segs(upd_msg, "IN1"); for( in1_no=1; in1_no<=in1_count; in1_no++) { /* del_seg.c */ strip_seg(upd_msg, "IN1", in1_no, 0, 0); strip_seg(upd_msg, "IN2", in1_no, 0, 0); strip_seg(upd_msg, "ZI2", in1_no, 0, 0); strip_seg(fwd_msg, "IN1", in1_no, 0, 0); strip_seg(fwd_msg, "IN2", in1_no, 0, 0); strip_seg(fwd_msg, "ZI2", in1_no, 0, 0); } /* for(in1_no) */ in1_count = 0; /* reset TCL flags */ Tcl_SetVar(interp,"INS_COVERAGE","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_PERS_PLAN_REL","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"INS_SUB_PERS_SYN","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_SUB_PERS_SYN","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_SUB_PATIENT","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"UPD_UNL_PPL","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_CVG1","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_CVG2","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_CVG3","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_MFN1","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_MFN2","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp,"FORWARD_MFN3","0", TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); return(0); }/******************** end of strip_all_IN1 ******************************/ /************************************************************************* * function: validate_addr * args: hl7_union_t *My_upd_msg, *My_fwd_msg * returns: 0 sub addr was not valid * -1 a fatal error occured * 1 sub addr is valid * * usage info: duplicates most patient address validations found in * prepareA08_reg.prepare_pers_addr while attempting * to scrub insurance company address info. * * calls: prepare_msgs_reg.addr_valid() * prepare_msgs_reg.trim_trailing_spaces() * prepare_msgs_reg.city_st_zip_valid() * * HISTORY: * -------- * Programmer: * Date: * Mod: * * Programmer: Jeff Martin * Date: 01-Nov-2000 * Mod: validations have been greatly reduced. * full version code is still there. * * Programmer: Jeff Martin * Date: 27-Mar-2000 * Mod: started. **************************************************************************/ int validate_addr(hl7_union_t *My_upd_msg, hl7_union_t *My_fwd_msg) { EXEC SQL BEGIN DECLARE SECTION; int country_cd_valid; EXEC SQL END DECLARE SECTION; /*************************************************************************/ address_valid = 1; /* quintenscient state is valid */ if( verbose_level >= VERBOSE_MADDENING) error_notify(__FILE__,__LINE__, "\tRunning validate_addr()", NOTIFY_UPDATE); /* allow any address info other than all NULL */ if( strlen(msg_ins_company_addr_1) + strlen(msg_ins_company_addr_2) + strlen(msg_ins_company_city) + strlen(msg_ins_company_st) + strlen(msg_ins_company_zip) + strlen(msg_ins_company_country) == 0 ) { sprintf(buf, "|8000|WARNING: Missing Insurance Company Address Info" "|n/a|PLAN ID %d|%s%s|%s|%d|", msg_plan_id,msg_hosp,msg_pat_no,msg_upd_by,msg_person_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); sprintf(buf, "\tvalidate_addr: stripping IN1, IN2, ZI2 data because\n" "\tinsurance company address in group %d is INVALID.", in1_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); strip_all_IN1(My_upd_msg, My_fwd_msg); address_valid = 0; return(0); } return(1); /* ignore the remaining validations for now */ /* validate msg_sub_addr_1 */ if( strlen(msg_ins_company_addr_1) == 0) { address_valid = 0; error_notify(__FILE__,__LINE__, "\tmsg_ins_company_addr_1 was NULL in message",NOTIFY_UPDATE); } else { if( addr_valid(msg_ins_company_addr_1 ) == 0){ sprintf(buf, "|8000|WARNING: Invalid Data Format|n/a|PERSON %d|addr_1|%s|%s|%d|", msg_person_no, msg_ins_company_addr_1, msg_upd_by,msg_person_no ); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); address_valid = 0; } else { trim_trailing_spaces(msg_ins_company_addr_1); if( hl7_set(My_upd_msg,&IN1_ins_company_addr_1,in1_no, 0,NULL,0,msg_ins_company_addr_1)) { sprintf(buf,"\nCan't set IN1.5.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_addr_1,in1_no, 0,NULL,0,msg_ins_company_addr_1)) { sprintf(buf,"\nCan't set IN1.5.0.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( verbose_level >= 1000) { sprintf(buf,"\tmsg_ins_company_addr_1 in message is valid:\n\t%s", msg_ins_company_addr_1); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } } /* addr_valid */ } /* if( strlen(msg_ins_company_addr_1) */ /* validate msg_ins_company_addr_2 */ if( strlen(msg_ins_company_addr_2) == 0) { error_notify(__FILE__,__LINE__, "\tmsg_ins_company_addr_2 was NULL in message",NOTIFY_UPDATE); } else { if( addr_valid(msg_ins_company_addr_2 ) == 0){ sprintf(buf, "|8000|WARNING: Invalid Data Format|n/a|PERSON %d|addr_2|%s|%s|%d|", msg_person_no, msg_ins_company_addr_2, msg_upd_by,msg_person_no ); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); address_valid = 0; } else { trim_trailing_spaces(msg_ins_company_addr_2); if( hl7_set(My_upd_msg,&IN1_ins_company_addr_2,in1_no, 0,NULL,0,msg_ins_company_addr_2)) { sprintf(buf,"\nCan't set IN1.5.1.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_addr_2,in1_no, 0,NULL,0,msg_ins_company_addr_2)) { sprintf(buf,"\nCan't set IN1.5.1.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( verbose_level >= 10000 ) { sprintf(buf,"\tmsg_ins_company_addr_2 in message is valid:\n\t%s", msg_ins_company_addr_2); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } } /* addr_valid */ } /* if( strlen(msg_ins_company_addr_2) */ /* validate msg_ins_company_city */ if( strlen(msg_ins_company_city) == 0) { error_notify(__FILE__,__LINE__, "\tmsg_ins_company_city was NULL in message",NOTIFY_UPDATE); } else { trim_trailing_spaces(msg_ins_company_city); if( hl7_set(My_upd_msg,&IN1_ins_company_city,in1_no, 0,NULL,0,msg_ins_company_city)) { sprintf(buf,"\nCan't set IN1.5.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_city,in1_no, 0,NULL,0,msg_ins_company_city)) { sprintf(buf,"\nCan't set IN1.5.2.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( verbose_level >= 10000 ) { sprintf(buf,"\tmsg_ins_company_city in message is valid:\n\t%s", msg_ins_company_city); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } } /* if( strlen(msg_ins_company_city) */ /* validate msg_ins_company_st */ if( strlen(msg_ins_company_st) == 0) { error_notify(__FILE__,__LINE__, "\tmsg_ins_company_st was NULL in message",NOTIFY_UPDATE); } /* validate msg_ins_company_country */ if( strlen(msg_ins_company_country) == 0) { error_notify(__FILE__,__LINE__, "\tmsg_ins_company_country was NULL in message", NOTIFY_UPDATE); } else { if( verbose_level >= VERBOSE_MADDENING) printf("SELECT 1\n" "FROM COUNTRY\n" "WHERE country_cd = '%s'\n",msg_ins_company_country); EXEC SQL REPEATED SELECT 1 into :country_cd_valid FROM COUNTRY WHERE country_cd = :msg_ins_company_country; switch(sqlca.sqlcode){ case 0: if( verbose_level >= 10000 ) { sprintf(buf,"\tmsg_ins_company_country_cd in msg is valid:\n\t%s", msg_ins_company_country); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } break; case 100: address_valid = 0; sprintf(buf, "|8000|WARNING: Invalid Code|n/a|PERSON %d" "|country_cd|%s|%s|%d|", msg_person_no,msg_ins_company_country, msg_upd_by,msg_person_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); break; default: printf("\nCan't select against COUNTRY\n"); ingerr(__FILE__, __LINE__, sqlca.sqlcode, NOTIFY_FATAL); return(-1); } /* switch */ } /* if( strlen(msg_sub_country_cd) == 0) */ /* valdate city, state, zip if USA */ if( !strlen(msg_ins_company_country) || !strcmp(msg_ins_company_country,"USA")) { if( !city_st_zip_valid( msg_ins_company_city, msg_ins_company_st, msg_ins_company_zip )) { sprintf(buf, "\t'%s' '%s'\n\t'%s' '%s'\nis NOT valid", msg_ins_company_city, msg_ins_company_st, msg_ins_company_zip, msg_ins_company_country); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); address_valid = 0; /* format an exception record if all fields are not empty */ if( strlen(msg_ins_company_city) + strlen(msg_ins_company_st) + strlen(msg_ins_company_zip) > 0) { sprintf(buf, "|8000|WARNING: Invalid Code|n/a|PERSON %d|City/State/Zip" "|%s/%s/%s|%s|%d|", msg_person_no,msg_ins_company_city,msg_ins_company_st, msg_ins_company_zip, msg_upd_by,msg_person_no); error_notify(__FILE__,__LINE__,buf,NOTIFY_WARNING); } } /* city_st_zip_valid() */ } /* !strcmp(msg_ins_company_country,"USA") */ /* set default country code */ if( !strlen(msg_ins_company_country) && address_valid ) { if( hl7_set(My_upd_msg,&IN1_ins_company_country,in1_no, 0,NULL,0,"USA")) { sprintf(buf,"\nCan't set IN1.5.5.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_country,in1_no, 0,NULL,0,"USA")) { sprintf(buf,"\nCan't set IN1.5.5.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } strcpy(msg_ins_company_country,"USA"); if( verbose_level >= 10000 ) error_notify(__FILE__,__LINE__, "\tSET msg_ins_company_country = USA",NOTIFY_UPDATE); } /* if( strlen(msg_ins_company_country) == 0) */ /* not USA, blank state field */ if( strcmp(msg_ins_company_country,"USA") && address_valid ) { if( strlen(msg_ins_company_st)) { if( hl7_set(My_upd_msg,&IN1_ins_company_st,in1_no, 0,NULL,0,NULL)) { sprintf(buf,"\nCan't set IN1.5.3.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_st,in1_no, 0,NULL,0,NULL)) { sprintf(buf,"\nCan't set IN1.5.3.0 segment %d\n",in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } msg_ins_company_st[0] = '\0'; error_notify(__FILE__,__LINE__, "\tSET foreign msg_ins_company_st = NULL",NOTIFY_UPDATE); } /* if( strlen(msg_ins_company_st) */ } /* strcmp(msg_ins_company_country,"USA") && address_valid */ /* set all ins_company address fields to NULL if not valid */ if( !address_valid) { if( hl7_set(My_upd_msg,&IN1_ins_company_addr_1,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.0.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_addr_1,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.0.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_upd_msg,&IN1_ins_company_addr_2,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.1.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_addr_2,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.1.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_upd_msg,&IN1_ins_company_city,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.2.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_city,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.2.0 segment %d fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_upd_msg,&IN1_ins_company_st,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.3.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_st,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.3.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_upd_msg,&IN1_ins_company_zip,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.4.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_zip,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.4.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_upd_msg,&IN1_ins_company_country,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.5.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(My_fwd_msg,&IN1_ins_company_country,in1_no,0,NULL,0,NULL) ) { sprintf(buf,"\nCan't set IN1.5.5.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } error_notify(__FILE__,__LINE__, "\tSET ins company address fields = NULL",NOTIFY_UPDATE); } /* if( !address_valid) */ else { if( verbose_level >= 10000 ) { sprintf(buf, "\tmsg_ins_company_city (%s), msg_ins_company_st (%s)\n" "\tmsg_ins_company_zip (%s)," " msg_ins_company_country (%s) is valid\n", msg_ins_company_city, msg_ins_company_st, msg_ins_company_zip, msg_ins_company_country); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } } return(address_valid); }/******************* end of validate_addr *******************************/ /************************************************************************* * function: fix_medicaid_dates * args: hl7_union_t *upd_msg, *fwd_msg * returns: (char *) to Ingres formatted date. * * usage info: * * HISTORY: * -------- * Programmer: * Date: * Mod: ***************************************************************************/ int fix_medicaid_dates(hl7_union_t *upd_msg, hl7_union_t *fwd_msg) { EXEC SQL BEGIN DECLARE SECTION; int _year; int _month; int _day; EXEC SQL END DECLARE SECTION; char *c43, *c44; /*************************************************************************/ /* decode message data */ c43=c44=(char )'\0'; c43 = (char *) hl7_get(upd_msg, &ZI2_mcaid_1st_elg_dt, 1, 0, NULL, 0, 0); strncpy(msg_mcaid_1st_elig_d, ( c43 ? c43 : "now"),25); c44 = (char *) hl7_get(upd_msg, &ZI2_mcaid_elg_thru_dt, 1, 0, NULL, 0, 0); strncpy(msg_mcaid_elig_thru_d, ( c44 ? c44 : ""),25); /* implement medicaid eff date rules */ if( !strlen(msg_mcaid_elig_thru_d) || !strncmp(msg_mcaid_1st_elig_d,"now",3)) { msg_mcaid_elig_thru_d[0]=(char )'\0'; /* parse msg_mcaid_1st_elig_d */ EXEC SQL SELECT DATE_PART('year', :msg_mcaid_1st_elig_d), DATE_PART('month', :msg_mcaid_1st_elig_d), DATE_PART('day', :msg_mcaid_1st_elig_d) INTO :_year, :_month, :_day; switch(sqlca.sqlcode) { case 0: sprintf(msg_mcaid_1st_elig_d,"%04d%02d%02d", _year, _month, _day); /* populate eff thru dt */ switch(_month) { case 02: /* leap year ignorant */ sprintf(msg_mcaid_elig_thru_d,"%04d%02d%02d", _year, _month, 28); break; /* FEB */ case 04: sprintf(msg_mcaid_elig_thru_d,"%04d%02d%02d", _year, _month, 30); break; case 06: sprintf(msg_mcaid_elig_thru_d,"%04d%02d%02d", _year, _month, 30); break; case 09: sprintf(msg_mcaid_elig_thru_d,"%04d%02d%02d", _year, _month, 30); break; case 11: sprintf(msg_mcaid_elig_thru_d,"%04d%02d%02d", _year, _month, 30); break; default: sprintf(msg_mcaid_elig_thru_d,"%04d%02d%02d", _year, _month, 31); break; /* the rest */ } /* switch(_month) */ /* store new values in messages */ if( hl7_set(upd_msg,&ZI2_mcaid_1st_elg_dt,in1_no, 0,NULL,0,msg_mcaid_1st_elig_d) ) { sprintf(buf,"\nCan't set ZI2.9.0.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_mcaid_1st_elg_dt,in1_no, 0,NULL,0,msg_mcaid_1st_elig_d) ) { sprintf(buf,"\nCan't set ZI2.9.0.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(upd_msg,&ZI2_mcaid_elg_thru_dt,in1_no, 0,NULL,0,msg_mcaid_elig_thru_d) ) { sprintf(buf,"\nCan't set ZI2.10.0.0 segment %d in upd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } if( hl7_set(fwd_msg,&ZI2_mcaid_elg_thru_dt,in1_no, 0,NULL,0,msg_mcaid_elig_thru_d) ) { sprintf(buf,"\nCan't set ZI2.10.0.0 segment %d in fwd msg\n", in1_no); error_notify(__FILE__, __LINE__,buf,NOTIFY_FATAL); return(-1); } break; /* sqlca.sqlcode==0 */ default: if( verbose_level >= VERBOSE_MADDENING ) { sprintf(buf,"'%s' is not a valid Ingres date", msg_mcaid_1st_elig_d); error_notify(__FILE__,__LINE__,buf,NOTIFY_UPDATE); } msg_mcaid_elig_thru_d[0]=msg_mcaid_1st_elig_d[0]=(char )'\0'; break; } /* switch */ }/* medicaid eff date rules */ return(0); } /*******************************************************************/