insert into "ChargeCategory" ("Active","ChargeCategoryName","CreatedBy","CreatedDate")
values (true,'InPatient',1029,now());

----------

alter table "LocationLabHeaderMap" drop column if exists "InPatientCharge";

delete from "LocationLabHeaderMap";
--LabHeader Charges
with generalChargeData as (
select "LabHeaderId","Charge","Active","CreatedBy","CreatedDate","ModifiedBy","ModifiedDate" from "LabHeader" where "Charge" is not null and "Charge" >= 0
)
insert into "LocationLabHeaderMap" ("LocationId","LabHeaderId","Charge","IsActive","CreatedBy","CreatedDate","ModifiedBy","ModifiedDate","ChargeCategoryId")
select 4 as "LocationId",GC."LabHeaderId",GC."Charge",GC."Active", GC."CreatedBy",GC."CreatedDate",GC."ModifiedBy",GC."ModifiedDate",
(select "ChargeCategoryId" from "ChargeCategory" where "ChargeCategoryName" = 'General') as "ChargeCategoryId"
from generalChargeData GC;

--- For INPatient charge
with inPatientChargeData as (
select "LabHeaderId","InPatientCharge" ,"Active","CreatedBy","CreatedDate","ModifiedBy","ModifiedDate" from "LabHeader" 
   where "InPatientCharge" is not null and "InPatientCharge" > 0
)
insert into "LocationLabHeaderMap" ("LocationId","LabHeaderId","Charge","IsActive","CreatedBy","CreatedDate","ModifiedBy","ModifiedDate","ChargeCategoryId")
select 4 as "LocationId",GC."LabHeaderId",GC."InPatientCharge",GC."Active", GC."CreatedBy",GC."CreatedDate",GC."ModifiedBy",GC."ModifiedDate",
(select "ChargeCategoryId" from "ChargeCategory" where "ChargeCategoryName" = 'InPatient') as "ChargeCategoryId"
from inPatientChargeData GC;
------ Lab Header Charges completed.