        end;
        if existingEncounterNum is not  null then 
             execute immediate ' update ' || tempEidTableName ||' set encounter_num = :x , process_status_flag = ''P''
-            where encounter_id = :y and not exists (select 1 from encounter_mapping em where em.encounter_ide = encounter_map_id
-        and em.encounter_ide_source = encounter_map_id_source)' using existingEncounterNum, disEncounterId;
+            where encounter_id = :y and encounter_id_source = :z and not exists (select 1 from encounter_mapping em where em.encounter_ide = encounter_map_id
+        and em.encounter_ide_source = encounter_map_id_source)' using existingEncounterNum, disEncounterId, disEncounterIdSource;
        else 
 
             maxEncounterNum := maxEncounterNum + 1 ;

        execute immediate ' update ' || tempPidTableName ||' set patient_num = patient_id, process_status_flag = ''P'' where 
        patient_id = :x and patient_id_source = ''HIVE'' and not exists (select 1 from patient_mapping pm where pm.patient_ide = patient_map_id
        and pm.patient_ide_source = patient_map_id_source)' using disPatientId;
   end if;    
    
   -- test if record fectched
   -- dbms_output.put_line(' HIVE ');

    end;
   if existingEncounterNum is not null then 
        execute immediate ' update ' || tempEidTableName ||' set encounter_num = encounter_id, process_status_flag = ''P''
        where encounter_id = :x and encounter_id_source = ''HIVE'' and not exists (select 1 from encounter_mapping em where em.encounter_ide = encounter_map_id
        and em.encounter_ide_source = encounter_map_id_source)' using disEncounterId;
	
   else 
