--This script will help you back up, and remove invalid NDC / CPT4 code pairings.
--For example NDC 1234, should not be attached to office visit code 99213 you would put those values below, then back them up and delete them from the table.
--so long as that set appears in ndc_mstr then when that cpt is used the software will try to attach that NDC.
select * from ndc_mstr
where ndc_id = '' --NDC code here
and cpt4_code_id = '' -- CPT4 its pairing up with here
select * into ndc_mstr_bkup_datehere from ndc_mstr
--back up the table
--delete the invalid data
delete from ndc_mstr
where ndc_id = '' --NDC code here
and cpt4_code_id = '' -- CPT4 its pairing up with here
--finally we must also check if the bad pair exists in the patient_procedures that are in the holding tank currently, if they try to import in with that pair
--the pair will be repopulated back into the NDC_mstr we just fixed.
select * from patient_procedure
where uniq_id in (select uniq_id from pending_charge)--this procedure is in the holding tank
and national_drug_code = ''--NDC code here
and cpt4_code_id = '' --cpt4 code here
select * into patient_procedure_bkup_datehere from patient_procedure
--back up the table
--set the NDC to null so we don't repopulate the pairing in the NDC mstr.
update patient_procedure
set national_drug_code = null
where uniq_id in (select uniq_id from pending_charge)--this procedure is in the holding tank
and national_drug_code = ''--NDC code here
and cpt4_code_id = '' --cpt4 code here