Commit e1c9a299 authored by Sandeep Sagar Panjala's avatar Sandeep Sagar Panjala

initial commit

parent 9b14a52b
ALTER TABLE public."Appointment"
ADD COLUMN "QueueStatusId" integer DEFAULT 4;
ALTER TABLE public."Appointment"
ADD CONSTRAINT "FK_Appointment_QueueStatusId" FOREIGN KEY ("QueueStatusId")
REFERENCES public."QueueStatus" ("QueueStatusId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
-- Table: public.PackageModule
-- DROP TABLE IF EXISTS public."PackageModule";
create sequence "PackageModule_PackageIdModule_Seq"
CREATE TABLE IF NOT EXISTS public."PackageModule"
(
"PackageModuleId" integer NOT NULL DEFAULT nextval('"PackageModule_PackageIdModule_Seq"'::regclass),
"PackageName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"LocationId" integer NOT NULL,
"ChargeModuleTemplateId" integer NOT NULL,
"ChargeCategoryId" integer NOT NULL,
"ChargeModuleCategoryIds" text COLLATE pg_catalog."default" NOT NULL,
"ModulesMasterIds" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL DEFAULT now(),
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"SubTotal" numeric(8,2) NOT NULL,
"DiscountPerc" numeric(4,2),
"Discount" numeric(8,2),
"Total" numeric(8,2) NOT NULL,
"Notes" character varying(250) COLLATE pg_catalog."default",
"PackageType" character varying(2) COLLATE pg_catalog."default" NOT NULL,
"Quantity" numeric(4,0) NOT NULL,
CONSTRAINT "PK_Package_PackageId" PRIMARY KEY ("PackageModuleId"),
CONSTRAINT "FK_PackageModule_ChargeCategoryId" FOREIGN KEY ("ChargeCategoryId")
REFERENCES public."ChargeCategory" ("ChargeCategoryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_PackageModule_ChargeModuleTemplateId" FOREIGN KEY ("ChargeModuleTemplateId")
REFERENCES public."ChargeModuleTemplate" ("ChargeModuleTemplateId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."PackageModule"
OWNER to postgres;
------------------------------------------------------------------------------------------------------------------------
-- Table: public.PackageModuleDetail
-- DROP TABLE IF EXISTS public."PackageModuleDetail";
create sequence "PackageModuleDetail_PackageIdModuleDetail_Seq"
CREATE TABLE IF NOT EXISTS public."PackageModuleDetail"
(
"PackageModuleDetailId" integer NOT NULL DEFAULT nextval('"PackageModuleDetail_PackageIdModuleDetail_Seq"'::regclass),
"PackageModuleId" integer NOT NULL,
"ChargeModuleDetailsId" bigint,
"Amount" numeric(8,2) NOT NULL,
"ChargeModuleCategoryId" integer,
"ModulesMasterId" integer,
"Quantity" smallint NOT NULL DEFAULT 1,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" numeric NOT NULL,
"CreatedDate" time without time zone NOT NULL DEFAULT now(),
"ModifiedBy" numeric,
"ModifiedDate" time without time zone,
"IsFree" boolean NOT NULL DEFAULT false,
CONSTRAINT "PackageModuleDetail_pkey" PRIMARY KEY ("PackageModuleDetailId"),
CONSTRAINT "FK_PackageModuleDetail_ChargeModuleDetailId" FOREIGN KEY ("ChargeModuleDetailsId")
REFERENCES public."ChargeModuleDetails" ("ChargeModuleDetailsId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "FK_PackageModuleDetail_PackageModuleId" FOREIGN KEY ("PackageModuleId")
REFERENCES public."PackageModule" ("PackageModuleId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
NOT VALID
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."PackageModuleDetail"
OWNER to postgres;
\ No newline at end of file
CREATE SEQUENCE public."ChargeCategory_ChargeCategoryId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ChargeCategory_ChargeCategoryId_seq"
OWNER TO postgres;
-------------------------------------------------------------------------------
-- Table: public.ChargeCategory
-- DROP TABLE public."ChargeCategory";
CREATE TABLE public."ChargeCategory"
(
"ChargeCategoryId" integer NOT NULL DEFAULT nextval('"ChargeCategory_ChargeCategoryId_seq"'::regclass),
"LocationId" integer,
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"ChargeCategoryName" character varying COLLATE pg_catalog."default",
CONSTRAINT "ChargeCategory_pkey" PRIMARY KEY ("ChargeCategoryId"),
CONSTRAINT "ChargeCategory_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ChargeCategory_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ChargeCategory_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ChargeCategory"
OWNER to postgres;
------------------------------------------------------------------------------------------------------
CREATE SEQUENCE public."ScanTestMaster_ScanTestMasterId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ScanTestMaster_ScanTestMasterId_seq"
OWNER TO postgres;
--------------------------------------------------------------------------------------------------------
-- Table: public.ScanTestMaster
-- DROP TABLE public."ScanTestMaster";
CREATE TABLE public."ScanTestMaster"
(
"ScanTestMasterId" bigint NOT NULL DEFAULT nextval('"ScanTestMaster_ScanTestMasterId_seq"'::regclass),
"ScanTestName" character varying(250) COLLATE pg_catalog."default" NOT NULL,
"ScanTestCode" character varying COLLATE pg_catalog."default" NOT NULL,
"Description" character varying(500) COLLATE pg_catalog."default",
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
"Duration" smallint,
CONSTRAINT "PK_ScanTestMaster_ScanTestMasterId" PRIMARY KEY ("ScanTestMasterId"),
CONSTRAINT "FK_ScanTestMaster_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_ScanTestMaster_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanTestMaster"
OWNER to postgres;
------------------------------------------------------------------------------------------------------------------------------------------
CREATE SEQUENCE public."LocationScanTestMasterMap_LocationScanTestMasterMapId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."LocationScanTestMasterMap_LocationScanTestMasterMapId_seq"
OWNER TO postgres;
----------------------------------------------------------------------------------------------------------
-- Table: public.LocationScanTestMasterMap
-- DROP TABLE public."LocationScanTestMasterMap";
CREATE TABLE public."LocationScanTestMasterMap"
(
"LocationScanTestMasterMapId" bigint NOT NULL DEFAULT nextval('"LocationScanTestMasterMap_LocationScanTestMasterMapId_seq"'::regclass),
"LocationId" integer NOT NULL,
"ScanTestMasterId" integer NOT NULL,
"Amount" numeric NOT NULL,
"ChargeCategoryId" integer NOT NULL,
CONSTRAINT "LocationScanTestMasterMap_pkey" PRIMARY KEY ("LocationScanTestMasterMapId"),
CONSTRAINT "LocationScanTestMasterMap_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "LocationScanTestMasterMap_ScanTestMaster_fkey" FOREIGN KEY ("ScanTestMasterId")
REFERENCES public."ScanTestMaster" ("ScanTestMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."LocationScanTestMasterMap"
OWNER to postgres;
---------------------------------------------------------------------------------------------
CREATE SEQUENCE public."ScanMachineMaster_ScanMachineMasterId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ScanMachineMaster_ScanMachineMasterId_seq"
OWNER TO postgres;
-----------------------------------------------------------------------------------------------------
-- Table: public.ScanMachineMaster
-- DROP TABLE public."ScanMachineMaster";
CREATE TABLE public."ScanMachineMaster"
(
"ScanMachineMasterId" bigint NOT NULL DEFAULT nextval('"ScanMachineMaster_ScanMachineMasterId_seq"'::regclass),
"MachineName" character varying COLLATE pg_catalog."default",
"DisplayName" character varying COLLATE pg_catalog."default",
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp(6) without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "ScanMachineMaster_pkey" PRIMARY KEY ("ScanMachineMasterId"),
CONSTRAINT "ScanMachineMaster_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanMachineMaster_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanMachineMaster"
OWNER to postgres;
-------------------------------------------------------------------------------------------------------------------------------------
CREATE SEQUENCE public."ScanMachineTestMap_ScanMachineTestMapId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ScanMachineTestMap_ScanMachineTestMapId_seq"
OWNER TO postgres;
-------------------------------------------------------------------------------------------------------------------------
-- Table: public.ScanMachineTestMap
-- DROP TABLE public."ScanMachineTestMap";
CREATE TABLE public."ScanMachineTestMap"
(
"ScanMachineTestMapId" bigint NOT NULL DEFAULT nextval('"ScanMachineTestMap_ScanMachineTestMapId_seq"'::regclass),
"ScanMachineMasterId" integer NOT NULL,
"ScanTestMasterId" integer NOT NULL,
"LocationId" integer NOT NULL,
CONSTRAINT "ScanMachineTestMap_pkey" PRIMARY KEY ("ScanMachineTestMapId"),
CONSTRAINT "ScanMachineTestMap_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanMachineTestMap_ScanMachineMasterId_fkey" FOREIGN KEY ("ScanMachineMasterId")
REFERENCES public."ScanMachineMaster" ("ScanMachineMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanMachineTestMap_ScanTestMasterId_fkey" FOREIGN KEY ("ScanTestMasterId")
REFERENCES public."ScanTestMaster" ("ScanTestMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanMachineTestMap"
OWNER to postgres;
\ No newline at end of file
UPDATE "Clients" SET "IdentityTokenLifetime" = 86400, "AccessTokenLifetime" = 259200, "AuthorizationCodeLifetime" = 86400;
\ No newline at end of file
-- FUNCTION: public.widget_Table_FollowUpAppointment(date, integer, integer)
DROP FUNCTION IF EXISTS public."widget_Table_FollowUpAppointment"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_FollowUpAppointment"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation", Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM')
from "Appointment" apt
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
where apt."AppointmentDate"::date="fromDate" and apt."VisitTypeId" =10
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_FollowUpAppointment"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Table_NewAppointment(date, integer, integer)
DROP FUNCTION IF EXISTS public."widget_Table_NewAppointment"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_NewAppointment"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",--Pr."FullName" as "ProviderName",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM')
from "Appointment" apt
--left join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
left join "Patient" Pa on Pa."PatientId" = apt."PatientId"
left join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and apt."VisitTypeId" <>10
and case when "referenceId" is null then 1=1 else apt."ProviderId"="referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
--LIMIT 10 offset 0
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_NewAppointment"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Table_NewPatientAppointment(date, integer, integer)
DROP FUNCTION IF EXISTS public."widget_Table_NewPatientAppointment"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_NewPatientAppointment"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM')
from "Appointment" apt
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and apt."VisitTypeId" =43
and Pa."CreatedDate"::date="fromDate" and Pa."Active" is true
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
-- select * from "AppointmentType";
-- select * from "VisitType"
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_NewPatientAppointment"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Table_PharmacyRetailStockProducts_ExpiryInMonths(date, integer, text)
DROP FUNCTION IF EXISTS public."widget_Table_PharmacyRetailStockProducts_ExpiryInMonths"(date, integer, text);
CREATE OR REPLACE FUNCTION public."widget_Table_PharmacyRetailStockProducts_ExpiryInMonths"(
"selectDate" date DEFAULT NULL::date,
"locationId" integer DEFAULT NULL::integer,
"retailStore" text DEFAULT NULL::text)
RETURNS TABLE("ProductName" character varying, "GenericName" text, "RetailName" text, "BatchNumber" character varying, "ExpiryDate" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
SELECT
PP."ProductName",
PP."GenericName",
RP."RetailName",
PS."BatchNumber",
TO_CHAR(PS."ExpiryDate",'Mon yyyy')
FROM
"PharmacyRetailStock" PS
JOIN "RetailWareHouseLink" PWL ON PWL."RetailWareHouseLinkId" = PS."RetailWareHouseLinkId"
JOIN "PharmacyWareHouse" PW ON PW."PharmacyWareHouseId" = PWL."PharmacyWareHouseId"
JOIN "RetailPharmacy" RP ON RP."RetailPharmacyId" = PWL."RetailPharmacyId"
JOIN "PharmacyProduct" PP ON PP."PharmacyProductId" = PS."PharmacyProductId"
WHERE
(PS."QuantityIn" - PS."QuantityOut") <> 0
and case when "retailStore" is null then 1=1 else RP."RetailName"="retailStore" end
AND case when "selectDate" is null then 1=1 else PS."ExpiryDate" <="selectDate"::date end
AND case when "locationId" is null then 1=1 else PW."LocationId" = "locationId" end
order by PS."ExpiryDate"
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_PharmacyRetailStockProducts_ExpiryInMonths"(date, integer, text)
OWNER TO postgres;
ALTER TABLE "PharmacyProduct" ALTER COLUMN "GenericName" type text;
----------------------------------------------------------------------------------------------------------------------
-- FUNCTION: public.widget_Table_PharmacyRetailStockProducts_UnderROL(integer, integer, text);
DROP FUNCTION IF EXISTS public."widget_Table_PharmacyRetailStockProducts_UnderROL"(integer, integer, text);
CREATE OR REPLACE FUNCTION public."widget_Table_PharmacyRetailStockProducts_UnderROL"(
"accountId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"retailStore" text DEFAULT NULL::text)
RETURNS TABLE("ProductName" character varying, "GenericName" text, "ROL" integer, "RetailName" text, "AvailableQty" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select * from ( SELECT
PP."ProductName",
PP."GenericName",
PPD."ROL",
rp."RetailName", SUM(PS."QuantityIn") -sum(PS."QuantityOut") as "AvailableQty"
FROM "PharmacyRetailStock" PS
join "PharmacyProduct" PP on PP."PharmacyProductId" = PS."PharmacyProductId"
join "RetailWareHouseLink" rwhl ON rwhl."RetailWareHouseLinkId" = PS."RetailWareHouseLinkId"
join "RetailPharmacy" rp on rp."RetailPharmacyId" = rwhl."RetailPharmacyId"
join "PharmacyWareHouse" pwh on pwh."PharmacyWareHouseId" = rwhl."PharmacyWareHouseId"
join "PharmacyProductDetail" PPD on PPD."PharmacyProductId" = PS."PharmacyProductId" and PPD."ROL" is not null
left JOIN "PharmacyRetailUser" PRU ON PRU."RetailPharmacyId"=RP."RetailPharmacyId"
WHERE
(PS."QuantityIn" - PS."QuantityOut") > 0 and
case when "retailStore" is null then 1=1 else RP."RetailName"="retailStore" end
AND case when "accountId" is null then 1=1 else PRU."AccountId"="accountId" end and
case when "locationId" is null then 1=1 else pwh."LocationId" = "locationId" end
group by PP."ProductName",PP."GenericName",rp."RetailName",PPD."ROL",PRU."AccountId")a
where A."ROL" >= A."AvailableQty"
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_PharmacyRetailStockProducts_UnderROL"(integer, integer, text)
OWNER TO postgres;
---------------------------------------------------------------------------------------------------------------------------------------------------------------
-- FUNCTION: public.widget_Table_WalkinAppointment(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_WalkinAppointment"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_WalkinAppointment"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM')
from "Appointment" apt
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
where
apt."AppointmentDate"::date="fromDate" and apt."Active" is true and apt."VisitTypeId" =9
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_WalkinAppointment"(date, integer, integer)
OWNER TO postgres;
\ No newline at end of file
alter table "PharmacyStore" add column "LocationId" int references "Location"("LocationId");
\ No newline at end of file
update "TelemedicineDomain" set "Domain"='conference.virtualsteth.com' where "Domain"='connect.virtualsteth.com'
\ No newline at end of file
DROP FUNCTION IF EXISTS public."widget_GetPharmacySaleAmountByDate"(date);
DROP FUNCTION IF EXISTS public."widget_Chart_Lab_Revenue"(text, date, text, integer);
DROP FUNCTION IF EXISTS public."widget_BarChart_Lab_Revenue"(date, text, integer);
DROP FUNCTION IF EXISTS public."widget_PieChart_Lab_Revenue"(date, text);
DROP FUNCTION IF EXISTS public."widget_Chart_Pharmacy_Sale_Revenue"(text, date, text, integer);
DROP FUNCTION IF EXISTS public."widget_BarChart_Pharmacy_Sale_Revenue"(date, text, integer);
DROP FUNCTION IF EXISTS public."widget_PieChart_Pharmacy_Sale_Revenue"(date, text);
DROP FUNCTION IF EXISTS public."widget_Chart_Appointment_Revenue"(text, date, text, integer);
DROP FUNCTION IF EXISTS public."widget_BarChart_Appointment_Revenue"(date, text, integer);
DROP FUNCTION IF EXISTS public."widget_PieChart_Appointment_Revenue"(date, text);
DROP FUNCTION IF EXISTS public."widget_Chart_OverAllRevenue"(text, date, text, integer);
DROP FUNCTION IF EXISTS public."widget_BarChart_OverAllRevenue"(date, text, integer);
DROP FUNCTION IF EXISTS public."widget_PieChart_OverAllRevenue"(date, text);
DROP FUNCTION IF EXISTS public."widget_Chart_Pharmacy_LowSellingProducts"(text, date, text, integer);
DROP FUNCTION IF EXISTS public."widget_BarChart_Pharmacy_LowSellingProducts"(date, text, integer);
DROP FUNCTION IF EXISTS public."widget_PieChart_Pharmacy_LowSellingProducts"(date, text);
-- FUNCTION: public.widget_BarChart_Appointment_Revenue(date, text, integer,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_BarChart_Appointment_Revenue"(date, text, integer,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_BarChart_Appointment_Revenue"(
"fromDate" date,
"filterType" text,
"displayCount" integer,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
filtervalue interval;
intervaldata interval;
fromdate date;
begin
create Temp TABLE temp_table
( appointmentdate date,
appointmentamount numeric
) ON COMMIT DELETE ROWS;
filtervalue= "displayCount"||' '|| "filterType";
intervaldata= '1 '|| "filterType";
raise notice ' %', filtervalue;
--fromdate:=case when "filterType"='day' then "fromDate"
--else date_trunc('month', "fromDate"::date) end;
for f in SELECT generate_series("fromDate" - filtervalue , "fromDate" + filtervalue, intervaldata) weeks
loop
insert into temp_table (appointmentdate,appointmentamount)
with actappointmentamount as (
select A.appointmentamount::bigint appointmentamount from (
select sum(coalesce(AP."Total",0)) appointmentamount
from "Appointment" ap
--left join "Provider" pr on pr."ProviderId"= ap."ProviderId" and ap."Active" =true
--left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
--left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where ap."Status" <> 'C'
and (Ap."AppointmentDate" >= f.weeks::text::date and Ap."AppointmentDate" < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else AP."LocationId"= "locationId" end
--and case when ("referenceId" is null) or ("referenceId"=0) then 1=1 else PA."ReferenceId"= "referenceId" end
)a
)
select f.weeks,coalesce((select (coalesce(appointmentamount,0)) :: numeric as "AppointmentAmount"
from actappointmentamount A),0) ;
end loop;
RETURN QUERY
select A.appointmentdate,A.appointmentamount from temp_table A;
drop table temp_table;
END;
$BODY$;
ALTER FUNCTION public."widget_BarChart_Appointment_Revenue"(date, text, integer,integer,integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.widget_Chart_Appointment_Revenue(text, date, text, integer,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_Chart_Appointment_Revenue"(text, date, text, integer,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_Chart_Appointment_Revenue"(
"chartType" text,
"fromDate" date,
"filterType" text,
"displayCount" integer DEFAULT NULL::integer,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
DECLARE
sql text := 'select "Date", "Count"::numeric from ';
BEGIN
IF "chartType"='Bar' THEN
sql := sql || '"widget_BarChart_Appointment_Revenue"('''||"fromDate"||''','''||"filterType"||''', '''||"displayCount"||''','''||coalesce("referenceId",0)||''','''||coalesce("locationId",0)||''')';
ELSE
sql := sql || '"widget_PieChart_Appointment_Revenue"('''||"fromDate"||''','''||"filterType"||''','''||coalesce("referenceId",0)||''','''||coalesce("locationId",0)||''')';
END IF;
raise notice 'query %', sql;
RETURN QUERY EXECUTE sql
;
END
$BODY$;
ALTER FUNCTION public."widget_Chart_Appointment_Revenue"(text, date, text, integer,integer,integer)
OWNER TO postgres;
select * from "widget_Chart_Appointment_Revenue"('Pie','2022-09-01','day',2,null,5)
\ No newline at end of file
-- FUNCTION: public.widget_PieChart_Appointment_Revenue(date, text,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_PieChart_Appointment_Revenue"(date, text,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_PieChart_Appointment_Revenue"(
"fromDate" date,
"filterType" text,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
intervaldata interval;
ftype text;
currentdate date;
fromdate date;
begin
intervaldata:= case when "filterType"='day' then '1 D' when "filterType"='month' then '1 Month' when "filterType"='year' then '1 Year' end;
ftype:= case when "filterType"='day' then 'month'::text when "filterType"='month' then 'year'::text when "filterType"='year' then 'year'::text end;
currentdate:= case when "filterType"='year' then date_trunc(ftype, "fromDate") - '2 Y'::interval else date_trunc(ftype, "fromDate") end ;
fromdate:=case when "filterType"='day' and current_date > "fromDate" then (date_trunc('month', "fromDate"::date) + interval '1 month' - interval '1 day')::date
when "filterType"='month' and "fromDate" < current_date then date_trunc('Year', "fromDate"::date) + interval '1 Year' - interval '1 month'
else "fromDate" end;
raise notice 'intervaldata %', intervaldata;
raise notice 'ftype %', ftype;
raise notice 'currentdate %', currentdate;
create Temp TABLE temp_table
( startdate date,
enddate date,
countdata numeric
) ON COMMIT DELETE ROWS;
create Temp TABLE temp_date_table
( startdate date,
enddate date
) ON COMMIT DELETE ROWS;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
insert into temp_date_table (startdate,enddate)
select f.weeks::text::date ,(f.weeks+ intervaldata)::text::date ;
--raise notice 'datetable %', f.weeks::text::date;
end loop;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
--raise notice 'currentdate %', f.weeks::text::date;
--raise notice 'fromdate %', fromdate::date;
insert into temp_table (startdate,enddate,countdata)
with actappointmentamount as (
select A.appointmentamount::bigint appointmentamount from (
select sum(coalesce(AP."Total",0)) appointmentamount
from "Appointment" ap
--left join "Provider" pr on pr."ProviderId"= ap."ProviderId" and ap."Active" =true
--left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
--left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where ap."Status" <> 'C'
and (Ap."AppointmentDate" >= f.weeks::text::date and Ap."AppointmentDate" < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else AP."LocationId"= "locationId" end
--and case when ("referenceId" is null) or ("referenceId"=0) then 1=1 else PA."ReferenceId"= "referenceId" end
)a
)
select date_trunc('month', current_date)::date startdate ,f.weeks enddate,
coalesce(A.appointmentamount,0) as "AppointmentAmount" from
actappointmentamount A ;
--left join refundappointmentamount B on A."AccountId"=B."AccountId";
end loop;
RETURN QUERY
with finalData as (select A.endDate,sum(coalesce(A.countdata,0) )::numeric countdata from temp_table A group by A.endDate)
select A.startdate,coalesce(B.countdata,0) from temp_date_table A
left join finalData B on A.startdate=B.endDate;
--select * from temp_date_table
--left join temp_table A on A.startdate=B.startdate ;
drop table temp_table;
drop table temp_date_table;
END;
$BODY$;
ALTER FUNCTION public."widget_PieChart_Appointment_Revenue"(date, text,integer,integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.widget_BarChart_Lab_Revenue(date, text, integer,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_BarChart_Lab_Revenue"(date, text, integer,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_BarChart_Lab_Revenue"(
"fromDate" date,
"filterType" text,
"displayCount" integer,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
filtervalue interval;
intervaldata interval;
fromdate date;
begin
create Temp TABLE temp_table
( labdate date,
labamount numeric
) ON COMMIT DELETE ROWS;
filtervalue= "displayCount"||' '|| "filterType";
intervaldata= '1 '|| "filterType";
raise notice ' %', filtervalue;
--fromdate:=case when "filterType"='day' then "fromDate"
--else date_trunc('month', "fromDate"::date) end;
for f in SELECT generate_series("fromDate" - filtervalue , "fromDate" + filtervalue, intervaldata) weeks
loop
insert into temp_table (labdate,labamount)
select f.weeks,coalesce(sum(coalesce(ar."NetAmount",0)),0) "LabAmount"
from "LabBookingHeader" ar
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where ar."Active" <> false and (ar."CreatedDate"::date >= f.weeks::text::date and ar."CreatedDate"::date < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
and case when ("referenceId" is null) or ("referenceId"=0) then 1=1 else PA."ReferenceId"= "referenceId" end
;
end loop;
RETURN QUERY
select A.labdate,A.labamount from temp_table A;
drop table temp_table;
END;
$BODY$;
ALTER FUNCTION public."widget_BarChart_Lab_Revenue"(date, text, integer,integer,integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Chart_Lab_Revenue(text, date, text, integer, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Chart_Lab_Revenue"(text, date, text, integer, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Chart_Lab_Revenue"(
"chartType" text,
"fromDate" date,
"filterType" text,
"displayCount" integer DEFAULT NULL::integer,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
DECLARE
sql text := 'select "Date", "Count"::numeric from ';
BEGIN
IF "chartType"='Bar' THEN
sql := sql || '"widget_BarChart_Lab_Revenue"('''||"fromDate"||''','''||"filterType"||''', '''||"displayCount"||''','''||coalesce("referenceId",0)||''','''||coalesce("locationId",0)||''')';
ELSE
sql := sql || '"widget_PieChart_Lab_Revenue"('''||"fromDate"||''','''||"filterType"||''','''||coalesce("referenceId",0)||''','''||coalesce("locationId",0)||''')';
END IF;
raise notice 'query %', sql;
RETURN QUERY EXECUTE sql;
END
$BODY$;
ALTER FUNCTION public."widget_Chart_Lab_Revenue"(text, date, text, integer, integer, integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.widget_PieChart_Lab_Revenue(date, text,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_PieChart_Lab_Revenue"(date, text,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_PieChart_Lab_Revenue"(
"fromDate" date,
"filterType" text,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
intervaldata interval;
ftype text;
currentdate date;
fromdate date;
begin
intervaldata:= case when "filterType"='day' then '1 D' when "filterType"='month' then '1 Month' when "filterType"='year' then '1 Year' end;
ftype:= case when "filterType"='day' then 'month'::text when "filterType"='month' then 'year'::text when "filterType"='year' then 'year'::text end;
currentdate:= case when "filterType"='year' then date_trunc(ftype, "fromDate") - '2 Y'::interval else date_trunc(ftype, "fromDate") end ;
fromdate:=case when "filterType"='day' and current_date > "fromDate" then (date_trunc('month', "fromDate"::date) + interval '1 month' - interval '1 day')::date
when "filterType"='month' and "fromDate" < current_date then date_trunc('Year', "fromDate"::date) + interval '1 Year' - interval '1 month'
else "fromDate" end;
raise notice 'intervaldata %', intervaldata;
raise notice 'ftype %', ftype;
raise notice 'currentdate %', currentdate;
create Temp TABLE temp_table
( startdate date,
enddate date,
countdata numeric
) ON COMMIT DELETE ROWS;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
raise notice 'currentdate %', f.weeks::text::date;
raise notice 'fromdate %', fromdate::date;
insert into temp_table (startdate,enddate,countdata)
select date_trunc('month', current_date)::date startdate ,f.weeks enddate,coalesce(sum(coalesce(ar."NetAmount",0)),0) "LabAmount"
from "LabBookingHeader" ar
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where ar."Active" <> false and (ar."CreatedDate"::date >= f.weeks::text::date and ar."CreatedDate"::date < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
and case when ("referenceId" is null) or ("referenceId"=0) then 1=1 else PA."ReferenceId"= "referenceId" end
;
end loop;
RETURN QUERY
select A.enddate,A.countdata from temp_table A;
drop table temp_table;
END;
$BODY$;
ALTER FUNCTION public."widget_PieChart_Lab_Revenue"(date, text,integer,integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.widget_Table_NewPatientAppointment(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_NewPatientAppointment"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_NewPatientAppointment"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM')
from "Appointment" apt
join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and AT."AppointmentTypeId" =1
and Pa."CreatedDate"::date="fromDate" and Pa."Active" is true
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_NewPatientAppointment"(date, integer, integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.widget_Pharmacy_OverAll_CardTotal(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Pharmacy_OverAll_CardTotal"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OverAll_CardTotal"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
join "Role" rol on rol."RoleId" = a."RoleId" and LOWER(rol."RoleName")<>LOWER('Patient')
join "LocationAccountMap" LA on LA."AccountId"=a."AccountId"
where case when "locationId" is null then 1=1 else LA."LocationId"= "locationId" end
)
,PharmaSaleAmount as (
select a."AccountId", sum(a."Cash") "PharmaSaleCash",sum(a."Card") "PharmaSaleCard" , sum(a."Cash")+ sum(a."Card")
"PharmaSaleAmount" from (
select a."AccountId",
case when ar."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else ar."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else ar."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId", sum(a."Cash") "PharmaReturnCash",sum(a."Card") "PharmaReturnCard"
,sum(a."Cash")+sum(a."Card") "PharmaReturnAmount"
from(
select a."AccountId",
case when srh."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when "fromDate" is null then 1=1 else ar."ReturnDate"::date = "fromDate" end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSaleCash",0) - coalesce(b. "PharmaReturnCash",0) as "PharmaSaleCash" ,
coalesce(a."PharmaSaleCard",0) - coalesce(b. "PharmaReturnCard",0) as "PharmaSaleCard" ,
coalesce(a."PharmaSaleAmount",0) - coalesce(b. "PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct
sum(coalesce(pa."PharmaSaleCard",0)) "TotalCard"
from accountdata a
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."widget_Pharmacy_OverAll_CardTotal"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Pharmacy_OverAll_CashTotal(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Pharmacy_OverAll_CashTotal"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OverAll_CashTotal"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
join "Role" rol on rol."RoleId" = a."RoleId" and LOWER(rol."RoleName")<>LOWER('Patient')
join "LocationAccountMap" LA on LA."AccountId"=a."AccountId"
where
case when "locationId" is null then 1=1 else LA."LocationId"= "locationId" end
)
,PharmaSaleAmount as (
select a."AccountId", sum(a."Cash") "PharmaSaleCash",sum(a."Card") "PharmaSaleCard"
, sum(a."Cash")+ sum(a."Card")"PharmaSaleAmount"
from (
select a."AccountId",
case when ar."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else ar."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else ar."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId", sum(a."Cash") "PharmaReturnCash",sum(a."Card") "PharmaReturnCard" ,sum(a."Cash")+sum(a."Card") "PharmaReturnAmount"
from(
select a."AccountId",
case when srh."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when "fromDate" is null then 1=1 else ar."ReturnDate"::date = "fromDate" end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSaleCash",0) - coalesce(b. "PharmaReturnCash",0) as "PharmaSaleCash" ,
coalesce(a."PharmaSaleCard",0) - coalesce(b. "PharmaReturnCard",0) as "PharmaSaleCard" ,
coalesce(a."PharmaSaleAmount",0) - coalesce(b. "PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct
sum(coalesce(pa."PharmaSaleCash",0)) "TotalCash"
from accountdata a
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."widget_Pharmacy_OverAll_CashTotal"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Pharmacy_OverAll_ChequeTotal(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Pharmacy_OverAll_ChequeTotal"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OverAll_ChequeTotal"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
join "Role" rol on rol."RoleId" = a."RoleId" and LOWER(rol."RoleName")<>LOWER('Patient')
join "LocationAccountMap" LA on LA."AccountId"=a."AccountId"
where
case when "locationId" is null then 1=1 else LA."LocationId"= "locationId" end
)
,PharmaSaleAmount as (
select a."AccountId", sum(a."Cheque") "PharmaSaleCheque"
from (
select a."AccountId",
case when ar."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else ar."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else ar."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId", sum(a."Cheque") "PharmaReturnCheque"
from(
select a."AccountId",
case when srh."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when "fromDate" is null then 1=1 else ar."ReturnDate"::date = "fromDate" end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSaleCheque",0) - coalesce(b. "PharmaReturnCheque",0) as "PharmaSaleCheque"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct
sum(coalesce(pa."PharmaSaleCheque",0)) "TotalCheque"
from accountdata a
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."widget_Pharmacy_OverAll_ChequeTotal"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_BarChart_Pharmacy_LowSellingProducts(date, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_BarChart_Pharmacy_LowSellingProducts"(date, text, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_BarChart_Pharmacy_LowSellingProducts"(
"fromDate" date,
"filterType" text,
"displayCount" integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Name" text, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
filtervalue interval;
intervaldata interval;
fromdate date;
begin
create Temp TABLE temp_table
( ddate date,
dname text,
countdata numeric
) ON COMMIT DELETE ROWS;
filtervalue= "displayCount"||' '|| "filterType";
intervaldata= '1 '|| "filterType";
raise notice 'filtervalue %', filtervalue;
if "displayCount"=2 then "displayCount"=5;
elsif "displayCount"=3 then "displayCount"=7;
elsif "displayCount"=4 then "displayCount"=9;
else "displayCount"=15; end if;
--fromdate:=case when "filterType"='day' then "fromDate"
--else date_trunc('month', "fromDate"::date) end;
for f in SELECT generate_series("fromDate"-filtervalue, "fromDate"+filtervalue, intervaldata) weeks
loop
raise notice 'fromdate %', "fromDate"-filtervalue;
raise notice 'todate %', "fromDate"+filtervalue;
insert into temp_table (ddate,dname,countdata)
--------------------------------------------------
with lowSellingData as(
select psd."PharmacyProductId",PP."ProductName", count(psd."PharmacyProductId") "Count"
from "PharmacySaleDetail" psd
join "PharmacyProduct" pp on pp."PharmacyProductId" = psd."PharmacyProductId"
join "PharmacySaleHeader" psh on psh."PharmacySaleHeaderId" = psd."PharmacySaleHeaderId"
where psh."CreatedDate"::date >= f.weeks::text::date and psh."CreatedDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else psh."LocationId"= "locationId" end
group by psd."PharmacyProductId" ,PP."ProductName"
)
,perlowSellingData as (
select a.weeks,a."ProductName",round(a."Count"/sum(a."Count") over()*100,2) "Count" from(
select f.weeks, lsd."ProductName", lsd."Count"
from lowSellingData lsd)a)
select f.weeks, lsd."ProductName", lsd."Count"
from perlowSellingData lsd
order by "Count" asc
limit "displayCount";
----------
end loop;
RETURN QUERY
select A.ddate,A.dname,A.countdata from temp_table A
order by A.countData asc
limit "displayCount";
drop table temp_table;
--drop table temp_date_table;
END;
$BODY$;
ALTER FUNCTION public."widget_BarChart_Pharmacy_LowSellingProducts"(date, text, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Chart_Pharmacy_LowSellingProducts(text, date, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Chart_Pharmacy_LowSellingProducts"(text, date, text, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Chart_Pharmacy_LowSellingProducts"(
"chartType" text,
"fromDate" date,
"filterType" text,
"displayCount" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Name" text, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
DECLARE
sql text := 'select "Date","Name", "Count"::numeric from ';
BEGIN
IF "chartType"='Bar' THEN
sql := sql || '"widget_BarChart_Pharmacy_LowSellingProducts"('''||"fromDate"||''','''||"filterType"||''', '''||"displayCount"||''','''||coalesce("locationId",0)||''')';
ELSE
sql := sql || '"widget_PieChart_Pharmacy_LowSellingProducts"('''||"fromDate"||''','''||"filterType"||''','''||coalesce("locationId",0)||''')';
END IF;
raise notice 'query %', sql;
RETURN QUERY EXECUTE sql
;
END
$BODY$;
ALTER FUNCTION public."widget_Chart_Pharmacy_LowSellingProducts"(text, date, text, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_PieChart_Pharmacy_LowSellingProducts(date, text, integer)
-- DROP FUNCTION IF EXISTS public."widget_PieChart_Pharmacy_LowSellingProducts"(date, text, integer);
CREATE OR REPLACE FUNCTION public."widget_PieChart_Pharmacy_LowSellingProducts"(
"fromDate" date,
"filterType" text,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Name" text, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
--f record;
--filtervalue interval;
--intervaldata interval;
f record;
intervaldata interval;
ftype text;
currentdate date;
fromdate date;
begin
intervaldata:= case when "filterType"='day' then '1 D' when "filterType"='month' then '1 Month' when "filterType"='year' then '1 Year' end;
ftype:= case when "filterType"='day' then 'month'::text when "filterType"='month' then 'year'::text when "filterType"='year' then 'year'::text end;
currentdate:= case when "filterType"='year' then date_trunc(ftype, "fromDate") - '2 Y'::interval else date_trunc(ftype, "fromDate") end ;
fromdate:=case when "filterType"='day' and current_date > "fromDate" then (date_trunc('month', "fromDate"::date) + interval '1 month' - interval '1 day')::date
when "filterType"='month' and "fromDate" < current_date then date_trunc('Year', "fromDate"::date) + interval '1 Year' - interval '1 month'
else "fromDate" end;
raise notice 'intervaldata %', intervaldata;
raise notice 'ftype %', ftype;
raise notice 'currentdate %', currentdate;
create Temp TABLE temp_table
(
startdate date,
enddate date,
dname text,
countdata numeric
) ON COMMIT DELETE ROWS;
create Temp TABLE temp_date_table
( startdate date,
enddate date
) ON COMMIT DELETE ROWS;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
insert into temp_date_table (startdate,enddate)
select f.weeks::text::date ,(f.weeks+ intervaldata)::text::date ;
--raise notice 'datetable %', f.weeks::text::date;
end loop;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
raise notice 'currentdate %', f.weeks::text::date;
raise notice 'fromdate %', fromdate::date;
insert into temp_table (startdate,enddate,dname,countdata)
----------------------------------------------
with lowSellingData as(
select psd."PharmacyProductId",PP."ProductName", count(psd."PharmacyProductId") "Count"
from "PharmacySaleDetail" psd
join "PharmacyProduct" pp on pp."PharmacyProductId" = psd."PharmacyProductId"
join "PharmacySaleHeader" psh on psh."PharmacySaleHeaderId" = psd."PharmacySaleHeaderId"
where psh."CreatedDate"::date >= f.weeks::text::date and psh."CreatedDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else psh."LocationId"= "locationId" end
group by psd."PharmacyProductId" ,PP."ProductName"
)
,perlowSellingData as (
select a.weeks,a."ProductName",round(a."Count"/sum(a."Count") over()*100,2) "Count" from(
select f.weeks, lsd."ProductName", lsd."Count"
from lowSellingData lsd)a)
select date_trunc('month', current_date)::date startdate ,f.weeks enddate,lsd."ProductName" , lsd."Count"
from perlowSellingData lsd;
---------------------
----------------------------------------------
end loop;
RETURN QUERY
with perlowSellingData as (select A.endDate,A.dname,sum(coalesce(A.countdata,0) )::numeric countdata from temp_table A group by A.endDate,A.dname)
select A.startdate,B.dname,coalesce(B.countdata,0) "Count" from perlowSellingData B
left join temp_date_table A on A.startdate=B.endDate
order by "Count" asc
limit 10;
drop table temp_table;
drop table temp_date_table;
END;
$BODY$;
ALTER FUNCTION public."widget_PieChart_Pharmacy_LowSellingProducts"(date, text, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Pharmacy_OverAll_OnlinePaymentTotal(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Pharmacy_OverAll_OnlinePaymentTotal"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OverAll_OnlinePaymentTotal"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
join "Role" rol on rol."RoleId" = a."RoleId" and LOWER(rol."RoleName")<>LOWER('Patient')
join "LocationAccountMap" LA on LA."AccountId"=a."AccountId"
where
case when "locationId" is null then 1=1 else LA."LocationId"= "locationId" end
)
,PharmaSaleAmount as (
select a."AccountId", sum(a."OnlinePayment") "PharmaSaleOnlinePayment"
from (
select a."AccountId",
case when ar."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "OnlinePayment"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else ar."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else ar."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId", sum(a."OnlinePayment") "PharmaReturnOnlinePayment"
from(
select a."AccountId",
case when srh."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "OnlinePayment"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when "fromDate" is null then 1=1 else ar."ReturnDate"::date = "fromDate" end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSaleOnlinePayment",0) - coalesce(b. "PharmaReturnOnlinePayment",0) as "PharmaSaleOnlinePayment"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct
sum(coalesce(pa."PharmaSaleOnlinePayment",0)) "TotalOnlinePayment"
from accountdata a
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."widget_Pharmacy_OverAll_OnlinePaymentTotal"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Pharmacy_OverAll_PaytmTotal(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Pharmacy_OverAll_PaytmTotal"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OverAll_PaytmTotal"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
join "Role" rol on rol."RoleId" = a."RoleId" and LOWER(rol."RoleName")<>LOWER('Patient')
join "LocationAccountMap" LA on LA."AccountId"=a."AccountId"
where
case when "locationId" is null then 1=1 else LA."LocationId"= "locationId" end
)
,PharmaSaleAmount as (
select a."AccountId", sum(a."Paytm") "PharmaSalePaytm"
from (
select a."AccountId",
case when ar."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else ar."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else ar."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId", sum(a."Paytm") "PharmaReturnPaytm"
from(
select a."AccountId",
case when srh."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when "fromDate" is null then 1=1 else ar."ReturnDate"::date = "fromDate" end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSalePaytm",0) - coalesce(b. "PharmaReturnPaytm",0) as "PharmaSalePaytm"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct
sum(coalesce(pa."PharmaSalePaytm",0)) "TotalPaytm"
from accountdata a
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."widget_Pharmacy_OverAll_PaytmTotal"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_BarChart_Pharmacy_Sale_Revenue(date, text, integer,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_BarChart_Pharmacy_Sale_Revenue"(date, text, integer,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_BarChart_Pharmacy_Sale_Revenue"(
"fromDate" date,
"filterType" text,
"displayCount" integer,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
filtervalue interval;
intervaldata interval;
fromdate date;
begin
create Temp TABLE temp_table
( saledate date,
pharmacyamount numeric
) ON COMMIT DELETE ROWS;
filtervalue= "displayCount"||' '|| "filterType";
intervaldata= '1 '|| "filterType";
raise notice 'filtervalue %', filtervalue;
--fromdate:=case when "filterType"='day' then "fromDate"
--else date_trunc('month', "fromDate"::date) end;
-- raise notice 'currentdate %', "fromdate"+filtervalue;
-- raise notice 'startdate %', fromdate;
for f in SELECT generate_series("fromDate"-filtervalue, "fromDate"+filtervalue, intervaldata) weeks
loop
-- raise notice 'loop interval %', intervaldata;
-- raise notice 'loop fromdate %', f.weeks;
insert into temp_table (saledate,pharmacyamount)
with PharmaSaleAmount as (
select a."AccountId",
sum(a."Cash") "PharmaSaleCash",
sum(a."Card") "PharmaSaleCard",
sum(a."Upi") "PharmaSaleUpi",
sum(a."Online") "PharmaSaleOnline",
sum(a."Cheque") "PharmaSaleCheque",
sum(a."Paytm") "PharmaSalePaytm",
sum(a."Cash")+ sum(a."Card")+ sum(a."Upi")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm") "PharmaSaleAmount"
from (
select a."AccountId",
case when "PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when "PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when "PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "Upi"
,case when "PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when "PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when "PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where (ar."SaleDate" >= f.weeks::text::date and ar."SaleDate" <= (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
and case when ("referenceId" is null) or ("referenceId"=0) then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId",
sum(a."Cash") "PharmaReturnCash",
sum(a."Card") "PharmaReturnCard",
sum(a."Upi") "PharmaReturnUpi",
sum(a."Online") "PharmaReturnOnline",
sum(a."Cheque") "PharmaReturnCheque",
sum(a."Paytm") "PharmaReturnPaytm",
sum(a."Cash")+ sum(a."Card")+ sum(a."Upi")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm") "PharmaReturnAmount"
from(
select a."AccountId",
case when srh."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when srh."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "Upi"
,case when srh."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when srh."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when srh."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where (ar."ReturnDate" >= f.weeks::text::date and ar."ReturnDate" <= (f.weeks+ intervaldata)::text::date) )a
group by a."AccountId"
)
select f.weeks,
coalesce((select coalesce(sum(a."PharmaSaleAmount"),0) - coalesce(sum(b. "PharmaReturnAmount"),0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"),0) ;
raise notice 'findal data %', f.weeks;
end loop;
RETURN QUERY
select A.saledate,A.pharmacyamount from temp_table A;
drop table temp_table;
END;
$BODY$;
ALTER FUNCTION public."widget_BarChart_Pharmacy_Sale_Revenue"(date, text, integer,integer,integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Chart_Pharmacy_Sale_Revenue(text, date, text, integer,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_Chart_Pharmacy_Sale_Revenue"(text, date, text, integer,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_Chart_Pharmacy_Sale_Revenue"(
"chartType" text,
"fromDate" date,
"filterType" text,
"displayCount" integer DEFAULT NULL::integer,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
DECLARE
sql text := 'select "Date", "Count"::numeric from ';
BEGIN
IF "chartType"='Bar' THEN
sql := sql || '"widget_BarChart_Pharmacy_Sale_Revenue"('''||"fromDate"||''','''||"filterType"||''', '''||"displayCount"||''','''||coalesce("referenceId",0)||''','''||coalesce("locationId",0)||''')';
ELSE
sql := sql || '"widget_PieChart_Pharmacy_Sale_Revenue"('''||"fromDate"||''','''||"filterType"||''','''||coalesce("referenceId",0)||''','''||coalesce("locationId",0)||''')';
END IF;
raise notice 'query %', sql;
RETURN QUERY EXECUTE sql
;
END
$BODY$;
ALTER FUNCTION public."widget_Chart_Pharmacy_Sale_Revenue"(text, date, text, integer,integer,integer)
OWNER TO postgres;
-- FUNCTION: public.widget_PieChart_Pharmacy_Sale_Revenue(date, text,integer,integer)
-- DROP FUNCTION IF EXISTS public."widget_PieChart_Pharmacy_Sale_Revenue"(date, text,integer,integer);
CREATE OR REPLACE FUNCTION public."widget_PieChart_Pharmacy_Sale_Revenue"(
"fromDate" date,
"filterType" text,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
intervaldata interval;
ftype text;
currentdate date;
fromdate date;
begin
intervaldata:= case when "filterType"='day' then '1 D' when "filterType"='month' then '1 Month' when "filterType"='year' then '1 Year' end;
ftype:= case when "filterType"='day' then 'month'::text when "filterType"='month' then 'year'::text when "filterType"='year' then 'year'::text end;
currentdate:= case when "filterType"='year' then date_trunc(ftype, "fromDate") - '2 Y'::interval else date_trunc(ftype, "fromDate") end ;
fromdate:=case when "filterType"='day' and current_date > "fromDate" then (date_trunc('month', "fromDate"::date) + interval '1 month' - interval '1 day')::date
when "filterType"='month' and "fromDate" < current_date then date_trunc('Year', "fromDate"::date) + interval '1 Year' - interval '1 month'
else "fromDate" end;
raise notice 'intervaldata %', intervaldata;
raise notice 'ftype %', ftype;
raise notice 'currentdate %', currentdate;
create Temp TABLE temp_table
( startdate date,
enddate date,
countdata numeric
) ON COMMIT DELETE ROWS;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
raise notice 'currentdate %', f.weeks::text::date;
raise notice 'fromdate %', fromdate::date;
insert into temp_table (startdate,enddate,countdata)
with PharmaSaleAmount as (
select a."AccountId",
sum(a."Cash") "PharmaSaleCash",
sum(a."Card") "PharmaSaleCard",
sum(a."Upi") "PharmaSaleUpi",
sum(a."Online") "PharmaSaleOnline",
sum(a."Cheque") "PharmaSaleCheque",
sum(a."Paytm") "PharmaSalePaytm",
sum(a."Cash")+ sum(a."Card")+ sum(a."Upi")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm") "PharmaSaleAmount"
from (
select a."AccountId",
case when "PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when "PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when "PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "Upi"
,case when "PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when "PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when "PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where (ar."SaleDate" >= f.weeks::text::date and ar."SaleDate" <= (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
and case when ("referenceId" is null) or ("referenceId"=0) then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId",
sum(a."Cash") "PharmaReturnCash",
sum(a."Card") "PharmaReturnCard",
sum(a."Upi") "PharmaReturnUpi",
sum(a."Online") "PharmaReturnOnline",
sum(a."Cheque") "PharmaReturnCheque",
sum(a."Paytm") "PharmaReturnPaytm",
sum(a."Cash")+ sum(a."Card")+ sum(a."Upi")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm") "PharmaReturnAmount"
from(
select a."AccountId",
case when srh."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when srh."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "Upi"
,case when srh."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when srh."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when srh."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where
(ar."ReturnDate" >= f.weeks::text::date and ar."ReturnDate" <= (f.weeks+ intervaldata)::text::date) )a
group by a."AccountId"
)
select
date_trunc('month', current_date)::date startdate ,f.weeks enddate,
coalesce(sum(a."PharmaSaleAmount"),0) - coalesce(sum(b. "PharmaReturnAmount"),0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId";
end loop;
RETURN QUERY
select A.enddate,A.countdata from temp_table A;
drop table temp_table;
END;
$BODY$;
ALTER FUNCTION public."widget_PieChart_Pharmacy_Sale_Revenue"(date, text,integer,integer)
OWNER TO postgres;
-- FUNCTION: public.widget_GetPharmacySaleAmountByDate(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_GetPharmacySaleAmountByDate"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_GetPharmacySaleAmountByDate"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as ( SELECT PP."CategoryId",LV."Name" as "CategoryName",SUM(PSD."NetAmount") as "SaleAmount",COALESCE(b.NetAmount, 0) as "RetrunAmount",SUM(PSD."NetAmount") - COALESCE(b.NetAmount, 0) as "TotalAmount"
FROM "PharmacySaleDetail" PSD
JOIN "PharmacyProduct" PP ON PP."PharmacyProductId" = PSD."PharmacyProductId"
JOIN "LookupValue" LV ON LV."LookupValueId" = PP."CategoryId"
left JOIN "PharmacySaleHeader" PSH ON PSH."PharmacySaleHeaderId"=PSD."PharmacySaleHeaderId"
LEFT JOIN (select SUM(SRD."NetAmount")NetAmount,SRD."PharmacyProductId" from "SaleReturnDetail" SRD
join "SaleReturnHeader" SRH on SRH."SaleReturnHeaderId"=SRD."SaleReturnHeaderId"
where SRH."ReturnDate"::date ="fromDate"
GROUP BY SRD."PharmacyProductId") B on
B."PharmacyProductId" = PSD."PharmacyProductId"
left join "Provider" pr on pr."ProviderId"= PSH."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else PSH."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else PSH."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
group by PP."CategoryId",LV."Name",b.NetAmount
),
salesTotal as (
select
COALESCE(SUM( a."TotalAmount"),0) as "Count"
from cts a)
select c.* from salesTotal c;
END
$BODY$;
ALTER FUNCTION public."widget_GetPharmacySaleAmountByDate"(date, integer, integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.widget_Pharmacy_OverAll_UPITotal(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Pharmacy_OverAll_UPITotal"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OverAll_UPITotal"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
join "Role" rol on rol."RoleId" = a."RoleId" and LOWER(rol."RoleName")<>LOWER('Patient')
join "LocationAccountMap" LA on LA."AccountId"=a."AccountId"
where
case when "locationId" is null then 1=1 else LA."LocationId"= "locationId" end
)
,PharmaSaleAmount as (
select a."AccountId", sum(a."Upi") "PharmaSaleUpi"
from (
select a."AccountId",
case when ar."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "Upi"
from "Account" a
left join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
left join "Provider" pr on pr."ProviderId"= ar."ProviderId"
left join "ProviderLocation" PL on PL."ProviderId"=pr."ProviderId" and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
left join "Account" PA on PA."ReferenceId"=pr."ProviderId" and PA."RoleId"=3
where case when "fromDate" is null then 1=1 else ar."SaleDate"::date = "fromDate" end
and case when "locationId" is null then 1=1 else ar."LocationId"= "locationId" end
and case when "referenceId" is null then 1=1 else PA."ReferenceId"= "referenceId" end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId", sum(a."Upi") "PharmaReturnUpi"
from(
select a."AccountId",
case when srh."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "Upi"
from "Account" a
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when "fromDate" is null then 1=1 else ar."ReturnDate"::date = "fromDate" end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSaleUpi",0) - coalesce(b. "PharmaReturnUpi",0) as "PharmaSaleUpi"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct
sum(coalesce(pa."PharmaSaleUpi",0)) "TotalUpi"
from accountdata a
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."widget_Pharmacy_OverAll_UPITotal"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Table_PharmacyRetailStockProducts_ExpiryInMonths(date, integer, text)
-- DROP FUNCTION IF EXISTS public."widget_Table_PharmacyRetailStockProducts_ExpiryInMonths"(date, integer, text);
CREATE OR REPLACE FUNCTION public."widget_Table_PharmacyRetailStockProducts_ExpiryInMonths"(
"selectDate" date DEFAULT NULL::date,
"locationId" integer DEFAULT NULL::integer,
"retailStore" text DEFAULT NULL::text)
RETURNS TABLE("ProductName" character varying, "GenericName" character varying, "RetailName" text, "BatchNumber" character varying, "ExpiryDate" date)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
SELECT
PP."ProductName",
PP."GenericName",
RP."RetailName",
PS."BatchNumber",
PS."ExpiryDate"
FROM
"PharmacyRetailStock" PS
JOIN "RetailWareHouseLink" PWL ON PWL."RetailWareHouseLinkId" = PS."RetailWareHouseLinkId"
JOIN "PharmacyWareHouse" PW ON PW."PharmacyWareHouseId" = PWL."PharmacyWareHouseId"
JOIN "RetailPharmacy" RP ON RP."RetailPharmacyId" = PWL."RetailPharmacyId"
JOIN "PharmacyProduct" PP ON PP."PharmacyProductId" = PS."PharmacyProductId"
WHERE
(PS."QuantityIn" - PS."QuantityOut") <> 0
and case when "retailStore" is null then 1=1 else RP."RetailName"="retailStore" end
AND case when "selectDate" is null then 1=1 else PS."ExpiryDate" <="selectDate"::date end
AND case when "locationId" is null then 1=1 else PW."LocationId" = "locationId" end
order by PS."ExpiryDate"
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_PharmacyRetailStockProducts_ExpiryInMonths"(date, integer, text)
OWNER TO postgres;
-- FUNCTION: public.widget_Table_PharmacyRetailStockProducts_UnderROL(integer, integer, text)
-- DROP FUNCTION IF EXISTS public."widget_Table_PharmacyRetailStockProducts_UnderROL"(integer, integer, text);
CREATE OR REPLACE FUNCTION public."widget_Table_PharmacyRetailStockProducts_UnderROL"(
"accountId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"retailStore" text DEFAULT NULL::text)
RETURNS TABLE("ProductName" character varying, "GenericName" character varying, "RetailName" text, "AvailableQty" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
SELECT
PP."ProductName",
PP."GenericName",
RP."RetailName",
SUM(PS."QuantityIn" - PS."QuantityOut") AS "AvailableQty"
FROM
"PharmacyRetailStock" PS
JOIN "RetailWareHouseLink" PWL ON PWL."RetailWareHouseLinkId" = PS."RetailWareHouseLinkId"
JOIN "PharmacyWareHouse" PW ON PW."PharmacyWareHouseId" = PWL."PharmacyWareHouseId"
JOIN "RetailPharmacy" RP ON RP."RetailPharmacyId" = PWL."RetailPharmacyId"
JOIN "PharmacyProduct" PP ON PP."PharmacyProductId" = PS."PharmacyProductId"
JOIN "PharmacyRetailUser" PRU ON PRU."RetailPharmacyId"=RP."RetailPharmacyId"
WHERE
PP."RolQuantity" > ( PS."QuantityIn" - PS."QuantityOut" )
and (PS."QuantityIn" - PS."QuantityOut") <> 0
and case when "retailStore" is null then 1=1 else RP."RetailName"="retailStore" end
AND case when "accountId" is null then 1=1 else PRU."AccountId"="accountId" end
AND case when "locationId" is null then 1=1 else PW."LocationId" = "locationId" end
group by PS."PharmacyProductId",PP."ProductName",PP."GenericName",RP."RetailName"
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_PharmacyRetailStockProducts_UnderROL"(integer, integer, text)
OWNER TO postgres;
-- FUNCTION: public.widget_BarChart_OverAllRevenue(date, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_BarChart_OverAllRevenue"(date, text, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_BarChart_OverAllRevenue"(
"fromDate" date,
"filterType" text,
"displayCount" integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Name" text, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
filtervalue interval;
intervaldata interval;
fromdate date;
begin
create Temp TABLE temp_table
( ddate date,
dname text,
countdata numeric
) ON COMMIT DELETE ROWS;
filtervalue= "displayCount"||' '|| "filterType";
intervaldata= '1 '|| "filterType";
raise notice 'filtervalue %', filtervalue;
--fromdate:=case when "filterType"='day' then "fromDate"
--else date_trunc('month', "fromDate"::date) end;
for f in SELECT generate_series("fromDate"-filtervalue, "fromDate"+filtervalue, intervaldata) weeks
loop
raise notice 'fromdate %', "fromDate"-filtervalue;
raise notice 'todate %', "fromDate"+filtervalue;
insert into temp_table (ddate,dname,countdata)
with actappointmentamount as (
select A.appointmentamount::bigint appointmentamount from (
select sum(coalesce(AP."Total",0)) appointmentamount
from "Appointment" ap
where ap."Status" <> 'C'
and (Ap."AppointmentDate" >= f.weeks::text::date and Ap."AppointmentDate" < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else AP."LocationId"= "locationId" end
)a
)
,appointmentamount as (
select
coalesce(A.appointmentamount,0) as "AppointmentAmount" from actappointmentamount A
)
,actadmissionamount as (
select a."Total" "AdmissionAmount" from (
select sum(coalesce(adr."Cost",0)) "Total"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where
adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
and adr."CreatedDate"::date >= f.weeks::text::date and adr."CreatedDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ad."LocationId"= "locationId" end
)a
)
,refadmissionamount as (
select a."Total" "AdmissionRefAmount" from (
select sum(coalesce(adr."Cost",0)) "Total"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where
adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
and adr."CreatedDate"::date >= f.weeks::text::date and adr."CreatedDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ad."LocationId"= "locationId" end
)a
)
,admissionamount as (
select
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A ,refadmissionamount B
)
,LabAmount as (
select a."TotalAmount" "LabAmount" from(
select sum(coalesce(ar."NetAmount",0)) "TotalAmount"
from "LabBookingHeader" ar
where ar."Active" <> false and (ar."CreatedDate"::date >= f.weeks::text::date and ar."CreatedDate"::date < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
)a
)
,PharmaSaleAmount as (
select a."Total"
"PharmaSaleAmount" from (
select sum(coalesce(ar."OverallNetAmount",0)) "Total"
from "PharmacySaleHeader" ar
where ar."SaleDate"::date >= f.weeks::text::date and ar."SaleDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
)a
)
,PharmaReturnAmount as (
select a."Total" "PharmaReturnAmount" from(
select sum(coalesce(ar."OverallNetAmount",0)) "Total"
from "SaleReturnHeader" ar
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where ar."ReturnDate" ::date >= f.weeks::text::date and ar."ReturnDate" ::date <= (f.weeks+ intervaldata)::text::date
)a
)
,PharmaAmount as (
select
coalesce(a."PharmaSaleAmount",0) - coalesce(b. "PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a ,PharmaReturnAmount b
)
,finaldata as (select
case when "Total" = 0 then 0 else round("AppointmentAmount"/"Total"*100,2) end "AppointmentAmount",
case when "Total" = 0 then 0 else round("AdmissionAmount"/"Total"*100,2) end "AdmissionAmount",
case when "Total" = 0 then 0 else round("LabAmount"/"Total"*100,2) end "LabAmount",
case when "Total" = 0 then 0 else round("PharmacyAmount"/"Total"*100,2) end "PharmacyAmount",
"Total"
from (
select distinct
ap."AppointmentAmount",
ad."AdmissionAmount",
lb."LabAmount",
sum(pa."PharmaAmount") over() "PharmacyAmount",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(),0) "Total"
from appointmentamount ap , admissionamount ad ,LabAmount lb ,PharmaAmount pa ) a)
select f.weeks,
unnest(array['AppointmentAmount','AdmissionAmount','LabAmount', 'PharmacyAmount']) as "Name",
unnest(array[ coalesce("AppointmentAmount",0),coalesce("AdmissionAmount",0),coalesce("LabAmount",0), coalesce("PharmacyAmount",0)]) as "Count"
from finaldata;
end loop;
RETURN QUERY
select A.ddate,A.dname,A.countdata from temp_table A;
drop table temp_table;
--drop table temp_date_table;
END;
$BODY$;
ALTER FUNCTION public."widget_BarChart_OverAllRevenue"(date, text, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_Chart_OverAllRevenue(text, date, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Chart_OverAllRevenue"(text, date, text, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Chart_OverAllRevenue"(
"chartType" text,
"fromDate" date,
"filterType" text,
"displayCount" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Name" text, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
DECLARE
sql text := 'select "Date","Name", "Count"::numeric from ';
BEGIN
IF "chartType"='Bar' THEN
sql := sql || '"widget_BarChart_OverAllRevenue"('''||"fromDate"||''','''||"filterType"||''', '''||"displayCount"||''','''||coalesce("locationId",0)||''')';
ELSE
sql := sql || '"widget_PieChart_OverAllRevenue"('''||"fromDate"||''','''||"filterType"||''','''||coalesce("locationId",0)||''')';
END IF;
raise notice 'query %', sql;
RETURN QUERY EXECUTE sql
;
END
$BODY$;
ALTER FUNCTION public."widget_Chart_OverAllRevenue"(text, date, text, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_PieChart_OverAllRevenue(date, text, integer)
-- DROP FUNCTION IF EXISTS public."widget_PieChart_OverAllRevenue"(date, text, integer);
CREATE OR REPLACE FUNCTION public."widget_PieChart_OverAllRevenue"(
"fromDate" date,
"filterType" text,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Date" date, "Name" text, "Count" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare
f record;
intervaldata interval;
ftype text;
currentdate date;
fromdate date;
begin
intervaldata:= case when "filterType"='day' then '1 D' when "filterType"='month' then '1 Month' when "filterType"='year' then '1 Year' end;
ftype:= case when "filterType"='day' then 'month'::text when "filterType"='month' then 'year'::text when "filterType"='year' then 'year'::text end;
currentdate:= case when "filterType"='year' then date_trunc(ftype, "fromDate") - '2 Y'::interval else date_trunc(ftype, "fromDate") end ;
fromdate:=case when "filterType"='day' and current_date > "fromDate" then (date_trunc('month', "fromDate"::date) + interval '1 month' - interval '1 day')::date
when "filterType"='month' and "fromDate" < current_date then date_trunc('Year', "fromDate"::date) + interval '1 Year' - interval '1 month'
else "fromDate" end;
raise notice 'intervaldata %', intervaldata;
raise notice 'ftype %', ftype;
raise notice 'currentdate %', currentdate;
create Temp TABLE temp_table
(
startdate date,
enddate date,
dname text,
countdata numeric
) ON COMMIT DELETE ROWS;
create Temp TABLE temp_date_table
( startdate date,
enddate date
) ON COMMIT DELETE ROWS;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
insert into temp_date_table (startdate,enddate)
select f.weeks::text::date ,(f.weeks+ intervaldata)::text::date ;
--raise notice 'datetable %', f.weeks::text::date;
end loop;
for f in
select generate_series( currentdate , fromdate, intervaldata) weeks
loop
raise notice 'currentdate %', f.weeks::text::date;
raise notice 'fromdate %', fromdate::date;
insert into temp_table (startdate,enddate,dname,countdata)
with actappointmentamount as (
select A.appointmentamount::bigint appointmentamount from (
select sum(coalesce(AP."Total",0)) appointmentamount
from "Appointment" ap
where ap."Status" <> 'C'
and (Ap."AppointmentDate" >= f.weeks::text::date and Ap."AppointmentDate" < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else AP."LocationId"= "locationId" end
)a
)
,appointmentamount as (
select
coalesce(A.appointmentamount,0) as "AppointmentAmount" from actappointmentamount A
)
,actadmissionamount as (
select a."Total" "AdmissionAmount" from (
select sum(coalesce(adr."Cost",0)) "Total"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where
adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
and adr."CreatedDate"::date >= f.weeks::text::date and adr."CreatedDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ad."LocationId"= "locationId" end
)a
)
,refadmissionamount as (
select a."Total" "AdmissionRefAmount" from (
select sum(coalesce(adr."Cost",0)) "Total"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where
adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
and adr."CreatedDate"::date >= f.weeks::text::date and adr."CreatedDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ad."LocationId"= "locationId" end
)a
)
,admissionamount as (
select
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A ,refadmissionamount B
)
,LabAmount as (
select a."TotalAmount" "LabAmount" from(
select sum(coalesce(ar."NetAmount",0)) "TotalAmount"
from "LabBookingHeader" ar
where ar."Active" <> false and (ar."CreatedDate"::date >= f.weeks::text::date and ar."CreatedDate"::date < (f.weeks+ intervaldata)::text::date)
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
)a
)
,PharmaSaleAmount as (
select a."Total"
"PharmaSaleAmount" from (
select sum(coalesce(ar."OverallNetAmount",0)) "Total"
from "PharmacySaleHeader" ar
where ar."SaleDate"::date >= f.weeks::text::date and ar."SaleDate"::date <= (f.weeks+ intervaldata)::text::date
and case when ("locationId" is null) or ("locationId"=0) then 1=1 else ar."LocationId"= "locationId" end
)a
)
,PharmaReturnAmount as (
select a."Total" "PharmaReturnAmount" from(
select sum(coalesce(ar."OverallNetAmount",0)) "Total"
from "SaleReturnHeader" ar
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where ar."ReturnDate" ::date >= f.weeks::text::date and ar."ReturnDate" ::date <= (f.weeks+ intervaldata)::text::date
)a
)
,PharmaAmount as (
select
coalesce(a."PharmaSaleAmount",0) - coalesce(b. "PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a ,PharmaReturnAmount b
)
,finaldata as (select
case when "Total" = 0 then 0 else round("AppointmentAmount"/"Total"*100,2) end "AppointmentAmount",
case when "Total" = 0 then 0 else round("AdmissionAmount"/"Total"*100,2) end "AdmissionAmount",
case when "Total" = 0 then 0 else round("LabAmount"/"Total"*100,2) end "LabAmount",
case when "Total" = 0 then 0 else round("PharmacyAmount"/"Total"*100,2) end "PharmacyAmount",
"Total"
from (
select distinct
ap."AppointmentAmount",
ad."AdmissionAmount",
lb."LabAmount",
sum(pa."PharmaAmount") over() "PharmacyAmount",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(),0) "Total"
from appointmentamount ap , admissionamount ad ,LabAmount lb ,PharmaAmount pa ) a)
select date_trunc('month', current_date)::date startdate ,f.weeks enddate,
unnest(array['AppointmentAmount','AdmissionAmount','LabAmount', 'PharmacyAmount']) as "Name",
unnest(array[ coalesce("AppointmentAmount",0),coalesce("AdmissionAmount",0),coalesce("LabAmount",0), coalesce("PharmacyAmount",0)]) as "Count"
from finaldata;
end loop;
RETURN QUERY
with finalData as (select A.endDate,A.dname,sum(coalesce(A.countdata,0) )::numeric countdata from temp_table A group by A.endDate,A.dname)
select A.startdate,B.dname,coalesce(B.countdata,0) from temp_date_table A
left join finalData B on A.startdate=B.endDate;
drop table temp_table;
drop table temp_date_table;
END;
$BODY$;
ALTER FUNCTION public."widget_PieChart_OverAllRevenue"(date, text, integer)
OWNER TO postgres;
-- FUNCTION: public.widget_FollowUp_Appointments_Count(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_FollowUp_Appointments_Count"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_FollowUp_Appointments_Count"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(*) from "Appointment"
where "Active" is true and "AppointmentDate"::date="fromDate" and
"AppointmentTypeId" =4
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else "LocationId"= "locationId" end;
end
$BODY$;
ALTER FUNCTION public."widget_FollowUp_Appointments_Count"(date, integer, integer)
OWNER TO postgres;
\ No newline at end of file
ALTER TABLE IF EXISTS public."AppointmentTransaction" DROP CONSTRAINT IF EXISTS "UQ_AppointmentTransaction_TransactionId";
\ No newline at end of file
-- Table: public.PaymentModule
-- DROP TABLE IF EXISTS public."PaymentModule";
CREATE SEQUENCE IF NOT EXISTS public."PaymentModule_PaymentModuleId_seq";
CREATE TABLE IF NOT EXISTS public."PaymentModule"
(
"PaymentModuleId" integer NOT NULL DEFAULT nextval('"PaymentModule_PaymentModuleId_seq"'::regclass),
"Name" character varying(150) COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "PaymentModule_pkey" PRIMARY KEY ("PaymentModuleId"),
CONSTRAINT "UQ_PaymentModule_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."PaymentModule"
OWNER to postgres;
-- Index: IX_PaymentModule_Name
-- DROP INDEX IF EXISTS public."IX_PaymentModule_Name";
CREATE UNIQUE INDEX IF NOT EXISTS "IX_PaymentModule_Name"
ON public."PaymentModule" USING btree
(upper("Name"::text) COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default;
---------------------------------------------------
INSERT INTO public."PaymentModule"(
"PaymentModuleId", "Name")
VALUES (1,'Patient'),(2,'Appointment'),(3,'Pharmacy'),(4,'Labs');
---------------------------------------------------
-- Table: public.PaymentInitiationLog
-- DROP TABLE IF EXISTS public."PaymentInitiationLog";
CREATE SEQUENCE IF NOT EXISTS public."PaymentInitiationLog_PaymentInitiationLogId_seq";
CREATE TABLE IF NOT EXISTS public."PaymentInitiationLog"
(
"PaymentInitiationLogId" integer NOT NULL DEFAULT nextval('"PaymentInitiationLog_PaymentInitiationLogId_seq"'::regclass),
"TableData" text NOT NULL,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) with time zone NOT NULL,
"PaymentModuleId" integer NOT NULL,
"Mode" character varying(10) NOT NULL,
CONSTRAINT "PaymentInitiationLog_pkey" PRIMARY KEY ("PaymentInitiationLogId"),
CONSTRAINT "FK_PaymentInitiationLog_PaymentModuleId" FOREIGN KEY ("PaymentModuleId")
REFERENCES public."PaymentModule" ("PaymentModuleId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_PaymentInitiationLog_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."PaymentInitiationLog"
OWNER to postgres;
--------------------------------------------------
INSERT INTO public."LogType"(
"LogTypeId", "LogTypeName", "Active")
VALUES (67, 'PaymentInitiationLog', true);
--------------------------------------------------
\ No newline at end of file
ALTER TABLE "AppointmentTransaction"
ALTER COLUMN "BankCode" DROP NOT NULL;
ALTER TABLE "AppointmentTransaction"
ALTER COLUMN "PaymentId" TYPE bigint;
\ No newline at end of file
alter table "AppointmentLog"
add column "TokenNumber" integer;
\ No newline at end of file
ALTER TABLE "AppointmentLog"
ADD COLUMN "AppointmentTypeId" integer,
ADD CONSTRAINT "FK_AppointmentLog_AppointmentTypeId" FOREIGN KEY ("AppointmentTypeId")
REFERENCES public."AppointmentType" ("AppointmentTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
\ No newline at end of file
alter table "AppointmentLog" add column "PayTypeId" int references "PayType"("PayTypeId");
\ No newline at end of file
alter table "PharmacySaleHeader"
add column "PaymentStatus" boolean default true;
\ No newline at end of file
INSERT INTO public."ReceiptAreaTypeId"(
"ReceiptAreaTypeId", "Name")
VALUES (7,'PharmacyReturn');
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], integer, integer);
\ No newline at end of file
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_uiReport_fetch_Appointments_Location"(
locationid integer DEFAULT NULL::integer,
"appointmentNo" text DEFAULT NULL::text,
"departmentId" integer[] DEFAULT NULL::integer[],
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"uMRNo" text DEFAULT NULL::text,
"patientReferredById" integer[] DEFAULT NULL::integer[],
"referredByName" text DEFAULT NULL::text,
mobile text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"appointmentTypeId" integer[] DEFAULT NULL::integer[],
"paymentStatus" boolean default null,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10
)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "AppointmentTypeName" character varying, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "Name" character varying, "ReferredByName" character varying, "PatientName" character varying, "PatientAge" smallint, "UMRNo" character varying, "Mobile" character varying, "PatientGender" character, "AppointmentTime" time without time zone, "VisitType" character, "PaymentType" character varying, "PaymentNumber" character varying, "TotalAppointments" bigint, "TotalAmount" bigint, "TotalAmountStr" text, "ReceiptCreatedByName" text, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" text, "PaymentStatus" boolean, "EncounterType" encountertype_elements)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (select coalesce(A."DepartmentId"::text,'GrandTotal') "DepartmentId",
A."ProviderId"::text as "ProviderId",
A."AppointmentDate",A."AppointmentTypeId",
ATN."Name" "AppointmentTypeName",
A."AppointmentNo",A."PatientId" "PatientId",PRB."Name",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
PT."PayTypeName" as "PaymentType",A."PaymentNumber",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::text as "TotalAmountStr" ,
sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband",
A."PaymentStatus",
A."EncounterType"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on A."AppointmentTypeId"=ATN."AppointmentTypeId"
where A."Status"<>'C' and
case when "departmentId" is null then 1=1 else A."DepartmentId" = any("departmentId") end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END and
case when "patientId" is null then 1=1 else Pa."PatientId" = any("patientId") end and
case when "appointmentNo" is null then 1=1 when "appointmentNo" ='' then 1=1 else A."AppointmentNo" ilike'%'||"appointmentNo" ||'%' end and
case when "providerId" is null then 1=1 else A."ProviderId" = any("providerId") end and
case when "uMRNo" is null then 1=1 when "uMRNo" ='' then 1=1 else Pa."UMRNo" ilike'%'||"uMRNo" ||'%' end and
case when "patientReferredById" is null then 1=1 else Pa."PatientReferredById" = any("patientReferredById") end and
case when "appointmentTypeId" is null then 1=1 else ATN."AppointmentTypeId" = any("appointmentTypeId") end and
case when "referredByName" is null then 1=1 when "referredByName" ='' then 1=1 else Pa."ReferredByName" ilike'%'||"referredByName" ||'%' end and
case when "mobile" is null then 1=1 when "mobile" ='' then 1=1 else Pa."Mobile" ilike'%'||"mobile" ||'%' end and
case when "payTypeId" is null then 1=1 else A."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end and
case when "paymentStatus" is null then 1=1 else A."PaymentStatus" ="paymentStatus" end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."PatientId",PRB."Name",
Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",A."AppointmentTypeId",
ATN."Name" ,
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband",A."PaymentStatus",A."EncounterType"), (A."DepartmentId",A."ProviderId"), ())
order by A."AppointmentId")
select A."DepartmentId",coalesce(D."DepartmentName",'GrandTotal') "DepartmentName",
case when A."AppointmentNo" is null then 'Total' else A."ProviderId" end "ProviderId",
case when A."AppointmentNo" is null then 'Total' else Pr."FullName" end as "ProviderName",
ATN."Name" "AppointmentTypeName",
A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else PRB."Name"::varchar end as "Name",
case when A."AppointmentNo" is null then null else Pa."ReferredByName"::varchar end as "ReferredByName",
case when A."AppointmentNo" is null then null else Pa."FullName"::varchar end as "PatientName",
case when A."AppointmentNo" is null then null else Pa."Age" end "PatientAge",
case when A."AppointmentNo" is null then null else Pa."UMRNo" end "UMRNo",
case when A."AppointmentNo" is null then null else Pa."Mobile" end "Mobile",
case when A."AppointmentNo" is null then null else Pa."Gender" end "PatientGender",
A."AppointmentTime",
A."VisitType",A."PaymentType",A."PaymentNumber",A."TotalAppointments",A."TotalAmount",A."TotalAmountStr",
CA."FullName" "ReceiptCreatedByName", R."CreatedDate" "ReceiptDate",R."ReceiptId",
case when A."AppointmentNo" is null then null else Pa."StreetAddress" end "StreetAddress",
case when A."AppointmentNo" is null then null else Pa."City" end "City",
case when A."AppointmentNo" is null then null else Pa."State" end "State",
A."FatherOrHusband",
A."PaymentStatus",A."EncounterType"
from cts A
left join "Department" D on A."DepartmentId"=D."DepartmentId"::text
left join "Provider" Pr on Pr."ProviderId"::text=A."ProviderId"
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left Join "Receipt" R on R."AppointmentId"=A."AppointmentId"
Left Join "Account" CA on CA."AccountId"=R."CreatedBy"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on ATN."AppointmentTypeId"=A."AppointmentTypeId"
order by A."AppointmentId"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[],boolean,integer, integer)
OWNER TO postgres;
ALTER TABLE IF EXISTS public."AppointmentLog"
ADD COLUMN "ReceiptTypeId" integer,
ADD COLUMN "ReceiptAreaTypeId" integer;
----------------------------------------------
\ No newline at end of file
ALTER TABLE IF EXISTS public."AppointmentTransaction"
ADD COLUMN "SalucroStatusCode" integer,
ADD COLUMN "SalucroTransactionId" text,
ADD COLUMN "CreatedBy" integer NOT NULL default 0,
ADD COLUMN "CreatedDate" timestamp(6) without time zone NOT NULL default current_date,
ADD COLUMN "LocationId" integer,
ADD COLUMN "ReceiptTypeId" integer,
ADD COLUMN "ReceiptAreaTypeId" integer;
----------------------------------------------
ALTER TABLE IF EXISTS public."AppointmentTransaction"
ADD CONSTRAINT "AppointmentTransaction_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
-----------------------------------------
\ No newline at end of file
alter table "Patient"
add column "Amount" numeric(8,2) default 0,
add column "PaymentNumber" character varying(50) COLLATE pg_catalog."default",
add column "PaymentStatus" boolean default false,
add column "PayTypeId" integer;
\ No newline at end of file
alter table "TicketAssignee"
add column "AssigneeAccountId" integer,
add CONSTRAINT "'Fk_Account_AccountId'" FOREIGN KEY ("AssigneeAccountId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
\ No newline at end of file
alter table "Ticket"
add column "DeviceType" text COLLATE pg_catalog."default"
\ No newline at end of file
alter table "TicketTimeline"
add column "AssignedToUser" integer,
add CONSTRAINT "'Fk_Account_AccountId'" FOREIGN KEY ("AssignedToUser")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
\ No newline at end of file
alter table "Supplier" drop column "Telephone",
drop column "DeliveryLocationPrimary",
drop column "DeliveryLocationSecondary",
drop column "TinNumber",
drop column "CstNumber";
--------------
alter table "Supplier" add column "ContactPersonName" text,
add column "DrugLicense" text,
add column "GSTNo" text;
-----------------
\ No newline at end of file
alter table "RequestIndentHeader" drop column "PaymentNoOfDays";
alter table "RequestIndentHeader" add column "ApprovedBy" int references "Account"("AccountId"),
add column "ApprovedDate" timestamp without time zone;
insert into "ProductRaiseStatus" ("Status") values ('MovedToTenderList'),('PartiallyApproved');
create table "RaiseTenderHeader"(
"RaiseTenderHeaderId" serial primary key,
"TenderNumber" varchar(250),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"Active" boolean default true,
"ProductRaiseStatusId" int references "ProductRaiseStatus"("ProductRaiseStatusId"),
"RequiredDate" date,
"PaymentClearDays" int,
"PaymentMode" varchar(250)
);
create table "RaiseTenderDetail"(
"RaiseTenderDetailId" serial primary key,
"RaiseTenderHeaderId" int references "RaiseTenderHeader"("RaiseTenderHeaderId"),
"RequestIndentDetailId" int references "RequestIndentDetail"("RequestIndentDetailId")
);
create table "TenderSendedToVendor"(
"TenderSendedToVendorId" serial primary key,
"RaiseTenderHeaderId" int references "RaiseTenderHeader"("RaiseTenderHeaderId"),
"CreatedDate" timestamp without time zone,
"CreatedBy" int references "Account"("AccountId")
);
insert into "ProductRaiseStatus" ("Status") values ('TenderRaised');
alter table "TenderSendedToVendor" add column "SupplierId" int references "Supplier"("SupplierId"),
add column "ProductRaiseStatusId" int references "ProductRaiseStatus"("ProductRaiseStatusId");
Alter table "Supplier" add column "UserId" int default null references "User"("UserId");
\ No newline at end of file
-- Table: public."ScanSubClassification"
-- DROP TABLE public."ScanSubClassification";
CREATE TABLE public."ScanSubClassification"
(
"ScanSubClassificationId" serial integer NOT NULL ,
"ScanClassificationId" integer NOT NULL,
"ScanSubClassificationName" character varying(225) COLLATE pg_catalog."default" NOT NULL,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "ScanSubClassification_pkey" PRIMARY KEY ("ScanSubClassificationId"),
CONSTRAINT "FK_ScanSubClassification_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_ScanSubClassification_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_ScanSubClassification_ScanClassificationId" FOREIGN KEY ("ScanClassificationId")
REFERENCES public."ScanClassification" ("ScanClassificationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanSubClassification"
OWNER to postgres;
\ No newline at end of file
insert into "LogType" ("LogTypeId","LogTypeName","Active") values (52,'ScanClassification',true);
insert into "LogType" ("LogTypeId","LogTypeName","Active") values (53,'ScanSubClassification',true);
insert into "LogType" ("LogTypeId","LogTypeName","Active") values (54,'ScanTest',true);
insert into "LogType" ("LogTypeId","LogTypeName","Active") values (55,'ScanMachine',true);
insert into "LogType" ("LogTypeId","LogTypeName","Active") values (56,'ScanAppointment',true);
ALTER TABLE public."BookScanAppointment"
ADD COLUMN "Status" character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT 'B'::bpchar;
ALTER TABLE public."BookScanAppointment"
ADD COLUMN "Reason" text COLLATE pg_catalog."default";
\ No newline at end of file
-- Table: public."ScanClassification"
-- DROP TABLE public."ScanClassification";
CREATE TABLE public."ScanClassification"
(
"ScanClassificationId" serial integer NOT NULL,
"ScanClassificationName" character varying COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "ScanClassificationId_pkey" PRIMARY KEY ("ScanClassificationId"),
CONSTRAINT "FK_ScanClassification_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_ScanClassification_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanClassification"
OWNER to postgres;
\ No newline at end of file
-- Table: public."ScanTestMaster"
-- DROP TABLE public."ScanTestMaster";
drop table "ScanTestMaster";
CREATE TABLE public."ScanTestMaster"
(
"ScanTestMasterId" bigint NOT NULL DEFAULT nextval('"ScanTestMaster_ScanTestMasterId_seq"'::regclass),
"ScanTestName" character varying(250) COLLATE pg_catalog."default" NOT NULL,
"ScanTestCode" character varying COLLATE pg_catalog."default" NOT NULL,
"Description" character varying(500) COLLATE pg_catalog."default",
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
"Duration" smallint,
"ScanClassificationId" integer,
CONSTRAINT "PK_ScanTestMaster_ScanTestMasterId" PRIMARY KEY ("ScanTestMasterId"),
CONSTRAINT "FK_ScanTestMaster_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_ScanTestMaster_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanTestMaster_ScanClassificationId_fkey" FOREIGN KEY ("ScanClassificationId")
REFERENCES public."ScanClassification" ("ScanClassificationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanTestMaster"
OWNER to postgres;
\ No newline at end of file
-- FUNCTION: public.udf_FetchPatients_For_QuickScheduleFollowUp(character varying, character varying, character varying, character varying)
-- DROP FUNCTION IF EXISTS public."udf_FetchPatients_For_QuickScheduleFollowUp"(character varying, character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_QuickScheduleFollowUp"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"patientName" character varying DEFAULT NULL::text,
"urlLink" character varying DEFAULT NULL::text)
RETURNS TABLE("PatientId" integer, "Salutation" character varying, "FirstName" text, "MiddleName" text, "LastName" text, "FullName" text, "DateOfBirth" date, "Age" smallint, "Gender" character, "UMRNo" character varying, "Email" character varying, "Mobile" character varying, "CountryId" integer, "ProfileImageUrl" text, "Active" boolean, "ProviderId" integer, "ProviderName" character varying, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean, "HWCName" character varying, "HWCPatientId" integer, "Description" text, "RowColor" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (
select row_number() over(partition by a."PatientId" order by a."AppointmentId" desc,
a."AppointmentDate" desc )"Max" ,a."PatientId",a."AppointmentId"
from "Appointment" a
join "Patient" pat on a."PatientId" =pat."PatientId"
join "Provider" pr on a."ProviderId" = pr."ProviderId"
where a."Active"=true
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%')|| "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
)
, maxapt as (
select a.* from "Appointment" a
join cts on a."AppointmentId"=cts."AppointmentId"
where "Max"=1)
,ctsadmission as (
select distinct max(a."AdmissionId") over(partition by a."PatientId" )"MaxAdmissionId" ,a."PatientId",
a."AppointmentId" from "Admission" a
join "Patient" pat on a."PatientId" =pat."PatientId"
where a."Active"=true
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%') || "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
)
, maxadmision as (
select a.* from "Admission" a
join ctsadmission cts on a."AdmissionId"=cts."MaxAdmissionId"
)
SELECT DISTINCT pat."PatientId" ,
pat."Salutation" ,
pat."FirstName" ,
pat."MiddleName" ,
pat."LastName" ,
pat."FullName" ,
pat."DateOfBirth" ,
pat."Age" ,
pat."Gender" ,
pat."UMRNo" ,
pat."Email" ,
pat."Mobile" ,
pat."CountryId" ,
pat."ProfileImageUrl" ,
-- pat."ThumbnailUrl" ,
pat."Active" ,
apt."ProviderId",
pr."FullName" as "ProviderName",
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT("urlLink", pat."Guid", '/', pat."ThumbnailUrl") ELSE NULL END) AS "ThumbnailUrl"
,(max(apt."AppointmentDate")over(partition by apt."PatientId")::text ||' ' || max(apt."AppointmentTime")over(partition by apt."PatientId",apt."AppointmentDate")::text)::timestamp as "AppointmentDate",
(case when (max(apt."AppointmentDate")over(partition by apt."PatientId")::text ||' ' || max(apt."AppointmentTime")over(partition by apt."PatientId")::text)::timestamp > now() at time zone 'UTC-5:30' then true else false end)"isActiveAppointmentExists"
,(case when max(adm."AdmissionId")over(partition by adm."PatientId") is null then false
when max(adm."AdmissionId")over(partition by adm."PatientId") is not null and max(dc."DischargeId")over(partition by pat."PatientId") is null then true
when max(adm."AdmissionId")over(partition by adm."PatientId") is not null and max(dc."DischargeId")over(partition by pat."PatientId") is not null then false end
)"isActiveAdmissionExists", HWC."HWCName",HWC."HWCPatientId", HWC."Description", HWC."RowColor"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join "Provider" pr on pr."ProviderId" = apt."ProviderId"
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
left join "HWCPatient" HWC on HWC."HWCPatientId" = pat."HWCPatientId"
WHERE pat."Active" IS TRUE
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%')|| "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchPatients_For_QuickScheduleFollowUp"(character varying, character varying, character varying, character varying)
OWNER TO postgres;
DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, integer, integer);
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, text[], integer, integer)
-- DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, text[], integer, integer);
CREATE OR REPLACE FUNCTION public."udf_uiReport_fetch_Appointments_Location"(
locationid integer DEFAULT NULL::integer,
"appointmentNo" text DEFAULT NULL::text,
"departmentId" integer[] DEFAULT NULL::integer[],
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"uMRNo" text DEFAULT NULL::text,
"patientReferredById" integer[] DEFAULT NULL::integer[],
"referredByName" text DEFAULT NULL::text,
mobile text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"appointmentTypeId" integer[] DEFAULT NULL::integer[],
"paymentStatus" boolean DEFAULT NULL::boolean,
"status" text[] DEFAULT NULL::text[],
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "AppointmentTypeName" character varying, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "Name" character varying, "ReferredByName" character varying, "PatientName" character varying, "PatientAge" smallint, "UMRNo" character varying, "Mobile" character varying, "PatientGender" character, "AppointmentTime" time without time zone, "VisitType" character, "PaymentType" character varying, "PaymentNumber" character varying, "TotalAppointments" bigint, "TotalAmount" bigint, "TotalAmountStr" text, "ReceiptCreatedByName" text, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" text, "PaymentStatus" boolean, "EncounterType" encountertype_elements, "Status" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (select coalesce(A."DepartmentId"::text,'GrandTotal') "DepartmentId",
A."ProviderId"::text as "ProviderId",
A."AppointmentDate",A."AppointmentTypeId",
ATN."Name" "AppointmentTypeName",
A."AppointmentNo",A."PatientId" "PatientId",PRB."Name",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
case when ATN."Name"='Follow Up' and sum(A."Total")=0 then 'Free Follow Up'
else PT."PayTypeName" end as "PaymentType" ,A."PaymentNumber",
A."AppointmentId",
case when A."Status"='B' then 'Booked' when A."Status"='R' then 'Rescheduled' when A."Status"='C' then 'Cancel' end::text as "Status",
COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::text as "TotalAmountStr" ,
sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband",
A."PaymentStatus",
A."EncounterType"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on A."AppointmentTypeId"=ATN."AppointmentTypeId"
where
--A."Status"<>'C' and
case when "departmentId" is null then 1=1 else A."DepartmentId" = any("departmentId") end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END and
case when "patientId" is null then 1=1 else Pa."PatientId" = any("patientId") end and
case when "appointmentNo" is null then 1=1 when "appointmentNo" ='' then 1=1 else A."AppointmentNo" ilike'%'||"appointmentNo" ||'%' end and
case when "providerId" is null then 1=1 else A."ProviderId" = any("providerId") end and
case when "uMRNo" is null then 1=1 when "uMRNo" ='' then 1=1 else Pa."UMRNo" ilike'%'||"uMRNo" ||'%' end and
case when "patientReferredById" is null then 1=1 else Pa."PatientReferredById" = any("patientReferredById") end and
case when "appointmentTypeId" is null then 1=1 else ATN."AppointmentTypeId" = any("appointmentTypeId") end and
case when "referredByName" is null then 1=1 when "referredByName" ='' then 1=1 else Pa."ReferredByName" ilike'%'||"referredByName" ||'%' end and
case when "mobile" is null then 1=1 when "mobile" ='' then 1=1 else Pa."Mobile" ilike'%'||"mobile" ||'%' end and
case when "payTypeId" is null then 1=1 else A."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end and
case when "paymentStatus" is null then 1=1 else A."PaymentStatus" ="paymentStatus" end
and case when "status" is null then 1=1 else A."Status" =any("status") end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."PatientId",PRB."Name",
Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",A."AppointmentTypeId",
ATN."Name" ,
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband",A."PaymentStatus",A."EncounterType"), (A."DepartmentId",A."ProviderId"), ())
order by A."AppointmentId")
select A."DepartmentId",coalesce(D."DepartmentName",'GrandTotal') "DepartmentName",
case when A."AppointmentNo" is null then 'Total' else A."ProviderId" end "ProviderId",
case when A."AppointmentNo" is null then 'Total' else Pr."FullName" end as "ProviderName",
ATN."Name" "AppointmentTypeName",
A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else PRB."Name"::varchar end as "Name",
case when A."AppointmentNo" is null then null else Pa."ReferredByName"::varchar end as "ReferredByName",
case when A."AppointmentNo" is null then null else Pa."FullName"::varchar end as "PatientName",
case when A."AppointmentNo" is null then null else Pa."Age" end "PatientAge",
case when A."AppointmentNo" is null then null else Pa."UMRNo" end "UMRNo",
case when A."AppointmentNo" is null then null else Pa."Mobile" end "Mobile",
case when A."AppointmentNo" is null then null else Pa."Gender" end "PatientGender",
A."AppointmentTime",
A."VisitType",A."PaymentType",A."PaymentNumber",A."TotalAppointments",A."TotalAmount",A."TotalAmountStr",
CA."FullName" "ReceiptCreatedByName", R."CreatedDate" "ReceiptDate",R."ReceiptId",
case when A."AppointmentNo" is null then null else Pa."StreetAddress" end "StreetAddress",
case when A."AppointmentNo" is null then null else Pa."City" end "City",
case when A."AppointmentNo" is null then null else Pa."State" end "State",
A."FatherOrHusband",
A."PaymentStatus",A."EncounterType",A."Status"
from cts A
left join "Department" D on A."DepartmentId"=D."DepartmentId"::text
left join "Provider" Pr on Pr."ProviderId"::text=A."ProviderId"
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left Join "Receipt" R on R."AppointmentId"=A."AppointmentId"
Left Join "Account" CA on CA."AccountId"=R."CreatedBy"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on ATN."AppointmentTypeId"=A."AppointmentTypeId"
order by A."AppointmentId"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, text[], integer, integer)
OWNER TO postgres;
ALTER TABLE public."Appointment"
ADD COLUMN "WaitingPriority" integer;
\ No newline at end of file
----------------------------------------------------------------
CREATE OR REPLACE FUNCTION public."widget_PatientCountNew"(
active boolean DEFAULT NULL::boolean,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(*) from "Account" A
join "Patient" P on P."PatientId" = A."ReferenceId" and A."RoleId" = 4
where A."Active"="active" and
case when "referenceId" is null then 1=1
else P."PatientId" in (
with cts as (
Select "PatientId" from "Appointment" where "ProviderId" = "referenceId"
union all
Select "PatientId" from "Admission" where "ProviderId" = "referenceId"
)Select distinct cts."PatientId" from cts
)
end;
End
$BODY$;
----------------------------------------------------------------
DROP FUNCTION public."widget_GetAppointmentCountByDate"(date, boolean);
CREATE OR REPLACE FUNCTION public."widget_GetAppointmentCountByDate"(
"fromDate" date DEFAULT NULL::date,
active boolean DEFAULT NULL::boolean,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*) from "Appointment"
where "AppointmentDate"::date="fromDate" and "Active"="active"
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end;
end
$BODY$;
-------------------------------------
DROP FUNCTION public."widget_GetAdmissionCountByDate"(date, boolean);
CREATE OR REPLACE FUNCTION public."widget_GetAdmissionCountByDate"(
"fromDate" date DEFAULT NULL::date,
active boolean DEFAULT NULL::boolean,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*) from "Admission"
where "AdmissionDate"::date="fromDate" and "Active"="active"
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end;
end
$BODY$;
----------------------------------------
CREATE OR REPLACE FUNCTION public."widget_New_Appointments_CountNew"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(*) from "Appointment"
where "Active" is true and "FollowUpForAppointmentId" is null and "AppointmentDate"::date="fromDate"
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end;
end
$BODY$;
---------------------------------------
CREATE OR REPLACE FUNCTION public."widget_FollowUp_Appointments_CountNew"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(*) from "Appointment"
where "Active" is true and "AppointmentDate"::date="fromDate" and
("FollowUpForAppointmentId" is not null or "FollowUpForAdmissionId" is not null)
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end;
end
$BODY$;
------------------------------------
DROP FUNCTION public."widget_GetDischargeCountByDate"(date);
CREATE OR REPLACE FUNCTION public."widget_GetDischargeCountByDate"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*)
from "Discharge" D
join "Admission" Adm on Adm."AdmissionId"=D."AdmissionId"
where "DischargeDate"::date="fromDate"
and case when "referenceId" is null then 1=1 else Adm."ProviderId" = "referenceId" end;
end
$BODY$;
--------------------------------------------------
DROP FUNCTION public."widget_GetBookedBedCount"();
CREATE OR REPLACE FUNCTION public."widget_GetBookedBedCount"(
"referenceId" integer DEFAULT NULL::integer
)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(Distinct(B."BedId"))
from "Bed" B
join "Admission" Adm on Adm."BedId"=B."BedId"
where B."BedStatusId" =2
and case when "referenceId" is null then 1=1 else Adm."ProviderId"= "referenceId" end;
end
$BODY$;
-------------------------------------------
DROP FUNCTION public."widget_GetBookedLabCountByDate"(date);
CREATE OR REPLACE FUNCTION public."widget_GetBookedLabCountByDate"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*) from "LabBookingHeader"
where "BookingDate"="fromDate" and "Active" is true
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end;
end
$BODY$;
-------------------------
DROP FUNCTION public."widget_Labs_InPatients_Count"(date);
CREATE OR REPLACE FUNCTION public."widget_Labs_InPatients_Count"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(DISTINCT lbh."PatientId")
from "LabBookingHeader" lbh
join "Admission" ad on ad."AdmissionId" = lbh."AdmissionId"
where lbh."Active" is true and lbh."BookingDate"::date="fromDate"::date
and case when "referenceId" is null then 1=1 else lbh."ProviderId"= "referenceId" end;
end
$BODY$;
---------------------------------------
DROP FUNCTION public."widget_Labs_OutPatients_Count"(date);
CREATE OR REPLACE FUNCTION public."widget_Labs_OutPatients_Count"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(distinct "PatientId") from "LabBookingHeader"
where "AdmissionId" is null and -- "AppointmentId" is null and
"Active" is true and "BookingDate"::date="fromDate"::date
and case when "referenceId" is null then 1=1 else "ProviderId"= "referenceId" end;
end
$BODY$;
--------------------------------------------
DROP FUNCTION public."widget_Pharmacy_InPatients_Count"(date);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_InPatients_Count"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(distinct "PatientId")
from "PharmacyIndentHeader" PIH
join "Admission" AD on AD."AdmissionId"=PIH."AdmissionId"
where PIH."Status"='A' and PIH."ModifiedDate"::date="fromDate"
and case when "referenceId" is null then 1=1 else AD."ProviderId"= "referenceId" end;
end
$BODY$;
-----------------------------------------
DROP FUNCTION public."widget_Pharmacy_OutPatients_Count"(date);
CREATE OR REPLACE FUNCTION public."widget_Pharmacy_OutPatients_Count"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(distinct PSH."PatientId")
from "PharmacySaleHeader" PSH
where "SaleDate"::date="fromDate"
and case when "referenceId" is null then 1=1
else PSH."PatientId" in(
select "PatientId" from "Appointment" where "ProviderId"="referenceId"
)end;
end
$BODY$;
----------------------------------------
-- FUNCTION: public.udf_dashBoard_fetch_Admissions_Location(date, timestamp without time zone, timestamp without time zone, integer[], integer[], text, integer, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_dashBoard_fetch_Admissions_Location"(date, timestamp without time zone, timestamp without time zone, integer[], integer[], text, integer, text, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_dashBoard_fetch_Admissions_Location"(
"admissionDate" date DEFAULT NULL::date,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"admissionNo" text DEFAULT NULL::text,
locationid integer DEFAULT NULL::integer,
"patientType" text DEFAULT NULL::text,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("AdmissionNo" text, "PatientId" integer, "PatientName" text, "Age" smallint, "Gender" character, "Mobile" character varying, "ProviderName" character varying, "AdmissionDate" timestamp without time zone, "AdmissionTime" time without time zone, "DepartmentName" character varying, "TotalAdmissions" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
TotalAdmissions bigint;
BEGIN
select count(A."AdmissionNo") into TotalAdmissions from "Admission" A
join "Patient" Pa on Pa."PatientId"=A."PatientId"
join "Provider" pr on Pr."ProviderId"=A."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
where
A."Active"=true and case when "admissionDate" is null then 1=1 else A."AdmissionDate"="admissionDate"::date end
AND case when "patientType" is null then 1=1 else A."PatientType" ="patientType" end;
return query
select A."AdmissionNo",Pa."PatientId",Pa."FullName" as "PatientName",Pa."Age",Pa."Gender",Pa."Mobile",Pr."FullName" "ProviderName"
,A."AdmissionDate",A."AdmissionTime",D."DepartmentName" ,TotalAdmissions from "Admission" A
join "Patient" Pa on Pa."PatientId"=A."PatientId"
join "Provider" pr on Pr."ProviderId"=A."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
where A."Active"=true and case when "admissionDate" is null then 1=1 else A."AdmissionDate"::date="admissionDate"::date end
AND case when "patientType" is null then 1=1 else A."PatientType" ="patientType" end
and case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate" and A."AdmissionDate" <="toDate" end
and case when "providerId" is null then 1=1 else pr."ProviderId" = any("providerId") end
and case when "patientId" is null then 1=1 else pa."PatientId" = any("patientId") end
and case when "admissionNo" is null then 1=1 else A."AdmissionNo" ilike'%'|| "admissionNo"||'%' end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END
order by A."AdmissionId" desc limit "pageSize" offset ("pageSize"*"pageIndex") ;
END
$BODY$;
ALTER FUNCTION public."udf_dashBoard_fetch_Admissions_Location"(date, timestamp without time zone, timestamp without time zone, integer[], integer[], text, integer, text, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.udf_dashBoard_fetch_Appointments_Location(date, timestamp without time zone, timestamp without time zone, integer[], integer[], character varying, integer, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_dashBoard_fetch_Appointments_Location"(date, timestamp without time zone, timestamp without time zone, integer[], integer[], character varying, integer, text, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_dashBoard_fetch_Appointments_Location"(
"appointmentDate" date DEFAULT NULL::date,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"appointmentNo" character varying DEFAULT NULL::text,
locationid integer DEFAULT NULL::integer,
"visitType" text DEFAULT NULL::text,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("AppointmentNo" character varying, "PatientId" integer, "PatientName" text, "Age" smallint, "Gender" character, "Mobile" character varying, "ProviderName" character varying, "AppointmentDate" date, "AppointmentTime" time without time zone, "DepartmentName" character varying, "VisitType" character, "TotalAppointments" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
TotalAppointments bigint;
BEGIN
select count(A."AppointmentNo") into TotalAppointments from "Appointment" A
join "Patient" Pa on Pa."PatientId"=A."PatientId"
join "Provider" pr on Pr."ProviderId"=A."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
where
A."Active"=true and case when "appointmentDate" is null then 1=1 else A."AppointmentDate"="appointmentDate"::date end
and case when "visitType" is null then 1=1 else trim(upper(A."VisitType"))=trim(upper("visitType")) end
;
return query
select A."AppointmentNo",Pa."PatientId",Pa."FullName" as "PatientName",Pa."Age",Pa."Gender",Pa."Mobile",Pr."FullName" "ProviderName"
,A."AppointmentDate",A."AppointmentTime",D."DepartmentName" ,A."VisitType",TotalAppointments from "Appointment" A
join "Patient" Pa on Pa."PatientId"=A."PatientId"
join "Provider" pr on Pr."ProviderId"=A."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
where A."Active"=true
and case when "appointmentDate" is null then 1=1 else A."AppointmentDate"="appointmentDate"::date end
and case when "visitType" is null then 1=1 else trim(upper(A."VisitType"))=trim(upper("visitType")) end
and case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end
and case when "providerId" is null then 1=1 else pr."ProviderId" = any("providerId") end
and case when "patientId" is null then 1=1 else pa."PatientId" = any("patientId") end
and case when "appointmentNo" is null then 1=1 else A."AppointmentNo" ilike '%' || "appointmentNo" ||'%' end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END
order by A."AppointmentDate" desc,A."AppointmentTime" desc limit "pageSize" offset ("pageSize"*"pageIndex") ;
END
$BODY$;
ALTER FUNCTION public."udf_dashBoard_fetch_Appointments_Location"(date, timestamp without time zone, timestamp without time zone, integer[], integer[], character varying, integer, text, integer, integer)
OWNER TO postgres;
alter table "PharmacySaleHeader" add "SpecializationId" integer references "Specialization"("SpecializationId");
\ No newline at end of file
alter table "AppointmentTransaction"
add column if not exists "VoucherNumber" character varying(15)
alter table "AppointmentTransaction"
add column if not exists "SendedVia" text;
alter table "AppointmentTransaction"
add column if not exists "ReceivedIn" text;
\ No newline at end of file
-- SEQUENCE: public.ActiveStatus_ActiveStatusId_seq
-- DROP SEQUENCE IF EXISTS public."ActiveStatus_ActiveStatusId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ActiveStatus_ActiveStatusId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ActiveStatus_ActiveStatusId_seq"
OWNER TO postgres;
-- Table: public.ActiveStatus
-- DROP TABLE IF EXISTS public."ActiveStatus";
CREATE TABLE IF NOT EXISTS public."ActiveStatus"
(
"ActiveStatusId" integer NOT NULL DEFAULT nextval('"ActiveStatus_ActiveStatusId_seq"'::regclass),
"Name" character varying(150) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "ActiveStatus_pkey" PRIMARY KEY ("ActiveStatusId")
)
TABLESPACE pg_default;
--------------------------------------------------
ALTER TABLE IF EXISTS public."ActiveStatus"
OWNER to postgres;
INSERT INTO public."ActiveStatus"(
"ActiveStatusId", "Name")
VALUES (1,'Active'),(2,'InActive');
---------------------------------------------------
INSERT INTO public."LogType"(
"LogTypeId", "LogTypeName","Active")
VALUES (66,'Cubicle',true);
-- ----------------------------
-- Table structure for Cubicle
-- ----------------------------
CREATE SEQUENCE "Cubicle_CubicleId_seq";
DROP TABLE IF EXISTS "public"."Cubicle";
CREATE TABLE "public"."Cubicle" (
"CubicleId" int4 NOT NULL DEFAULT nextval('"Cubicle_CubicleId_seq"'::regclass),
"Name" varchar(150) COLLATE "pg_catalog"."default" NOT NULL,
"ProviderId" int4,
"CreatedBy" int4 NOT NULL,
"CreatedDate" timestamptz(6) NOT NULL,
"ModifiedBy" int4,
"ModifiedDate" timestamptz(6),
"ActiveStatusId" int4 NOT NULL
)
;
-- ----------------------------
-- Primary Key structure for table Cubicle
-- ----------------------------
ALTER TABLE "public"."Cubicle" ADD CONSTRAINT "Cubicle_pkey" PRIMARY KEY ("CubicleId");
-- ----------------------------
-- Foreign Keys structure for table Cubicle
-- ----------------------------
ALTER TABLE "public"."Cubicle" ADD CONSTRAINT "FK_Cubicle_ActiveStatusId" FOREIGN KEY ("ActiveStatusId") REFERENCES "public"."ActiveStatus" ("ActiveStatusId") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."Cubicle" ADD CONSTRAINT "FK_Cubicle_CreatedBy" FOREIGN KEY ("CreatedBy") REFERENCES "public"."Account" ("AccountId") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."Cubicle" ADD CONSTRAINT "FK_Cubicle_ModifiedBy" FOREIGN KEY ("ModifiedBy") REFERENCES "public"."Account" ("AccountId") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."Cubicle" ADD CONSTRAINT "FK_Cubicle_ProviderId" FOREIGN KEY ("ProviderId") REFERENCES "public"."Provider" ("ProviderId") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE public."Appointment"
ADD COLUMN "CubicleId" integer;
ALTER TABLE public."Appointment"
ADD CONSTRAINT "FK_Appointment_CubicleId" FOREIGN KEY ("CubicleId")
REFERENCES public."Cubicle" ("CubicleId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
INSERT INTO "Department" ("DepartmentName","Active","CreatedBy","CreatedDate","DeptType")
VALUES ( 'Pathology', true, 1029, current_timestamp, 'Providers');
\ No newline at end of file
alter table "Provider"
add column "PanCardNo" character varying(20),
add column "Employee" character(1),
add column "Type" character(1),
add column "DoctorType" character(1)
\ No newline at end of file
------------------------------------------------------
alter table "User"
add column "AddressLine" character varying(200),
add column "EmployeeCode" character varying(20)
-------------------------------------------------------
alter table "Account"
add column "FinanceBackground" boolean,
add column "ExcelDownload" boolean,
add column "RestrictUserLogin" boolean
\ No newline at end of file
alter table "LabBookingDetail"
add column if not exists "Barcode" text
ALTER TABLE "NewLabBookingHeader"
ADD COLUMN "AppointmentId" integer,
add CONSTRAINT "NewLabBookingHeader_AppointmentId_fkey" FOREIGN KEY ("AppointmentId")
REFERENCES public."Appointment" ("AppointmentId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
-- SEQUENCE: public.HowDidYouKnow_HowDidYouKnowId_seq
-- DROP SEQUENCE IF EXISTS public."HowDidYouKnow_HowDidYouKnowId_seq";
CREATE SEQUENCE IF NOT EXISTS public."HowDidYouKnow_HowDidYouKnowId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."HowDidYouKnow_HowDidYouKnowId_seq"
OWNER TO postgres;
-- Table: public.HowDidYouKnow
-- DROP TABLE IF EXISTS public."HowDidYouKnow";
CREATE TABLE IF NOT EXISTS public."HowDidYouKnow"
(
"HowDidYouKnowId" integer NOT NULL DEFAULT nextval('"HowDidYouKnow_HowDidYouKnowId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "HowDidYouKnow_pkey" PRIMARY KEY ("HowDidYouKnowId"),
CONSTRAINT "UQ_HowDidYouKnow_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."HowDidYouKnow"
OWNER to postgres;
-- SEQUENCE: public.Education_EducationId_seq
-- DROP SEQUENCE IF EXISTS public."Education_EducationId_seq";
CREATE SEQUENCE IF NOT EXISTS public."Education_EducationId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."Education_EducationId_seq"
OWNER TO postgres;
-- Table: public.Education
-- DROP TABLE IF EXISTS public."Education";
CREATE TABLE IF NOT EXISTS public."Education"
(
"EducationId" integer NOT NULL DEFAULT nextval('"Education_EducationId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "Education_pkey" PRIMARY KEY ("EducationId"),
CONSTRAINT "UQ_Education_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Education"
OWNER to postgres;
-- SEQUENCE: public.Occupation_OccupationId_seq
-- DROP SEQUENCE IF EXISTS public."Occupation_OccupationId_seq";
CREATE SEQUENCE IF NOT EXISTS public."Occupation_OccupationId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."Occupation_OccupationId_seq"
OWNER TO postgres;
-- Table: public.Occupation
-- DROP TABLE IF EXISTS public."Occupation";
CREATE TABLE IF NOT EXISTS public."Occupation"
(
"OccupationId" integer NOT NULL DEFAULT nextval('"Occupation_OccupationId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "Occupation_pkey" PRIMARY KEY ("OccupationId"),
CONSTRAINT "UQ_Occupation_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Occupation"
OWNER to postgres;
----------------------------------------------------------
ALTER TABLE "Patient"
ADD COLUMN "HowDidYouKnowId" integer,
ADD COLUMN "EducationId" integer,
ADD COLUMN "OccupationId" integer;
-----------------------------------------------------------
ALTER TABLE "Patient"
ADD CONSTRAINT "Patient_HowDidYouKnowId_fkey" FOREIGN KEY ("HowDidYouKnowId")
REFERENCES public."HowDidYouKnow" ("HowDidYouKnowId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
ADD CONSTRAINT "Patient_EducationId_fkey" FOREIGN KEY ("EducationId")
REFERENCES public."Education" ("EducationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
ADD CONSTRAINT "Patient_OccupationId_fkey" FOREIGN KEY ("OccupationId")
REFERENCES public."Occupation" ("OccupationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
-------------------------------------------------------------
INSERT INTO public."HowDidYouKnow"(
"HowDidYouKnowId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (1, 'ABSOLUTE CURIOSITY', true, 6776, current_date),
(2, 'FAMILY TRADITION', true, 6776, current_date),
(3, 'HEARD FROM A COLLEAGUE/FRIEND', true, 6776, current_date),
(4, 'NEWS PAPER', true, 6776, current_date),
(5, 'PRACTO WEBSITE', true, 6776, current_date),
(6, 'REFERRED BY COLLEAGUE', true, 6776, current_date),
(7, 'REFERRED BY DOCTOR', true, 6776, current_date),
(8, 'REFERRED BY FRIEND', true, 6776, current_date),
(9, 'SECOND OPINION', true, 6776, current_date),
(10, 'WEBSEARCH', true, 6776, current_date);
-----------------------------------------------------------
INSERT INTO public."Education"(
"EducationId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (1, 'ANM', true, 6776, current_date),
(2, 'B PHARMACY', true, 6776, current_date),
(3, 'B TECH', true, 6776, current_date),
(4, 'BDS', true, 6776, current_date),
(5, 'Below 5th std', true, 6776, current_date),
(6, 'Below 9th std', true, 6776, current_date),
(7, 'Bsc Nursing', true, 6776, current_date),
(8, 'DGO', true, 6776, current_date),
(9, 'DNB', true, 6776, current_date),
(10, 'Fellowship', true, 6776, current_date),
(11, 'FRCOG', true, 6776, current_date),
(12, 'FRCS', true, 6776, current_date),
(13, 'GNM', true, 6776, current_date),
(14, 'Graduate', true, 6776, current_date),
(15, 'Intermediate', true, 6776, current_date),
(16, 'M PHARMACY', true, 6776, current_date),
(17, 'M phil', true, 6776, current_date),
(18, 'M.TECH', true, 6776, current_date),
(19, 'MBA', true, 6776, current_date),
(20, 'MBBS', true, 6776, current_date),
(21, 'MBBS & ABOVE', true, 6776, current_date),
(22, 'MCA', true, 6776, current_date),
(23, 'MD', true, 6776, current_date),
(24, 'MDS', true, 6776, current_date),
(25, 'Midwifery', true, 6776, current_date),
(26, 'MRCOG', true, 6776, current_date),
(27, 'MS', true, 6776, current_date),
(28, 'Msc Nursing', true, 6776, current_date),
(29, 'Not applicable', true, 6776, current_date),
(30, 'PHD', true, 6776, current_date),
(31, 'PHD in Nursing', true, 6776, current_date),
(32, 'Postgraduate', true, 6776, current_date),
(33, 'SSC', true, 6776, current_date),
(34, 'Uneducated', true, 6776, current_date);
----------------------------------------------------------
INSERT INTO public."Occupation"(
"OccupationId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (1, 'Accountant', true, 6776, current_date),
(2, 'Air Hostess', true, 6776, current_date),
(3, 'Architecht', true, 6776, current_date),
(4, 'Army', true, 6776, current_date),
(5, 'Barber', true, 6776, current_date),
(6, 'Beautician', true, 6776, current_date),
(7, 'BUMS', true, 6776, current_date),
(8, 'Business', true, 6776, current_date),
(9, 'Chairman', true, 6776, current_date),
(10, 'Chef', true, 6776, current_date),
(11, 'Counsellor', true, 6776, current_date),
(12, 'Doctor', true, 6776, current_date),
(13, 'Driver', true, 6776, current_date),
(14, 'Engineer', true, 6776, current_date),
(15, 'Farmer', true, 6776, current_date),
(16, 'Front Office', true, 6776, current_date),
(17, 'GOVT.EMPLOYEE', true, 6776, current_date),
(18, 'HEAD NURSE', true, 6776, current_date),
(19, 'Home Maker', true, 6776, current_date),
(20, 'House Keeping', true, 6776, current_date),
(21, 'HOUSEWIFE', true, 6776, current_date),
(22, 'HR', true, 6776, current_date),
(23, 'IAS/IPS', true, 6776, current_date),
(24, 'Industrialist', true, 6776, current_date),
(25, 'IT PROFESSIONAL', true, 6776, current_date),
(26, 'Labourer', true, 6776, current_date),
(27, 'Lawyer', true, 6776, current_date),
(28, 'Lecturer', true, 6776, current_date),
(29, 'LOBBY MANAGER', true, 6776, current_date),
(30, 'MAINTAINANCE INCHARGE', true, 6776, current_date),
(31, 'Manager', true, 6776, current_date),
(32, 'Managing Director', true, 6776, current_date),
(33, 'Mandal Revenue Officer', true, 6776, current_date),
(34, 'Matron', true, 6776, current_date),
(35, 'Mechanic', true, 6776, current_date),
(36, 'Navy', true, 6776, current_date),
(37, 'Nurse', true, 6776, current_date),
(38, 'NURSING SUPRINDENT', true, 6776, current_date),
(39, 'Occupationnm', true, 6776, current_date),
(40, 'OFFICER', true, 6776, current_date),
(41, 'OTHERS', true, 6776, current_date),
(42, 'PERSONAL MANAGER', true, 6776, current_date),
(43, 'Pharmacist', true, 6776, current_date),
(44, 'Pilot', true, 6776, current_date),
(45, 'Police Man', true, 6776, current_date),
(46, 'Politician', true, 6776, current_date),
(47, 'PRIVATE EMPLOYEE', true, 6776, current_date),
(48, 'Professor', true, 6776, current_date),
(49, 'Public Relation Officer', true, 6776, current_date),
(50, 'Receptionist', true, 6776, current_date),
(51, 'RETIRED', true, 6776, current_date),
(52, 'Security', true, 6776, current_date),
(53, 'Software Engineer', true, 6776, current_date),
(54, 'SOFTWARE(IT)', true, 6776, current_date),
(55, 'STUDENT', true, 6776, current_date),
(56, 'SUPERVISOR', true, 6776, current_date),
(57, 'Tailor', true, 6776, current_date),
(58, 'Teacher', true, 6776, current_date),
(59, 'Technician', true, 6776, current_date),
(60, 'Unemployed', true, 6776, current_date),
(61, 'WARD BOY', true, 6776, current_date),
(62, 'WORKING ABROAD', true, 6776, current_date);
---------------------------------------------------------------
\ No newline at end of file
-- Table: public.Encounter
-- DROP TABLE public."Encounter";
CREATE TABLE public."ObEncounter"
(
"OBEncounterId" bigserial NOT NULL,
"AppointmentId" integer,
"OBEncounterDate" timestamp(6) without time zone NOT NULL,
"Vitals" text COLLATE pg_catalog."default",
"ProblemList" text COLLATE pg_catalog."default",
"BriefRos" text COLLATE pg_catalog."default",
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"AdmissionId" integer,
CONSTRAINT "OBEncounter_pkey" PRIMARY KEY ("OBEncounterId"),
CONSTRAINT "UQ_OBEncounter" UNIQUE ("AppointmentId")
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TYPE encountertype_elements ADD VALUE 'OBEncounter';
\ No newline at end of file
alter table "Patient"
add column "TempPatient" boolean default false;
--wait for the query to run, it will take time and ignore some warnings after query succeded
update "Patient" set "TempPatient"=true where "PaymentStatus"=false and "UMRNo" not ilike '%UMR%';
\ No newline at end of file
alter table "PharmacyIndentDetail" add column "CreatedBy" INTEGER
alter table "PharmacyIndentDetail" add column "CreatedDate" TIMESTAMP without time zone
alter table "PharmacyIndentDetail" add column "RequestedDate" TIMESTAMP without time zone
\ No newline at end of file
DROP FUNCTION public."udf_fetchAvailabilities"(integer, integer, text, text);
CREATE OR REPLACE FUNCTION public."udf_fetchAvailabilities"(
providerid integer,
providerlocationid integer,
fromdate text,
todate text)
RETURNS TABLE("ProviderAvailabilityId" integer, "ProviderId" integer, "ProviderLocationId" integer, "LocationId" integer, "PracticeName" character varying, "PracticeTIN" character varying, "PracticeLocationName" character varying, "Date" date, "DateNumber" integer, "Day" character varying, "Status" character, "From24HrsTime" text, "To24HrsTime" text, "From12HrsTime" text, "To12HrsTime" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
begin
return query
with TotalDates as (
SELECT generate_series( fromDate::date,toDate::date, '1 day')::date "Dates" ,A."ProviderId",
A."ProviderLocationId",A."LocationId"
from "ProviderLocation" A where A."ProviderId"=providerId
)
,Availability as (
select A."ProviderId",A."ProviderLocationId",A."LocationId",json_array_elements(A."Availability"::json )"Availability"
from "ProviderLocation" A where A."ProviderId"=providerId
--and case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
)
,AvailData as (
select A."ProviderId",A."ProviderLocationId",A."LocationId",
A."Availability"->'day' "Day" ,A."Availability"->'fromTime' "FromTime"
,A."Availability"->'toTime' "ToTime" from Availability A
)
, LeaveAvailability as (
select A."ProviderId",A."LeaveDate",coalesce(A."ProviderLocationId"::text,
(select string_agg(D."ProviderLocationId"::text,',') "ProviderLocationId" from "ProviderLocation" D where D."ProviderId"=providerId
--and case when providerLocationId is null then 1=1 else D."ProviderLocationId"=providerLocationId end
)
)"ProviderLocationId" from "ProviderLeave" A where A."ProviderId"=providerId
--and case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
)
,LeaveData as (
select A."ProviderId",A."LeaveDate",regexp_split_to_table(A."ProviderLocationId",',') ::int "ProviderLocationId"
from LeaveAvailability A
)
,FinalData as (
select distinct C."LeaveDate", A."Dates" "Date", A."ProviderId",A."ProviderLocationId",A."LocationId",extract(ISODOW from "Dates")"DateNo", CASE
WHEN extract(ISODOW from "Dates") =1 THEN 'Monday'
WHEN extract(ISODOW from "Dates") =2 THEN 'Tuesday'
WHEN extract(ISODOW from "Dates")=3 THEN 'Wednesday'
WHEN extract(ISODOW from "Dates")=4 THEN 'Thursday'
WHEN extract(ISODOW from "Dates")=5 THEN 'Friday'
WHEN extract(ISODOW from "Dates")=6 THEN 'Saturday'
WHEN extract(ISODOW from "Dates")=7 THEN 'Sunday' end "Day" ,
case when C."LeaveDate" is not null then 'L' when B."Day" is not null then 'A' else null end "Status"
,case when C."LeaveDate" is not null then null else replace (coalesce(B."FromTime"::text,null),'"','') end "FromTime",
case when C."LeaveDate" is not null then null else replace (coalesce(B."ToTime"::text,null),'"','') end "ToTime"
from TotalDates A
left join AvailData B on B."Day"::text::int = extract(ISODOW from A."Dates") and A."ProviderId"=A."ProviderId" and A."ProviderLocationId"=B."ProviderLocationId"
and A."LocationId"=B."LocationId"
left join LeaveData C on C."LeaveDate"::date =A."Dates" and A."ProviderLocationId"=C."ProviderLocationId"
)
select row_number() over()::int "ProviderAvailabilityId",A."ProviderId",A."ProviderLocationId",B."LocationId",
P."FullName" "PracticeName",P."TIN" ,B."Name" "PracticeLocationName"
,A."Date",A."DateNo"::int,A."Day"::text::character varying(10),A."Status"::char, A."FromTime", A."ToTime",
to_char(to_timestamp( A."FromTime", 'HH24:MI'), 'HH12:MI AM') ::text "From12HrsTime" ,
to_char(to_timestamp( A."ToTime", 'HH24:MI'), 'HH12:MI AM') ::text "To12HrsTime"
from FinalData A
join "Location" B on A."LocationId"=B."LocationId"
join "Practice" P on P."PracticeId"=B."PracticeId"
where case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
order by A."Date"
--where "Date"='2020-05-03'::date
--SELECT TO_TIMESTAMP('20:00', 'HH12:MI:AM')::TIME to_char
-- select to_char('20:00'::timestamp, 'HH12:MI AM')
;
--select::timestamp
--select to_char(to_timestamp( '20:00', 'HH24:MI'), 'HH12:MI AM')
end
$BODY$;
----------------------------
DROP FUNCTION public."udf_fetchAvailableDates"(integer);
CREATE OR REPLACE FUNCTION public."udf_fetchAvailableDates"(
providerid integer)
RETURNS TABLE("Date" date, "DateNumber" integer, "DayName" character varying, "Status" character)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
begin
return query
with TotalDates as (
SELECT DISTINCT generate_series( now()::date,now()::date+ interval '12' month, '1 day')::date "Dates" ,
A."ProviderId",A."ProviderLocationId",A."LocationId"
from "ProviderLocation" A
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."Active" IS TRUE
)
,Availability as (
select A."ProviderId",A."ProviderLocationId",A."LocationId",json_array_elements(A."Availability"::json )"Availability"
from "ProviderLocation" A
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."Active" IS TRUE
--and case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
)
,Avail as (
select A."ProviderId",A."ProviderLocationId",A."LocationId",A."Availability"->'day' "Day" ,
A."Availability"->'slots' "Slots"
from Availability A
)
, LeaveAvailability as (
select A."ProviderId",A."LeaveDate",coalesce(A."ProviderLocationId"::text,
(
select string_agg(D."ProviderLocationId"::text,',') "ProviderLocationId" from "ProviderLocation" D where D."ProviderId"= providerid
))
"ProviderLocationId" from "ProviderLeave" A where A."ProviderId"=providerid
)
,LeaveData as (
select A."ProviderId",A."LeaveDate",regexp_split_to_table(A."ProviderLocationId",',') ::int "ProviderLocationId"
from LeaveAvailability A
)
,FinalData as (
select DISTINCT C."LeaveDate", A."Dates" "Date", A."ProviderId",A."ProviderLocationId",
A."LocationId",extract(ISODOW from "Dates")"DateNo", CASE
WHEN extract(ISODOW from "Dates") =1 THEN 'Monday'
WHEN extract(ISODOW from "Dates") =2 THEN 'Tuesday'
WHEN extract(ISODOW from "Dates")=3 THEN 'Wednesday'
WHEN extract(ISODOW from "Dates")=4 THEN 'Thursday'
WHEN extract(ISODOW from "Dates")=5 THEN 'Friday'
WHEN extract(ISODOW from "Dates")=6 THEN 'Saturday'
WHEN extract(ISODOW from "Dates")=7 THEN 'Sunday' end "Day" ,
case when C."LeaveDate" is not null then 'L' when B."Day" is not null then 'A' else '' end "Status"
from TotalDates A
left join Avail B on B."Day"::text::int = extract(ISODOW from A."Dates") and A."ProviderId"=A."ProviderId" and A."ProviderLocationId"=B."ProviderLocationId"
and A."LocationId"=B."LocationId"
left join LeaveData C on C."LeaveDate"::date =A."Dates" and A."ProviderLocationId"=C."ProviderLocationId"
)
select DISTINCT A."Date",A."DateNo"::int,A."Day"::text::character varying(10),A."Status"::char
from FinalData A
order by A."Date";
end
$BODY$;
\ No newline at end of file
1. Keep all your development Queries into "1. QA" folder
2. Person who moved to QA run all the scripts from "1. QA" once done move those scripts to "2. Prod"
3. person who moved to prod run all the scripts from "2. Prod" once done move those scripts to "3. Complete"
Insert into "ReceiptAreaTypeId" ("ReceiptAreaTypeId","Name") values (6,'CancelPatientRegistration')
\ No newline at end of file
-- SEQUENCE: public.HowDidYouKnow_HowDidYouKnowId_seq
-- DROP SEQUENCE IF EXISTS public."HowDidYouKnow_HowDidYouKnowId_seq";
CREATE SEQUENCE IF NOT EXISTS public."HowDidYouKnow_HowDidYouKnowId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."HowDidYouKnow_HowDidYouKnowId_seq"
OWNER TO postgres;
-- Table: public.HowDidYouKnow
-- DROP TABLE IF EXISTS public."HowDidYouKnow";
CREATE TABLE IF NOT EXISTS public."HowDidYouKnow"
(
"HowDidYouKnowId" integer NOT NULL DEFAULT nextval('"HowDidYouKnow_HowDidYouKnowId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "HowDidYouKnow_pkey" PRIMARY KEY ("HowDidYouKnowId"),
CONSTRAINT "UQ_HowDidYouKnow_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."HowDidYouKnow"
OWNER to postgres;
-- SEQUENCE: public.Education_EducationId_seq
-- DROP SEQUENCE IF EXISTS public."Education_EducationId_seq";
CREATE SEQUENCE IF NOT EXISTS public."Education_EducationId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."Education_EducationId_seq"
OWNER TO postgres;
-- Table: public.Education
-- DROP TABLE IF EXISTS public."Education";
CREATE TABLE IF NOT EXISTS public."Education"
(
"EducationId" integer NOT NULL DEFAULT nextval('"Education_EducationId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "Education_pkey" PRIMARY KEY ("EducationId"),
CONSTRAINT "UQ_Education_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Education"
OWNER to postgres;
-- SEQUENCE: public.Occupation_OccupationId_seq
-- DROP SEQUENCE IF EXISTS public."Occupation_OccupationId_seq";
CREATE SEQUENCE IF NOT EXISTS public."Occupation_OccupationId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."Occupation_OccupationId_seq"
OWNER TO postgres;
-- Table: public.Occupation
-- DROP TABLE IF EXISTS public."Occupation";
CREATE TABLE IF NOT EXISTS public."Occupation"
(
"OccupationId" integer NOT NULL DEFAULT nextval('"Occupation_OccupationId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "Occupation_pkey" PRIMARY KEY ("OccupationId"),
CONSTRAINT "UQ_Occupation_Name" UNIQUE ("Name")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Occupation"
OWNER to postgres;
----------------------------------------------------------
ALTER TABLE "Patient"
ADD COLUMN "HowDidYouKnowId" integer,
ADD COLUMN "EducationId" integer,
ADD COLUMN "OccupationId" integer;
-----------------------------------------------------------
ALTER TABLE "Patient"
ADD CONSTRAINT "Patient_HowDidYouKnowId_fkey" FOREIGN KEY ("HowDidYouKnowId")
REFERENCES public."HowDidYouKnow" ("HowDidYouKnowId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
ADD CONSTRAINT "Patient_EducationId_fkey" FOREIGN KEY ("EducationId")
REFERENCES public."Education" ("EducationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
ADD CONSTRAINT "Patient_OccupationId_fkey" FOREIGN KEY ("OccupationId")
REFERENCES public."Occupation" ("OccupationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
-------------------------------------------------------------
INSERT INTO public."HowDidYouKnow"(
"HowDidYouKnowId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (1, 'ABSOLUTE CURIOSITY', true, 6776, current_date),
(2, 'FAMILY TRADITION', true, 6776, current_date),
(3, 'HEARD FROM A COLLEAGUE/FRIEND', true, 6776, current_date),
(4, 'NEWS PAPER', true, 6776, current_date),
(5, 'PRACTO WEBSITE', true, 6776, current_date),
(6, 'REFERRED BY COLLEAGUE', true, 6776, current_date),
(7, 'REFERRED BY DOCTOR', true, 6776, current_date),
(8, 'REFERRED BY FRIEND', true, 6776, current_date),
(9, 'SECOND OPINION', true, 6776, current_date),
(10, 'WEBSEARCH', true, 6776, current_date);
-----------------------------------------------------------
INSERT INTO public."Education"(
"EducationId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (1, 'ANM', true, 6776, current_date),
(2, 'B PHARMACY', true, 6776, current_date),
(3, 'B TECH', true, 6776, current_date),
(4, 'BDS', true, 6776, current_date),
(5, 'Below 5th std', true, 6776, current_date),
(6, 'Below 9th std', true, 6776, current_date),
(7, 'Bsc Nursing', true, 6776, current_date),
(8, 'DGO', true, 6776, current_date),
(9, 'DNB', true, 6776, current_date),
(10, 'Fellowship', true, 6776, current_date),
(11, 'FRCOG', true, 6776, current_date),
(12, 'FRCS', true, 6776, current_date),
(13, 'GNM', true, 6776, current_date),
(14, 'Graduate', true, 6776, current_date),
(15, 'Intermediate', true, 6776, current_date),
(16, 'M PHARMACY', true, 6776, current_date),
(17, 'M phil', true, 6776, current_date),
(18, 'M.TECH', true, 6776, current_date),
(19, 'MBA', true, 6776, current_date),
(20, 'MBBS', true, 6776, current_date),
(21, 'MBBS & ABOVE', true, 6776, current_date),
(22, 'MCA', true, 6776, current_date),
(23, 'MD', true, 6776, current_date),
(24, 'MDS', true, 6776, current_date),
(25, 'Midwifery', true, 6776, current_date),
(26, 'MRCOG', true, 6776, current_date),
(27, 'MS', true, 6776, current_date),
(28, 'Msc Nursing', true, 6776, current_date),
(29, 'Not applicable', true, 6776, current_date),
(30, 'PHD', true, 6776, current_date),
(31, 'PHD in Nursing', true, 6776, current_date),
(32, 'Postgraduate', true, 6776, current_date),
(33, 'SSC', true, 6776, current_date),
(34, 'Uneducated', true, 6776, current_date);
----------------------------------------------------------
INSERT INTO public."Occupation"(
"OccupationId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (1, 'Accountant', true, 6776, current_date),
(2, 'Air Hostess', true, 6776, current_date),
(3, 'Architecht', true, 6776, current_date),
(4, 'Army', true, 6776, current_date),
(5, 'Barber', true, 6776, current_date),
(6, 'Beautician', true, 6776, current_date),
(7, 'BUMS', true, 6776, current_date),
(8, 'Business', true, 6776, current_date),
(9, 'Chairman', true, 6776, current_date),
(10, 'Chef', true, 6776, current_date),
(11, 'Counsellor', true, 6776, current_date),
(12, 'Doctor', true, 6776, current_date),
(13, 'Driver', true, 6776, current_date),
(14, 'Engineer', true, 6776, current_date),
(15, 'Farmer', true, 6776, current_date),
(16, 'Front Office', true, 6776, current_date),
(17, 'GOVT.EMPLOYEE', true, 6776, current_date),
(18, 'HEAD NURSE', true, 6776, current_date),
(19, 'Home Maker', true, 6776, current_date),
(20, 'House Keeping', true, 6776, current_date),
(21, 'HOUSEWIFE', true, 6776, current_date),
(22, 'HR', true, 6776, current_date),
(23, 'IAS/IPS', true, 6776, current_date),
(24, 'Industrialist', true, 6776, current_date),
(25, 'IT PROFESSIONAL', true, 6776, current_date),
(26, 'Labourer', true, 6776, current_date),
(27, 'Lawyer', true, 6776, current_date),
(28, 'Lecturer', true, 6776, current_date),
(29, 'LOBBY MANAGER', true, 6776, current_date),
(30, 'MAINTAINANCE INCHARGE', true, 6776, current_date),
(31, 'Manager', true, 6776, current_date),
(32, 'Managing Director', true, 6776, current_date),
(33, 'Mandal Revenue Officer', true, 6776, current_date),
(34, 'Matron', true, 6776, current_date),
(35, 'Mechanic', true, 6776, current_date),
(36, 'Navy', true, 6776, current_date),
(37, 'Nurse', true, 6776, current_date),
(38, 'NURSING SUPRINDENT', true, 6776, current_date),
(39, 'Occupationnm', true, 6776, current_date),
(40, 'OFFICER', true, 6776, current_date),
(41, 'OTHERS', true, 6776, current_date),
(42, 'PERSONAL MANAGER', true, 6776, current_date),
(43, 'Pharmacist', true, 6776, current_date),
(44, 'Pilot', true, 6776, current_date),
(45, 'Police Man', true, 6776, current_date),
(46, 'Politician', true, 6776, current_date),
(47, 'PRIVATE EMPLOYEE', true, 6776, current_date),
(48, 'Professor', true, 6776, current_date),
(49, 'Public Relation Officer', true, 6776, current_date),
(50, 'Receptionist', true, 6776, current_date),
(51, 'RETIRED', true, 6776, current_date),
(52, 'Security', true, 6776, current_date),
(53, 'Software Engineer', true, 6776, current_date),
(54, 'SOFTWARE(IT)', true, 6776, current_date),
(55, 'STUDENT', true, 6776, current_date),
(56, 'SUPERVISOR', true, 6776, current_date),
(57, 'Tailor', true, 6776, current_date),
(58, 'Teacher', true, 6776, current_date),
(59, 'Technician', true, 6776, current_date),
(60, 'Unemployed', true, 6776, current_date),
(61, 'WARD BOY', true, 6776, current_date),
(62, 'WORKING ABROAD', true, 6776, current_date);
\ No newline at end of file
alter table "Appointment" add column "LocationId" integer
alter table "Patient" add column "LocationId" integer
alter table "Appointment" add CONSTRAINT "FK_Appointment_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
alter table "Patient" add CONSTRAINT "FK_Patient_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
\ No newline at end of file
alter table "Settings" add Column "Numeral" integer
\ No newline at end of file
alter table "AppointmentLog"
add column "PatientRegistrationCharges" numeric(10,2);
alter table "AppointmentTransaction"
add column "StatusCheckInProgress" boolean default false;
\ No newline at end of file
-- FUNCTION: public.UDF_TEST1(integer, integer, integer, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."UDF_TEST1"(integer, integer, integer, text, integer, integer);
CREATE OR REPLACE FUNCTION public."UDF_TEST1"(
providerid integer,
specializationid integer,
locationid integer,
appointmentdate text,
chargetypesid integer,
consultationtypeid integer)
RETURNS TABLE("ProviderAvailabilityChargeTypeId" integer, "ChargeTypesId" integer, "ChargeName" character varying, "Charge" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
IF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."SpecializationId" = specializationid and PA."LocationId" = locationid
AND PA."StartDate"::DATE <= appointmentdate::DATE and PA."EndDate"::DATE >= appointmentdate::DATE
AND PA."ChargeTypesId" = chargetypesid And PA."ConsultationTypeId" = consultationtypeid
--END IF; 1
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."SpecializationId" = specializationId and PA."LocationId" = locationId
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."SpecializationId" = specializationId and PA."LocationId" = locationId and PA."ProviderId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."SpecializationId" = specializationId and PA."LocationId" = locationId and PA."ProviderId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
--END IF; 2
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName",PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."LocationId" = locationId and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."LocationId" = locationId and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
--END IF; 3
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName",PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."LocationId" = locationId and PA."ProviderId" is null and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."LocationId" = locationId and PA."ProviderId" is null and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
END IF; -- 1
end
$BODY$;
ALTER FUNCTION public."UDF_TEST1"(integer, integer, integer, text, integer, integer)
OWNER TO postgres;
ALTER TABLE "Cubicle" ADD COLUMN "LocationId" integer;
\ No newline at end of file
-- FUNCTION: public.udf_fetchProviderAvailabilityDatesNew(integer, integer, integer, text, text)
-- DROP FUNCTION IF EXISTS public."udf_fetchProviderAvailabilityDatesNew"(integer, integer, integer, text, text);
CREATE OR REPLACE FUNCTION public."udf_fetchProviderAvailabilityDatesNew"(
providerid integer,
locationid integer,
specializationid integer,
startdate text,
enddate text)
RETURNS TABLE("Date" date, "DateNumber" integer, "DayName" character varying, "Status" character)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with TotalDates as (
SELECT DISTINCT generate_series( startDate::date,endDate::date, '1 day')::date "Dates" ,
--generate_series(timestamp '2022-10-31', '2023-03-16', '1 day')::date AS "Dates",
--generate_series(timestamp A."StartDate", A."EndDate", '1 day')::date AS "Dates",
A."ProviderId",A."ProviderAvailabilityId",A."LocationId", A."StartDate", A."EndDate", A."LocationId", S."SpecializationId"
from "ProviderAvailability" A
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Provider" PR on A."ProviderId" = PR."ProviderId" AND PR."Active" = TRUE
JOIN "Specialization" S on S."SpecializationId" = ANY(PR."Specializations") AND S."Active" IS TRUE
--JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."LocationId" = locationId And S."SpecializationId" = specializationId And A."Active" IS TRUE
)
,Availability as (
select A."FreeFollowUpDays", A."AvailableDay", A."ProviderAvailabilityId"
--A."ProviderId"
--,A."ProviderLocationId"
,A."LocationId", A."StartDate", A."EndDate", S."SpecializationId"
--,json_array_elements(case when (A."Availability" is null or A."Availability"='') then '[]' else (A."Availability"::json)end) "Availability"
from "ProviderAvailability" A
--left join "ProviderAvailabilitySlot" PAS on PAS."ProviderAvailabilityId" = A."ProviderAvailabilityId"
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Provider" PR on A."ProviderId" = PR."ProviderId" AND PR."Active" = TRUE
JOIN "Specialization" S on S."SpecializationId" = ANY(PR."Specializations") AND S."Active" IS TRUE
--JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
--JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."LocationId" = locationId And S."SpecializationId" = specializationId And A."Active" IS TRUE
--and case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
)
,Avail as (
SELECT unnest(string_to_array(A."AvailableDay", ',')) AS "Day", A."ProviderAvailabilityId",A."LocationId", A."StartDate", A."EndDate", A."SpecializationId"
from Availability A
)
, LeaveAvailability as (
select A."ProviderId",A."LeaveDate",coalesce(A."ProviderAvailabilityId"::text,
(
select string_agg(D."ProviderAvailabilityId"::text,',') "ProviderAvailabilityId" from "ProviderAvailability" D where D."ProviderId"= providerid and D."LocationId" = locationId
))
"ProviderAvailabilityId" from "ProviderLeave" A where A."ProviderId"=providerid and A."LocationId" = locationId
)
,LeaveData as (
select A."ProviderId",A."LeaveDate",regexp_split_to_table(A."ProviderAvailabilityId",',') ::int "ProviderAvailabilityId"
from LeaveAvailability A
)
,FinalData as (
select DISTINCT C."LeaveDate", A."Dates" "Date", A."ProviderId",A."ProviderAvailabilityId",A."StartDate",A."EndDate"
--,A."LocationId"
,extract(ISODOW from "Dates")"DateNo", CASE
WHEN extract(ISODOW from "Dates") =1 THEN 'Monday'
WHEN extract(ISODOW from "Dates") =2 THEN 'Tuesday'
WHEN extract(ISODOW from "Dates")=3 THEN 'Wednesday'
WHEN extract(ISODOW from "Dates")=4 THEN 'Thursday'
WHEN extract(ISODOW from "Dates")=5 THEN 'Friday'
WHEN extract(ISODOW from "Dates")=6 THEN 'Saturday'
WHEN extract(ISODOW from "Dates")=7 THEN 'Sunday' end "Day" ,
case when C."LeaveDate" is not null then 'L' when B."Day" is not null then 'A' else '' end "Status"
from TotalDates A
left join Avail B on B."Day"::text::int = extract(ISODOW from A."Dates") and A."ProviderId"=A."ProviderId" and A."ProviderAvailabilityId"=B."ProviderAvailabilityId"
--and A."LocationId"=B."LocationId"
left join LeaveData C on C."LeaveDate"::date =A."Dates" and A."ProviderAvailabilityId"=C."ProviderAvailabilityId"
)
select DISTINCT A."Date",A."DateNo"::int,A."Day"::text::character varying(10),A."Status"::char
from FinalData A
where
--A."Date" >= A."StartDate"::Date or
A."Date" <= A."EndDate"::Date
order by A."Date";
end
$BODY$;
ALTER FUNCTION public."udf_fetchProviderAvailabilityDatesNew"(integer, integer, integer, text, text)
OWNER TO postgres;
alter table "Specialization" add Column "EncounterTypeId" integer
create sequence "IvfEncounter_IvfEncounterId_seq";
CREATE TABLE IF NOT EXISTS public."IvfEncounter"
(
"IvfEncounterId" bigint NOT NULL DEFAULT nextval('"IvfEncounter_IvfEncounterId_seq"'::regclass),
"AppointmentId" integer,
"IvfEncounterDate" timestamp(6) without time zone NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"AdmissionId" integer,
CONSTRAINT "IvfEncounter_pkey" PRIMARY KEY ("IvfEncounterId"),
CONSTRAINT "UQ_IvfEncounter" UNIQUE ("IvfEncounterId")
);
alter table "IvfEncounter" add "GynHistory" text;
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment