Commit 9b14a52b authored by Sandeep Sagar Panjala's avatar Sandeep Sagar Panjala

initial commit

parent f0b314d4
ALTER TABLE public."Appointment"
ADD COLUMN "WaitingPriority" integer;
\ No newline at end of file
ALTER TABLE public."AccountSession"
ADD COLUMN "WebToken" text COLLATE pg_catalog."default";
\ No newline at end of file
ALTER TABLE IF EXISTS public."Account"
DROP CONSTRAINT "UQ_Account";
ALTER TABLE IF EXISTS public."Account"
ADD CONSTRAINT "UQ_Account" UNIQUE("RoleId", "ReferenceId", "CountryId");
ALTER TABLE IF EXISTS public."Patient"
DROP CONSTRAINT uq_patient_mobile ;
\ No newline at end of file
ALTER TABLE "LabServices"
ADD COLUMN IF NOT EXISTS "LabMainDetailId" integer;
ALTER TABLE "LabServices"
ADD CONSTRAINT "FK_LabServices_LabMainDetailId" FOREIGN KEY ("LabMainDetailId") REFERENCES "LabMainDetail" ("LabMainDetailId");
ALTER TABLE "NewLabBookingHeader"
ADD COLUMN IF NOT EXISTS "AdmissionId" integer;
insert into "LabBookingStatus" ("Status","Active")
values('SampleVerified',true),('SampleRejected',true);
\ No newline at end of file
CREATE SEQUENCE public."LocationDepartmentMap_LocationDepartmentMapId_seq";
CREATE TABLE public."LocationDepartmentMap"
(
"LocationDepartmentMapId" integer NOT NULL DEFAULT nextval('"LocationDepartmentMap_LocationDepartmentMapId_seq"'::regclass),
"DepartmentId" integer NOT NULL,
"LocationId" integer NOT NULL,
CONSTRAINT "LocationDepartmentMap_pkey" PRIMARY KEY ("LocationDepartmentMapId"),
CONSTRAINT "FK_LocationDepartmentMap_DepartmentId" FOREIGN KEY ("DepartmentId")
REFERENCES public."Department" ("DepartmentId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "FK_LocationDepartmentMap_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
);
\ No newline at end of file
--Delete these unused tables
Drop TABLE IF EXISTS "LabGroup";
Drop TABLE IF EXISTS "LabOrderHdr";
Drop TABLE IF EXISTS "LabOrderValue";
Drop TABLE IF EXISTS "LabOrder";
--Add a Map table for LabPackage with Location
CREATE TABLE IF NOT EXISTS "LocationLabPackageMap" (
"LocationLabPackageMapId" serial PRIMARY KEY,
"LocationId" INT REFERENCES "Location"("LocationId") NOT NULL,
"LabPackageId" INT REFERENCES "LabPackage"("LabPackageId") NOT NULL,
"Amount" numeric not null,
"IsActive" bool DEFAULT true,
"CreatedBy" INT REFERENCES "Account"("AccountId"),
"CreatedDate" timestamp(6) without time zone,
"ModifiedBy" integer REFERENCES "Account"("AccountId"),
"ModifiedDate" timestamp(6) without time zone
);
--Add a Map table for LocationLabHeaderMap with Location
CREATE TABLE IF NOT EXISTS "LocationLabHeaderMap" (
"LocationLabHeaderMapId" serial PRIMARY KEY,
"LocationId" INT REFERENCES "Location"("LocationId") NOT NULL,
"LabHeaderId" INT REFERENCES "LabHeader"("LabHeaderId") NOT NULL,
"Charge" numeric NOT NULL,
"InPatientCharge" numeric ,
"IsActive" bool DEFAULT true,
"CreatedBy" INT REFERENCES "Account"("AccountId"),
"CreatedDate" timestamp(6) without time zone,
"ModifiedBy" integer REFERENCES "Account"("AccountId"),
"ModifiedDate" timestamp(6) without time zone
);
--Select * from "Location"
--Insert Data into "LocationLabPackageMap" table
INSERT INTO "LocationLabPackageMap" ("LocationId","LabPackageId","Amount")
SELECT (Select "LocationId" from "Location" where "Name"='Vikarabad'), "LabPackageId","Amount" from "LabPackage";
--Insert Data into "LocationLabHeaderMap" table
INSERT INTO "LocationLabHeaderMap" ("LocationId","LabHeaderId","Charge","InPatientCharge")
SELECT (Select "LocationId" from "Location" where "Name"='Vikarabad'), "LabHeaderId","Charge","InPatientCharge" from "LabHeader";
--Add LocationMapping to LabBookingHeader Table
ALTER TABLE "LabBookingHeader" ADD COLUMN IF NOT EXISTS "LocationId" INT REFERENCES "Location"("LocationId");
--Update LocationId in "LabBookingHeader" table
UPDATE "LabBookingHeader" SET "LocationId"= (Select "LocationId" from "Location" where "Name"='Vikarabad');
--Add LocationMapping to LabLog Table
ALTER TABLE "LabLog" ADD COLUMN IF NOT EXISTS "LocationId" INT REFERENCES "Location"("LocationId");
--Update LocationId in "LabLog" table
UPDATE "LabLog" SET "LocationId"= (Select "LocationId" from "Location" where "Name"='Vikarabad');
/*
Navicat Premium Data Transfer
Source Server : 96 Server 5433
Source Server Type : PostgreSQL
Source Server Version : 100003
Source Host : 192.168.8.96:5433
Source Catalog : Hims_21_June_2021
Source Schema : public
Target Server Type : PostgreSQL
Target Server Version : 100003
File Encoding : 65001
Date: 18/04/2022 14:49:15
*/
-- ----------------------------
-- Table structure for Location
-- ----------------------------
DROP TABLE IF EXISTS "public"."Location";
CREATE TABLE "public"."Location" (
"LocationId" serial,
"Name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
"CreatedBy" int4 NOT NULL,
"CreatedDate" timestamp(6) NOT NULL
)
;
-- ----------------------------
-- Records of Location
-- ----------------------------
INSERT INTO "public"."Location"("Name","CreatedBy","CreatedDate") VALUES ( 'Hitech City', 1029, now());
INSERT INTO "public"."Location"("Name","CreatedBy","CreatedDate") VALUES ('Uppal', 1029, now());
-- ----------------------------
-- Primary Key structure for table Location
-- ----------------------------
ALTER TABLE "public"."Location" ADD CONSTRAINT "Location_pkey" PRIMARY KEY ("LocationId");
-- ----------------------------
-- Foreign Keys structure for table Location
-- ----------------------------
ALTER TABLE "public"."Location" ADD CONSTRAINT "FK_Location_CreatedBy" FOREIGN KEY ("CreatedBy") REFERENCES "public"."Account" ("AccountId") ON DELETE NO ACTION ON UPDATE NO ACTION;
/*
Navicat Premium Data Transfer
Source Server : 96 Server 5433
Source Server Type : PostgreSQL
Source Server Version : 100003
Source Host : 192.168.8.96:5433
Source Catalog : Hims_21_June_2021
Source Schema : public
Target Server Type : PostgreSQL
Target Server Version : 100003
File Encoding : 65001
Date: 18/04/2022 14:49:29
*/
-- ----------------------------
-- Table structure for LocationAccountMap
-- ----------------------------
DROP TABLE IF EXISTS "public"."LocationAccountMap";
CREATE TABLE "public"."LocationAccountMap" (
"LocationAccountMapId" serial,
"LocationId" int4 NOT NULL,
"AccountId" int4 NOT NULL
)
;
-- ----------------------------
-- Primary Key structure for table LocationAccountMap
-- ----------------------------
ALTER TABLE "public"."LocationAccountMap" ADD CONSTRAINT "LocationAccountMap_pkey" PRIMARY KEY ("LocationAccountMapId");
-- ----------------------------
-- Foreign Keys structure for table LocationAccountMap
-- ----------------------------
ALTER TABLE "public"."LocationAccountMap" ADD CONSTRAINT "FK_LocationAccountMap_AccountId" FOREIGN KEY ("AccountId") REFERENCES "public"."Account" ("AccountId") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "public"."LocationAccountMap" ADD CONSTRAINT "FK_LocationAccountMap_LocationId" FOREIGN KEY ("LocationId") REFERENCES "public"."Location" ("LocationId") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE public."Admission"
ADD COLUMN "LocationId" integer;
\ No newline at end of file
INSERT INTO "LocationAccountMap" ("LocationId", "AccountId")
SELECT (SELECT "LocationId" FROM "Location" WHERE "Name" = 'Uppal'), "AccountId" FROM "Account";
Update "Admission" SET "LocationId" = (SELECT "LocationId" from "Location" where "Name" = 'Uppal');
CREATE OR REPLACE FUNCTION "public"."udf_fetch_Admission"("admissionNo" text=NULL::text, "providerId" int4=NULL::integer, "patientId" int4=NULL::integer, "isDischarged" bool=NULL::boolean, "patientMobileNo" text=NULL::text, "fromDate" date=NULL::date, "toDate" date=NULL::date, "dischargeDate" date=NULL::date, "uMRNo" text=NULL::text, "active" bool=NULL::boolean, "locationId" int4=0, "pageIndex" int4=0, "pageSize" int4=10)
RETURNS TABLE("AdmissionId" int4, "AdmissionNo" text, "IsConvertedFromOPtoIp" bool, "AdmissionDate" timestamp, "AdmissionTime" time, "PatientName" text, "UMRNo" varchar, "PatientAge" int2, "PatientGender" bpchar, "patientMobile" varchar, "ProviderAge" int2, "ProviderGender" bpchar, "ProviderName" text, "DepartmentName" text, "WardName" varchar, "RoomName" varchar, "BedNumber" varchar, "AttendantName" varchar, "AttendantRelationWithPatient" varchar, "AttendantContactNo" varchar, "IsDischarged" bool, "DischargeDate" date, "DischargeTime" time, "DischargeStatus" varchar, "IsMaternity" bool, "EncounterId" int4, "SurgeryName" varchar, "ProviderThumbnailUrl" text, "PatientThumbnailUrl" text, "BedId" int4, "RoomId" int4, "WardId" int4, "DepartmentId" int4, "PatientId" int4, "ProviderId" int4, "SurgeryTypeId" int4, "PatientType" bpchar, "AdmissionNotes" text, "PaidAmount" numeric, "FinalAmount" numeric, "PaymentStatus" text, "IsFinalBill" bool, "TotalItems" int8, "Active" bool, "ExpectedDischargeDate" timestamp, "DischargedBy" int4, "DischargedByRole" text, "DischargedByName" text, "LocationName" text) AS $BODY$
BEGIN
return query
With TotalItems as (
select count(distinct A."AdmissionId")::bigint "TotalItems"
from "Admission" A
join "Location" l on l."LocationId" = A."LocationId"
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
where l."LocationId" = "locationId"
And
case when "admissionNo" is null then 1=1
when "admissionNo"='' then 1=1
else A."AdmissionNo" ilike '%'||"admissionNo"||'%' end and
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "providerId" is null then 1=1
else Pr."ProviderId" = "providerId" end and
case when "isDischarged" is null then 1=1
when "isDischarged" =true then ds."AdmissionId"=A."AdmissionId"
when "isDischarged" =false then ds."AdmissionId" is null
end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate" and A."AdmissionDate" <="toDate" end
)
select A."AdmissionId",A."AdmissionNo",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName" "PatientName",Pa."UMRNo",Pa."Age" "PatientAge",Pa."Gender" as "PatientGender",pa."Mobile" "patientMobile",Pr."Age" "ProviderAge",Pr."Gender" as "ProviderGender",
Pr."FullName"::text "ProviderName",D."DepartmentName"::text "DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName" "AttendantName",A."AttendantRelationWithPatient" "AttendantRelationWithPatient",A."AttendantContactNo" "AttendantContactNumber",
case when ds."DischargeId" is not null then true else false end as "IsDischarged",ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus"
,A."IsMaternity",A."EncounterId",st."SurgeryName",
(CASE WHEN pr."ThumbnailUrl" IS NOT NULL THEN CONCAT(pr."Guid", '/', pr."ThumbnailUrl") ELSE NULL END) AS "ProviderThumbnailUrl",
(CASE WHEN pa."ThumbnailUrl" IS NOT NULL THEN CONCAT(pa."Guid", '/', pa."ThumbnailUrl") ELSE NULL END) AS "PatientThumbnailUrl"
,A."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,
sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0) "PaidAmount"
,
FB."FinalAmount" ,
case when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))=0 then 'Payment Cleared'
when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))>0 then 'Payment Due'
when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))<0 then 'Pending Refund' end "PaymentStatus",
case when FB."FinalBillId" is null then false else true end "IsFinalBill",(select T."TotalItems" from TotalItems T) "TotalItems",
A."Active",
A."ExpectedDischargeDate",
A."DischargedBy" ,
case when RL."RoleId" = '3' then DP."DepartmentName"::TEXT else RL."RoleName"::TEXT end as "DischargedByRole",
case when RL."RoleId" = '3' then PRO."FullName" else AC."FullName" end as "DischargedByName",
l."Name" "LocationName"
from "Admission" A
join "Location" l on l."LocationId" = A."LocationId"
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
left join "Account" AC on AC."AccountId"=A."DischargedBy"
left join "Role" RL on RL."RoleId"= AC."RoleId"
left join "Provider" PRO on PRO."ProviderId"=AC."ReferenceId"
left join "Department" DP on DP."DepartmentId"=PRO."DepartmentId"
where l."LocationId" = "locationId"
And
case when "admissionNo" is null then 1=1
when "admissionNo"='' then 1=1
else A."AdmissionNo" ilike '%'||"admissionNo"||'%' end and
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "providerId" is null then 1=1
else Pr."ProviderId" = "providerId" end and
case when "isDischarged" is null then 1=1
when "isDischarged" =true then ds."AdmissionId"=A."AdmissionId"
when "isDischarged" =false then ds."AdmissionId" is null
end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate"::date and A."AdmissionDate"::date <="toDate" end
AND
case when "dischargeDate" is null then 1=1 else "dischargeDate" =ds."DischargeDate"::date end
and
case when "uMRNo" is null then 1=1
when "uMRNo"='' then 1=1
else Pa."UMRNo" ilike '%'||"uMRNo"||'%' end
group by A."AdmissionId",A."AdmissionNo",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName",Pa."UMRNo",Pa."Age" ,Pa."Gender" ,Pr."Age" ,Pr."Gender" ,
Pr."FullName",D."DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName",A."AttendantRelationWithPatient",A."AttendantContactNo" , ds."DischargeId",
l."Name",
ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus",pa."Mobile"
,A."IsMaternity",A."EncounterId",st."SurgeryName",pr."ThumbnailUrl", pr."Guid",pr."ThumbnailUrl" ,pa."Guid", pa."ThumbnailUrl",
A."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,FB."FinalAmount" ,FB."FinalBillId",
RL."RoleId",DP."DepartmentName",PRO."FullName",AC."FullName"
order by A."AdmissionId" desc
limit "pageSize" offset ("pageSize"*"pageIndex");
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000
\ No newline at end of file
Alter table "PharmacyIndentHeader" add column "LocationId" int references "Location"("LocationId");
--Select * from "Location"
--Update "PharmacyIndentHeader" set "LocationId" = 2;
Alter table "PharmacyRequestIndentHeader" add column "LocationId" int references "Location"("LocationId");
--Select * from "Location"
update "PharmacyRequestIndentHeader" set "LocationId" = 2;
DROP FUNCTION public."udf_DailySalesReportByMedication"(text, text, text, text, text, date, date);
DROP FUNCTION public."udf_DailySalesReportByMedication"(text, text, text, text, text, text, date, date);
CREATE OR REPLACE FUNCTION public."udf_DailySalesReportByMedication"(
"productName" text DEFAULT NULL::text,
"genericName" text DEFAULT NULL::text,
"categoryName" text DEFAULT NULL::text,
"companyName" text DEFAULT NULL::text,
"supplierName" text DEFAULT NULL::text,
"paidVia" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"locationId" int default null)
RETURNS TABLE("PharmacyProductId" integer, "ProductName" character varying, "BatchNumber" character varying, "GenericName" character varying, "CategoryName" character varying, "CompanyName" text, "SupplierName" text, "SaleQuantity" bigint, "Mrp" numeric, "Discount" numeric, "TotalAmount" numeric, "PaidVia" text, "SaleDate" timestamp without time zone, "PurchaseValue" numeric,
"PurchaseUnitQty" integer, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select A."PharmacyProductId",A."ProductName",A."BatchNumber",A."GenericName",A."CategoryName ",A."CompanyName"
,A."SupplierName"
,sum(A."Quantity") "SaleQuantity",A."Mrp",A."OverallDiscount" "Discount",sum(A."NetAmount") "TotalAmount"
,A."PaidVia",A."SaleDate" , TRUNC((A."PPD_NetAmount"/A."PPD_Quantity"),2) as "PurchaseValue"
,A."PurchaseUnitQty",A."LocationName"
from (
select PS."PharmacyProductId",PP."ProductName",PRS."BatchNumber",pp."GenericName",ci."Name" "CategoryName ",c."Name" "CompanyName",s."Name" "SupplierName"
,PH."SaleDate",PS."Quantity",PRS."Mrp",Ps."Discount" "OverallDiscount",PS."NetAmount" , PH."PaidVia",
ppd."NetAmount" as "PPD_NetAmount",ppd."Quantity" as "PPD_Quantity",L."Name" as "LocationName"
,pp."PurchaseUnitQty"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyPurchaseDetail" Ppd on ppd."PharmacyStockId"=prs."PharmacyStockId" and ppd."PharmacyProductId"=PRS."PharmacyProductId"
join "PharmacyPurchaseHeader" pph on pph."PharmacyPurchaseHeaderId"=Ppd."PharmacyPurchaseHeaderId"
join "Supplier" s on s."SupplierId"=pph."SupplierId"
join "Location" L on L."LocationId" = PH."LocationId"
where case when "productName" ='' then 1=1 when "productName" is null then 1=1 else PP."ProductName" ilike '%'||"productName"||'%' end and
case when "genericName" ='' then 1=1 when "genericName" is null then 1=1 else pp."GenericName" ilike '%'||"genericName"||'%' end and
case when "categoryName" ='' then 1=1 when "categoryName" is null then 1=1 else ci."Name" ilike '%'||"categoryName"||'%' end and
case when "companyName" ='' then 1=1 when "companyName" is null then 1=1 else c."Name" ilike '%'||"companyName"||'%' end and
case when "supplierName" ='' then 1=1 when "supplierName" is null then 1=1 else s."Name" ilike '%'||"supplierName"||'%' end and
case when "paidVia" ='' then 1=1 when "paidVia" is null then 1=1 else PH."PaidVia" ilike '%'||"paidVia"||'%' end and
case when "fromDate" is null then 1=1 else "fromDate" ::date <=PH."SaleDate"::date and PH."SaleDate"::date <="toDate" ::date end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PS."PharmacyProductId",PP."ProductName",PRS."BatchNumber",PH."SaleDate"
,pp."GenericName",ci."Name",c."Name" ,s."Name" ,PS."Quantity",PS."NetAmount",PRS."Mrp",Ps."Discount" ,PH."PaidVia" ,
ppd."NetAmount", ppd."Quantity",pp."PurchaseUnitQty",L."Name") A
group by A."PharmacyProductId",A."ProductName",A."BatchNumber",A."GenericName",A."CategoryName ",
A."CompanyName",A."SupplierName",A."Mrp",A."OverallDiscount",A."PaidVia",A."SaleDate", (A."PPD_NetAmount"/A."PPD_Quantity") , A."PurchaseUnitQty",
A."LocationName"
order by A."ProductName"
;
END
$BODY$;
-----
DROP FUNCTION public."udf_PharmacySales_Report"(timestamp without time zone, timestamp without time zone, integer, character varying);
CREATE OR REPLACE FUNCTION public."udf_PharmacySales_Report"(
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"createdBy" integer DEFAULT NULL::integer,
"paidVia" character varying DEFAULT NULL::text,
"locationId" text default null)
RETURNS TABLE("SaleDate" timestamp without time zone, "TotalAmount" numeric, "TotalTaxes" numeric, "TotalDiscount" numeric, "TotalNetAmount" numeric,
"PaidVia" text,"LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."SaleDate" , sum(PH."Total") "Total", sum(PH."OverallTaxes") "OverallTaxes",
sum(PH."OverallDiscount") "OverallDiscount",
sum(PH."OverallNetAmount") "OverallNetAmount", PH."PaidVia",L."Name" as "LocationName"
from "PharmacySaleHeader" PH
join "Location" L on L."LocationId" = PH."LocationId"
where case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end
and case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end
and case when "createdBy" is null then 1=1 else PH."CreatedBy"="createdBy" end
and case when "paidVia" is null then 1=1 else PH."PaidVia" ilike'%'|| "paidVia"||'%' end
and case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."SaleDate",PH."PaidVia",L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
-----
DROP FUNCTION public."udf_PharmacySalesReport"(date, date);
DROP FUNCTION public."udf_PharmacySalesReport"(date, date, integer, character varying);
DROP FUNCTION public."udf_PharmacySalesReport"(date, date, character varying);
DROP FUNCTION public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_Report"(
"billNumber" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"paidVia" character varying DEFAULT NULL::text,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text default null::text)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "PaidVia" text, "CreatedByName" text, "RoleName" character varying, "ProviderName" character varying, "TotalAmount" numeric, "RetailName" text,
"OverallTaxes" numeric,"LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."CreatedDate" "SaleDate",PH."PatientName",PH."Mobile"
,Pa."UMRNo",PH."PaidVia",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."ProviderName", PH."OverallNetAmount" ,RP."RetailName",PH."OverallTaxes",L."Name" as "LocationName"
from "PharmacySaleHeader" PH
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
--join "Provider" pr on pr."ProviderId"::text=PH."ProviderId"::text
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
join "Location" L on L."LocationId" = PH."LocationId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "paidVia" is null then 1=1 else PH."PaidVia" ilike '%' || "paidVia" ||'%' end and
case when "providerId" is null then 1=1 else PH."ProviderId" ="providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."SaleDate", PH."OverallNetAmount",PH."PatientName",PH."Mobile",Pa."UMRNo",PH."PaidVia",A."FullName"
,R."RoleName" ,PH."ProviderName",RP."RetailName",PH."OverallTaxes",L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
---------
DROP FUNCTION public."udf_PharmacyBills_FinalReport"(text, integer, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, boolean);
DROP FUNCTION public."udf_PharmacyBills_FinalReport"(text, integer, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, boolean);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_FinalReport"(
"billNumber" text DEFAULT NULL::text,
"accountId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"paidVia" character varying DEFAULT NULL::text,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text default null::text,
"pharmacyBillType" boolean DEFAULT NULL::boolean)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying, "PaidVia" text, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "ProviderName" character varying, "CreatedByName" text, "RoleName" character varying, "TotalAmount" numeric, "SaleReturnHeaderId" integer, "OverallTaxes" numeric, "RetailName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",PH."SaleDate" "SaleDate",PH."PatientName",
PH."Mobile" ,Ph."UMRNo",PH."ProviderName",ph."CreatedByName",
ph."Role", PH."OverallNetAmount",PH."SaleReturnHeaderId" ,PH."OverallTaxes",PH."RetailName"
from
(
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",PH."CreatedDate" "SaleDate",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",PH."ProviderName",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."OverallNetAmount",true "PharmacyBillType",null "SaleReturnHeaderId",PH."OverallTaxes",
RP."RetailName"
from "PharmacySaleHeader" PH
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "accountId" is null then 1=1 else PH."CreatedBy"="accountId" end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "paidVia" is null then 1=1 else PH."PaidVia" ilike '%' || "paidVia" ||'%' end and
case when "providerId" is null then 1=1 else PH."ProviderId" = "providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",PH."SaleDate", PH."OverallNetAmount",
PH."PatientName",PH."ProviderName",Pa."UMRNo",A."FullName"
,R."RoleName",RP."RetailName"
union
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",srh."ReturnDate" "SaleDate",PH."PatientName",
Ph."Mobile" ,Pa."UMRNo",PH."ProviderName",A."FullName"
"CreatedByName",R."RoleName" "Role", -srh."OverallNetAmount" "TotalAmount",false "PharmacyBillType"
,srh."SaleReturnHeaderId",srh."OverallTaxes",
RP."RetailName"
from "SaleReturnHeader" srh
Join "PharmacySaleHeader" ph on ph."PharmacySaleHeaderId"= srh."PharmacySaleHeaderId"
join "Account" A on A."AccountId"=srh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "accountId" is null then 1=1 else srh."CreatedBy"="accountId" end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "paidVia" is null then 1=1 else PH."PaidVia" ilike '%' || "paidVia" ||'%' end and
case when "providerId" is null then 1=1 else PH."ProviderId" = "providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else srh."ReturnDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else srh."ReturnDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else ph."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",srh."ReturnDate", srh."OverallNetAmount",
PH."PatientName",Pa."Mobile",Pa."UMRNo",PH."ProviderName",A."FullName"
,R."RoleName",srh."SaleReturnHeaderId", RP."RetailName"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."SaleDate" desc, PH."PharmacySaleHeaderId";
END
$BODY$;
------------
DROP FUNCTION public."udf_PharmacyPurchaseReport"(text, text, integer, text, text, date, timestamp without time zone, timestamp without time zone, boolean, integer);
CREATE OR REPLACE FUNCTION public."udf_PharmacyPurchaseReport"(
"billNumber" text DEFAULT NULL::text,
"billType" text DEFAULT NULL::text,
"createdBy" integer DEFAULT NULL::integer,
"supplierName" text DEFAULT NULL::text,
"paidVia" text DEFAULT NULL::text,
"dueDate" 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,
"pharmacyBillType" boolean DEFAULT NULL::boolean,
"pharmacyWareHouseId" integer DEFAULT NULL::integer,
"locationId" text default null::text)
RETURNS TABLE("PharmacyPurchaseHeaderId" integer, "DueDate" timestamp without time zone,
"BillNumber" character varying, "BillType" character varying,
"BillDate" timestamp without time zone, "CreatedByName" text, "RoleName" character varying,
"SupplierName" text, "SupplierId" integer, "NetAmount" numeric, "WareHouseName" text,
"LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",PH."BillDate",ph."CreatedByName",
ph."Role",ph."SupplierName",PH."SupplierId", PH."NetAmount",PH."WareHouseName",PH."LocationName" from
(
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",PH."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName",S."SupplierId" ,PH."Netamount" "NetAmount",true "PharmacyBillType"
,PW."WareHouseName",L."Name" as "LocationName"
from "PharmacyPurchaseHeader" PH
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "Account" A on A."AccountId"=ph."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacyWareHouse" PW on PW."PharmacyWareHouseId"=PH."PharmacyWareHouseId"
join "Location" L on L."LocationId" = PW."LocationId"
left join "PharmacyPurchaseReturnHeader" pr on pr."PharmacyPurchaseHeaderId" = PH."PharmacyPurchaseHeaderId"
where
case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end
and case when "paidVia" is null then 1=1 else PH."BillType" ilike '%' || "paidVia" ||'%' end and
case when "dueDate" is null then 1=1 else "dueDate" =PH."DueDate"::date end
and case when "fromDate" is null then 1=1
else (PH."CreatedDate" >= "fromDate" and PH."CreatedDate" <= "toDate") end and
case when "pharmacyWareHouseId" is null then 1=1 else PW."PharmacyWareHouseId" = "pharmacyWareHouseId" end and
case when "locationId" is null then 1=1 else PW."LocationId" = "locationId"::int end
group by PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate", PH."Netamount",S."Name",S."SupplierId",
A."FullName" ,R."RoleName",PW."WareHouseName",L."Name"
union
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",prh."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName",S."SupplierId", -prh."OverallNetamount" "Netamount",false "PharmacyBillType"
,PW."WareHouseName",L."Name" as "LocationName"
from "PharmacyPurchaseReturnHeader" prh
join "Account" A on A."AccountId"=prh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
Join "PharmacyPurchaseHeader" ph on ph."PharmacyPurchaseHeaderId"= prh."PharmacyPurchaseHeaderId"
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyWareHouse" PW on PW."PharmacyWareHouseId" =ph."PharmacyWareHouseId"
join "Location" L on L."LocationId" = PW."LocationId"
where
case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end
and case when "paidVia" is null then 1=1 else PH."BillType" ilike '%' || "paidVia" ||'%' end and
case when "dueDate" is null then 1=1 else "dueDate" =PH."DueDate"::date end
--and case when "fromDate" is null then 1=1 else PH."BillDate" >= "fromDate" end
--and case when "toDate" is null then 1=1 else PH."BillDate" <= "toDate" end
and case when "fromDate" is null then 1=1
else (PH."CreatedDate" >= "fromDate" and PH."CreatedDate" <= "toDate") end and
case when "pharmacyWareHouseId" is null then 1=1 else PW."PharmacyWareHouseId" = "pharmacyWareHouseId" end and
case when "locationId" is null then 1=1 else PW."LocationId" = "locationId"::int end
group by PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",prh."CreatedDate",A."FullName"
,R."RoleName" ,S."Name" ,s."SupplierId", prh."OverallNetamount",PW."WareHouseName",L."Name"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."BillDate" desc, PH."PharmacyPurchaseHeaderId";
END
$BODY$;
-----------------
DROP FUNCTION public."udf_ProductPurchaseReport"(text, text, integer, text, text, date, date, boolean);
CREATE OR REPLACE FUNCTION public."udf_ProductPurchaseReport"(
"billNumber" text DEFAULT NULL::text,
"billType" text DEFAULT NULL::text,
"createdBy" integer DEFAULT NULL::integer,
"supplierName" text DEFAULT NULL::text,
"productName" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"pharmacyBillType" boolean DEFAULT NULL::boolean,
"locationId" text default null::text)
RETURNS TABLE("ProductName" character varying, "GenericName" character varying, "CategoryName" character varying, "PurchaseRate" numeric, "Quantity" numeric, "Mrp" numeric, "TaxAmount" numeric, "PharmacyPurchaseHeaderId" integer, "BillNumber" character varying, "BillType" character varying, "BillDate" timestamp without time zone, "CreatedByName" text, "RoleName" character varying, "SupplierName" text, "NetAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."ProductName",PH."GenericName",PH."CategoryName",PH."PurchaseRate",PH."Quantity",PH."Mrp",PH."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."BillDate",ph."CreatedByName",
ph."Role",ph."SupplierName", PH."NetAmount" from
(
select PP."ProductName",PP."GenericName",ci."Name" "CategoryName",PPD."PurchaseRate",PPD."Quantity",PPD."Mrp",PPD."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName", ppd."NetAmount" "NetAmount",true "PharmacyBillType"
from "PharmacyPurchaseHeader" PH
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyPurchaseDetail" ppd on ppd."PharmacyPurchaseHeaderId" = ph."PharmacyPurchaseHeaderId"
join "PharmacyProduct" pp on pp."PharmacyProductId" = ppd."PharmacyProductId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Account" A on A."AccountId"=ph."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacyWareHouse" PWH on PWH."PharmacyWareHouseId" = PH."PharmacyWareHouseId"
left join "PharmacyPurchaseReturnHeader" pr on pr."PharmacyPurchaseHeaderId" = PH."PharmacyPurchaseHeaderId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end and
case when "productName" is null then 1=1 else pp."ProductName" ilike '%' || "productName" ||'%' end
and case when "fromDate" is null then 1=1 else PH."BillDate"::date >= "fromDate" end
and case when "toDate" is null then 1=1 else PH."BillDate"::date <= "toDate" end and
case when "locationId" is null then 1=1 else PWH."LocationId" = "locationId"::int end
group by PP."ProductName",PP."GenericName",ci."Name",PPD."PurchaseRate",PPD."Quantity",PPD."Mrp",PPD."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate", ppd."NetAmount",S."Name",
A."FullName" ,R."RoleName"
union
select PP."ProductName",PP."GenericName",ci."Name" "CategoryName",PPD."PurchaseRate",
PrD."ReturnQuantity" "Quantity",PPD."Mrp",PrD."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",prh."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName", -prd."NetAmount" "Netamount",false "PharmacyBillType"
from "PharmacyPurchaseReturnHeader" prh
join "Account" A on A."AccountId"=prh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
Join "PharmacyPurchaseHeader" ph on ph."PharmacyPurchaseHeaderId"= prh."PharmacyPurchaseHeaderId"
join "PharmacyWareHouse" PWH on PWH."PharmacyWareHouseId" = ph."PharmacyWareHouseId"
join "PharmacyPurchaseDetail" ppd on ppd."PharmacyPurchaseHeaderId" = ph."PharmacyPurchaseHeaderId"
join "PharmacyProduct" pp on pp."PharmacyProductId" = ppd."PharmacyProductId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyPurchaseReturnDetail" prd on prh."PharmacyPurchaseReturnHeaderId"= prd."PharmacyPurchaseReturnHeaderId"
and ppd."PharmacyProductId"=prd."PharmacyProductId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end and
case when "productName" is null then 1=1 else pp."ProductName" ilike '%' || "productName" ||'%' end
and case when "fromDate" is null then 1=1 else PH."BillDate"::date >= "fromDate" end
and case when "toDate" is null then 1=1 else PH."BillDate"::date <= "toDate" end and
case when "locationId" is null then 1=1 else PWH."LocationId" = "locationId"::int end
group by PP."ProductName",PP."GenericName",ci."Name",PPD."PurchaseRate",PrD."ReturnQuantity",PPD."Mrp",PrD."TaxAmount",PH."PharmacyPurchaseHeaderId" ,
PH."BillNumber",PH."BillType",prh."CreatedDate",A."FullName"
,R."RoleName" ,S."Name" , prd."NetAmount"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."BillDate" desc, PH."PharmacyPurchaseHeaderId";
END
$BODY$;
-----------
DROP FUNCTION public."udf_PatientMedicationReport"(integer, text, text, text);
DROP FUNCTION public."udf_PatientMedicationReport"(integer, text, text, text, text, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_PatientMedicationReport"(
"patientId" integer DEFAULT NULL::integer,
"uMRNo" text DEFAULT NULL::text,
"patientMobile" text DEFAULT NULL::text,
"billNumber" text DEFAULT NULL::text,
"paidVia" text DEFAULT NULL::text,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"locationId" text default null::text)
RETURNS TABLE("PatientName" text, "UMRNo" character varying, "PatientMobile" character varying, "BillNumber" character varying, "BillType" character varying, "SaleDate" timestamp without time zone, "OverallNetAmount" numeric, "ProductName" character varying, "GenericName" character varying, "CategoryName" character varying, "CompanyName" text, "BatchNumber" character varying, "PaidVia" text, "Quantity" integer, "NetAmount" numeric, "TotalAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select P."FullName" "PatientName",P."UMRNo",p."Mobile" "PatientMobile" ,Ph."BillNumber",PH."BillType",
PH."CreatedDate" "SaleDate",PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" "CategoryName ",c."Name" "CompanyName",PRS."BatchNumber", PH."PaidVia" ,sum(PS."Quantity")::int "Quantity",
PS."NetAmount" ,sum(PS."NetAmount") "TotalAmount"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Patient" P on P."PatientId"=ph."PatientId"
--where p."UMRNo" ='UMR21050206'
where case when "uMRNo" ='' then 1=1 when "uMRNo" is null then 1=1 else p."UMRNo" ilike '%'||"uMRNo"||'%' end and
--case when "patientName" ='' then 1=1 when "patientName" is null then 1=1 else P."FullName" ilike '%'||"patientName"||'%' end and
case when "patientId" is null then 1=1 else P."PatientId"="patientId" end and
case when "patientMobile" ='' then 1=1 when "patientMobile" is null then 1=1 else p."Mobile" ilike '%'||"patientMobile"||'%' end and
case when "billNumber" ='' then 1=1 when "billNumber" is null then 1=1 else Ph."BillNumber" ilike '%'||"billNumber"||'%' end
and case when "paidVia" ='' then 1=1 when "paidVia" is null then 1=1 else Ph."PaidVia" ilike '%'||"paidVia"||'%' end
and case when "fromDate" is null then 1=1 else "fromDate" <= PH."CreatedDate" and PH."CreatedDate" <= "toDate" end
and case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
GROUP BY GROUPING SETS(( P."FullName",P."UMRNo",p."Mobile" ,Ph."BillNumber",PH."CreatedDate",PH."BillType",
PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" ,c."Name" ,PRS."BatchNumber",PH."PaidVia" ,PS."Quantity",PS."NetAmount" ),
( P."FullName",Ph."BillNumber",PH."BillType"), ())
order by Ph."CreatedDate" desc
;
END
$BODY$;
--------
-- Not Completed yet
--DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, date, date, integer, integer);
-- DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, boolean, date, date, integer, integer);
-- DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, boolean, text, date, date, date, text, integer, integer);
-- DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer);
-- DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer);
-- DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, boolean, text, date, date, integer, integer);
-- DROP FUNCTION public."udf_fetch_Admission"(text, integer, integer, boolean, text, date, date, text, integer, integer);
alter table "PharmacyWareHouse" add "LocationId" int references "Location"("LocationId");
-- This is depends on select * from "Location" l
--update "PharmacyWareHouse" set "LocationId" = 2;
----------------------
Alter table "PharmacySaleHeader" add column "LocationId" int references "Location"("LocationId");
-- Should be updated based on below Select command.
--Select * from "Location"
--update "PharmacySaleHeader" set "LocationId" = 2;
Alter table "DemandBook" add column "LocationId" int references "Location"("LocationId");
--Select * from "Location";
--Update "DemandBook" set "LocationId" = 2;
Alter table "IndentHeader" add column "LocationId" int references "Location"("LocationId");
--Select * from "Location"
update "IndentHeader" set "LocationId" = 2;
\ No newline at end of file
--------------------------------------------
CREATE SEQUENCE public."LocationPackageMap_LocationPackageMapId_seq";
CREATE TABLE public."LocationPackageMap"
(
"LocationPackageMapId" integer NOT NULL DEFAULT nextval('"LocationPackageMap_LocationPackageMapId_seq"'::regclass),
"PackageId" integer NOT NULL,
"LocationId" integer NOT NULL,
CONSTRAINT "LocationPackageMap_pkey" PRIMARY KEY ("LocationPackageMapId"),
CONSTRAINT "FK_LocationPackageMap_PackageId" FOREIGN KEY ("PackageId")
REFERENCES public."Package" ("PackageId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "FK_LocationPackageMap_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
);
-----------------------------------
CREATE SEQUENCE public."LocationMealTypesMap_LocationMealTypesMapId_seq";
CREATE TABLE public."LocationMealTypesMap"
(
"LocationMealTypesMapId" integer NOT NULL DEFAULT nextval('"LocationMealTypesMap_LocationMealTypesMapId_seq"'::regclass),
"MealTypeId" integer NOT NULL,
"LocationId" integer NOT NULL,
CONSTRAINT "LocationMealTypesMap_pkey" PRIMARY KEY ("LocationMealTypesMapId"),
CONSTRAINT "FK_LocationMealTypesMap_MealTypeId" FOREIGN KEY ("MealTypeId")
REFERENCES public."MealTypes" ("MealTypeId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "FK_LocationMealTypesMap_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
);
--------------------------------------------
CREATE SEQUENCE public."LocationFloorMap_LocationFloorMapId_seq";
CREATE TABLE public."LocationFloorMap"
(
"LocationFloorMapId" integer NOT NULL DEFAULT nextval('"LocationFloorMap_LocationFloorMapId_seq"'::regclass),
"FloorId" integer NOT NULL,
"LocationId" integer NOT NULL,
CONSTRAINT "LocationFloorMap_pkey" PRIMARY KEY ("LocationFloorMapId"),
CONSTRAINT "FK_LocationFloorMap_FloorId" FOREIGN KEY ("FloorId")
REFERENCES public."Floor" ("FloorId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "FK_LocationFloorMap_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
);
------------------------------------------
ALTER TABLE "Specialization" ADD PRIMARY KEY ("SpecializationId");
CREATE TABLE public."LocationSpecializationMap"
(
"LocationSpecializationMapId" bigserial,
"SpecializationId" bigint NOT NULL references "Specialization"("SpecializationId"),
"LocationId" bigint NOT NULL,
CONSTRAINT "PK_LocationSpecializationMap_LocationSpecializationMapId" PRIMARY KEY ("LocationSpecializationMapId"),
CONSTRAINT "FK_LocationSpecializationMap_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
ALTER TABLE "DiscountModule" ADD COLUMN "Active" BOOLEAN NOT NULL DEFAULT true;
ALTER TABLE "ChargeTypes" ADD COLUMN "LocationId" integer;
\ No newline at end of file
alter table "AppointmentLog" add column "LocationId" int references "Location"("LocationId");
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_fetch_Beds_ListView"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer, integer, integer, integer);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- FUNCTION: public.udf_fetch_Beds_ListView(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer, integer, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_fetch_Beds_ListView"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer, integer, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_fetch_Beds_ListView"(
"admissionNo" text DEFAULT NULL::text,
"providerId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"isDischarged" boolean DEFAULT NULL::boolean,
"patientMobileNo" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"dischargeDate" date DEFAULT NULL::date,
"uMRNo" text DEFAULT NULL::text,
active boolean DEFAULT NULL::boolean,
locationid integer DEFAULT NULL::integer,
floorid integer DEFAULT NULL::integer,
wardid integer DEFAULT NULL::integer,
bedstatusid integer DEFAULT NULL::integer,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("AdmissionId" integer, "AdmissionNo" text, "PatientPriorityId" integer, "IsConvertedFromOPtoIp" boolean, "AdmissionDate" timestamp without time zone, "AdmissionTime" time without time zone, "PatientName" text, "UMRNo" character varying, "PatientAge" smallint, "PatientGender" character, "patientMobile" character varying, "ProviderAge" smallint, "ProviderGender" character, "ProviderName" text, "DepartmentName" text, "WardName" character varying, "RoomName" character varying, "BedNumber" character varying, "AttendantName" character varying, "AttendantRelationWithPatient" character varying, "AttendantContactNo" character varying, "IsDischarged" boolean, "DischargeDate" date, "DischargeTime" time without time zone, "DischargeStatus" character varying, "IsMaternity" boolean, "EncounterId" integer, "SurgeryName" character varying, "ProviderThumbnailUrl" text, "PatientThumbnailUrl" text, "BedId" integer, "RoomId" integer, "WardId" integer, "DepartmentId" integer, "PatientId" integer, "ProviderId" integer, "SurgeryTypeId" integer, "PatientType" character, "AdmissionNotes" text, "PaidAmount" numeric, "FinalAmount" numeric, "PaymentStatus" text, "IsFinalBill" boolean, "TotalItems" bigint, "Active" boolean, "ExpectedDischargeDate" timestamp without time zone, "DischargedBy" integer, "DischargedByRole" text, "DischargedByName" text, "BedStatusName" character varying, "BedStatusID" integer, "FloorId" integer, "FloorName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
With TotalItems as (
select count(distinct B."BedId")::bigint "TotalItems"
from "Bed" B
join "Room" R on B."RoomId"=R."RoomId"
join "Ward" W on w."WardId"=R."WardId"
left join "BedStatus" BS ON BS."BedStatusId" = B."BedStatusId"
LEFT JOIN "Admission" A on B."BedId"=A."BedId" and A."Active"=true and A."IsDischarged"=false
LEFT join "Patient" Pa on A."PatientId"=Pa."PatientId"
LEFT join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
LEFT join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
)
select A."AdmissionId",A."AdmissionNo",A."PatientPriorityId", A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName" "PatientName",Pa."UMRNo",Pa."Age" "PatientAge",Pa."Gender" as "PatientGender",pa."Mobile" "patientMobile",Pr."Age" "ProviderAge",Pr."Gender" as "ProviderGender",
Pr."FullName"::text "ProviderName",D."DepartmentName"::text "DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName" "AttendantName",A."AttendantRelationWithPatient" "AttendantRelationWithPatient",A."AttendantContactNo" "AttendantContactNumber",
case when ds."DischargeId" is not null then true else false end as "IsDischarged",ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus"
,A."IsMaternity",A."EncounterId",st."SurgeryName",
(CASE WHEN pr."ThumbnailUrl" IS NOT NULL THEN CONCAT(pr."Guid", '/', pr."ThumbnailUrl") ELSE NULL END) AS "ProviderThumbnailUrl",
(CASE WHEN pa."ThumbnailUrl" IS NOT NULL THEN CONCAT(pa."Guid", '/', pa."ThumbnailUrl") ELSE NULL END) AS "PatientThumbnailUrl"
,B."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,
sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0) "PaidAmount"
,
FB."FinalAmount" ,
case when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))=0 then 'Payment Cleared'
when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))>0 then 'Payment Due'
when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))<0 then 'Pending Refund' end "PaymentStatus",
case when FB."FinalBillId" is null then false else true end "IsFinalBill",(select T."TotalItems" from TotalItems T) "TotalItems",
A."Active",
A."ExpectedDischargeDate",
A."DischargedBy" ,
case when RL."RoleId" = '3' then DP."DepartmentName"::TEXT else RL."RoleName"::TEXT end as "DischargedByRole",
case when RL."RoleId" = '3' then PRO."FullName" else AC."FullName" end as "DischargedByName",
BS."BedStatusName",BS."BedStatusId",F."FloorId",F."FloorName"
from "Bed" B
join "Room" R on B."RoomId"=R."RoomId"
join "Ward" W on w."WardId"=R."WardId"
JOIN "Floor" F on F."FloorId"=W."FloorId"
left join "BedStatus" BS ON BS."BedStatusId" = B."BedStatusId"
LEFT JOIN "Admission" A on B."BedId"=A."BedId" and A."Active"=true and A."IsDischarged"=false
LEFT join "Patient" Pa on A."PatientId"=Pa."PatientId"
LEFT join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
LEFT join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
left join "Account" AC on AC."AccountId"=A."DischargedBy"
left join "Role" RL on RL."RoleId"= AC."RoleId"
left join "Provider" PRO on PRO."ProviderId"=AC."ReferenceId"
left join "Department" DP on DP."DepartmentId"=PRO."DepartmentId"
where f."LocationId" = locationid
and case when coalesce(floorid,0) <> 0 then F."FloorId" = floorid else 1 = 1 end
and case when coalesce(wardid,0) <> 0 then w."WardId" = wardid else 1 = 1 end
and case when coalesce(bedstatusid,0) <> 0 then B."BedStatusId" = bedstatusid else 1 = 1 end
group by A."AdmissionId",A."AdmissionNo",A."PatientPriorityId",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName",Pa."UMRNo",Pa."Age" ,Pa."Gender" ,Pr."Age" ,Pr."Gender" ,
Pr."FullName",D."DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName",A."AttendantRelationWithPatient",A."AttendantContactNo" , ds."DischargeId",F."FloorId",F."FloorName"
,ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus",pa."Mobile"
,A."IsMaternity",A."EncounterId",st."SurgeryName",pr."ThumbnailUrl", pr."Guid",pr."ThumbnailUrl" ,pa."Guid", pa."ThumbnailUrl",
B."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,FB."FinalAmount" ,FB."FinalBillId",
RL."RoleId",DP."DepartmentName",PRO."FullName",AC."FullName",BS."BedStatusName",BS."BedStatusId"
order by B."BedNumber" desc;
--limit "pageSize" offset ("pageSize"*"pageIndex");
END
$BODY$;
ALTER FUNCTION public."udf_fetch_Beds_ListView"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer, integer, integer, integer)
OWNER TO postgres;
alter table "ModulesMaster" add column "PackageType" varchar(20),add column "IsChargeCategoryApplicable" bool default false;
\ 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
create table "DepartmentConsumption"("DepartmentConsumptionId" serial primary key,"PharmacyDepartmentalStockId" int references "PharmacyDepartmentalStock"("PharmacyDepartmentalStockId"),
"QuantityConsumed" int not null,"ConsumedBy" int references "Account"("AccountId"),"CreatedDate" timestamp without time zone,
"ReasonForConsumption" varchar(300));
alter table "DepartmentConsumption" add column "CreatedBy" int references "Account"("AccountId");
\ No newline at end of file
-- SEQUENCE: public.AppointmentStatus_AppointmentStatusId_seq
-- DROP SEQUENCE IF EXISTS public."AppointmentStatus_AppointmentStatusId_seq";
CREATE SEQUENCE IF NOT EXISTS public."AppointmentStatus_AppointmentStatusId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."AppointmentStatus_AppointmentStatusId_seq"
OWNER TO postgres;
---------------------------------------
-- Table: public.AppointmentStatus
-- DROP TABLE IF EXISTS public."AppointmentStatus";
CREATE TABLE IF NOT EXISTS public."AppointmentStatus"
(
"AppointmentStatusId" integer NOT NULL DEFAULT nextval('"AppointmentStatus_AppointmentStatusId_seq"'::regclass),
"Name" character varying(14) 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,
"LocationId" integer,
CONSTRAINT "AppointmentStatus_pkey" PRIMARY KEY ("AppointmentStatusId"),
CONSTRAINT "FK_AppointmentStatus_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "FK_AppointmentStatus_Modifiedby" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."AppointmentStatus"
OWNER to postgres;
COMMENT ON COLUMN public."AppointmentStatus"."AppointmentStatusId"
IS ' ';
\ No newline at end of file
-- SEQUENCE: public.ConsultationType_ConsultationTypeId_seq
-- DROP SEQUENCE IF EXISTS public."ConsultationType_ConsultationTypeId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ConsultationType_ConsultationTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ConsultationType_ConsultationTypeId_seq"
OWNER TO postgres;
----------------
-- Table: public.ConsultationType
-- DROP TABLE IF EXISTS public."ConsultationType";
CREATE TABLE IF NOT EXISTS public."ConsultationType"
(
"ConsultationTypeId" integer NOT NULL DEFAULT nextval('"ConsultationType_ConsultationTypeId_seq"'::regclass),
"Name" character varying(30) 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,
"LocationId" integer,
CONSTRAINT "ConsultationType_pkey" PRIMARY KEY ("ConsultationTypeId"),
CONSTRAINT "FK_ConsultationType_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "FK_ConsultationType_Modifiedby" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ConsultationType"
OWNER to postgres;
COMMENT ON COLUMN public."ConsultationType"."ConsultationTypeId"
IS ' ';
\ No newline at end of file
-- SEQUENCE: public.ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId_seq
-- DROP SEQUENCE IF EXISTS public."ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId_seq"
OWNER TO postgres;
------------------------
-- Table: public.ProviderAvailabilityChargeType
-- DROP TABLE IF EXISTS public."ProviderAvailabilityChargeType";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilityChargeType"
(
"ProviderAvailabilityChargeTypeId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId"'::regclass),
"ProviderAvailabilitySlotId" integer NOT NULL,
"ChargeTypesId" integer NOT NULL,
"Charge" integer,
"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 "ProviderAvailabilityChargeType_pkey" PRIMARY KEY ("ProviderAvailabilityChargeTypeId"),
CONSTRAINT "FK_ProviderAvailabilityChargeType_ProviderAvailabilitySlotId" FOREIGN KEY ("ProviderAvailabilitySlotId")
REFERENCES public."ProviderAvailabilitySlot" ("ProviderAvailabilitySlotId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "ProviderAvailabilityChargeType_ChargeTypesId_fkey" FOREIGN KEY ("ChargeTypesId")
REFERENCES public."ChargeTypes" ("ChargeTypesId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilityChargeType"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilityChargeType"."ProviderAvailabilityChargeTypeId"
IS ' ';
\ No newline at end of file
-- SEQUENCE: public.ProviderAvailabilitySlot_ProviderAvailabilitySlotId_seq
-- DROP SEQUENCE IF EXISTS public."ProviderAvailabilitySlot_ProviderAvailabilitySlotId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ProviderAvailabilitySlot_ProviderAvailabilitySlotId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ProviderAvailabilitySlot_ProviderAvailabilitySlotId_seq"
OWNER TO postgres;
----------------------------
-- Table: public.ProviderAvailabilitySlot
-- DROP TABLE IF EXISTS public."ProviderAvailabilitySlot";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilitySlot"
(
"ProviderAvailabilitySlotId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilitySlot_ProviderAvailabilitySlotId_seq"'::regclass),
"ProviderAvailabilityId" integer NOT NULL,
"SpecializationId" integer NOT NULL,
"AvailableDay" text COLLATE pg_catalog."default",
"StartTime" text COLLATE pg_catalog."default",
"EndTime" 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,
"FreeFollowUpDaysLimit" integer,
"FreeFollowUpDays" integer,
CONSTRAINT "ProviderAvailabilitySlot_pkey" PRIMARY KEY ("ProviderAvailabilitySlotId"),
CONSTRAINT "FK_ProviderAvailabilitySlot_ProviderAvailabilityId" FOREIGN KEY ("ProviderAvailabilityId")
REFERENCES public."ProviderAvailability" ("ProviderAvailabilityId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "ProviderAvailabilitySlot_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilitySlot"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilitySlot"."ProviderAvailabilitySlotId"
IS ' ';
\ No newline at end of file
-- SEQUENCE: public.ProviderAvailability_ProviderAvailabilityId_seq
-- DROP SEQUENCE IF EXISTS public."ProviderAvailability_ProviderAvailabilityId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ProviderAvailability_ProviderAvailabilityId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ProviderAvailability_ProviderAvailabilityId_seq"
OWNER TO postgres;
-------------------------------
-- Table: public.ProviderAvailability
-- DROP TABLE IF EXISTS public."ProviderAvailability";
CREATE TABLE IF NOT EXISTS public."ProviderAvailability"
(
"ProviderAvailabilityId" integer NOT NULL DEFAULT nextval('"ProviderAvailability_ProviderAvailabilityId_seq"'::regclass),
"ProviderId" integer NOT NULL,
"LocationId" integer NOT NULL,
"ConsultationTypeId" integer 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,
"StartDate" character varying COLLATE pg_catalog."default",
"EndDate" character varying COLLATE pg_catalog."default",
CONSTRAINT "ProviderAvailability_pkey" PRIMARY KEY ("ProviderAvailabilityId"),
CONSTRAINT "FK_ProviderAvailability_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "ProviderAvailability_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailability"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailability"."ProviderAvailabilityId"
IS ' ';
\ No newline at end of file
-- SEQUENCE: public.ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_seq
-- DROP SEQUENCE IF EXISTS public."ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_seq"
OWNER TO postgres;
-----------------
-- Table: public.ProviderAvailabilityVisitType
-- DROP TABLE IF EXISTS public."ProviderAvailabilityVisitType";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilityVisitType"
(
"ProviderAvailabilityVisitTypeId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_s"'::regclass),
"ProviderAvailabilityId" integer NOT NULL,
"VisitTypeId" integer NOT NULL,
"Duration" integer,
"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 "ProviderAvailabilityVisitType_pkey" PRIMARY KEY ("ProviderAvailabilityVisitTypeId"),
CONSTRAINT "FK_ProviderAvailabilityVisitType_ProviderAvailabilityId" FOREIGN KEY ("ProviderAvailabilityId")
REFERENCES public."ProviderAvailability" ("ProviderAvailabilityId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "ProviderAvailabilityVisitType_VisitTypeId_fkey" FOREIGN KEY ("VisitTypeId")
REFERENCES public."VisitType" ("VisitTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilityVisitType"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilityVisitType"."ProviderAvailabilityVisitTypeId"
IS ' ';
\ No newline at end of file
Create table "PatientLabHeader"(
"PatientLabHeaderId" serial Primary Key,
"AppointmentId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"Active" boolean DEFAULT true,
CONSTRAINT "PatientLabHeader_AppointmentId_fkey" FOREIGN KEY ("AppointmentId")
REFERENCES public."Appointment" ("AppointmentId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PatientLabHeader_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PatientLabHeader_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
Create table "PatientLabDetail"(
"PatientLabDetailId" serial Primary Key,
"PatientLabHeaderId" int references "PatientLabHeader"("PatientLabHeaderId"),
"LabHeaderId" int references "LabHeader"("LabHeaderId"),
"LabPackageId" int references "LabPackage"("LabPackageId")
);
-------------------
Create table "WebNotificationType"("WebNotificationTypeId" serial Primary Key, "ModuleType" text);
Alter table "WebNotification" add column "WebNotificationTypeId" int references "WebNotificationType"("WebNotificationTypeId");
insert into "WebNotificationType" ("ModuleType")values('Pharmacy'),('Labratory');
-- Select * from "WebNotificationType"
update "WebNotification" set "WebNotificationTypeId" = 1;
--------------------------------
\ No newline at end of file
insert into "ReceiptAreaTypeId" ("ReceiptAreaTypeId","Name")
values(8,'Labs'),(9,'LabsCancel');
\ No newline at end of file
INSERT INTO "LabBookingStatus" ("Status", "Active")
VALUES ('DoctorAssigned', true);
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
insert into "LabBookingStatus"("Status","Active")
values('DoctorVerified',true);
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
INSERT INTO "LabBookingStatus" ("Status", "Active")
VALUES ('Verified', true);
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
create sequence "LabReportVerification_LabReportVerificationId_seq";
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Table: public.LabReportVerification
-- DROP TABLE IF EXISTS public."LabReportVerification";
CREATE TABLE IF NOT EXISTS public."LabReportVerification"
(
"LabReportVerificationId" integer NOT NULL DEFAULT nextval('"LabReportVerification_LabReportVerificationId_seq"'::regclass),
"NewLabBookingDetailId" integer NOT NULL,
"ApprovedBy" integer NOT NULL,
"ApprovedDate" timestamp without time zone,
"Approved" boolean DEFAULT false,
CONSTRAINT "LabReportVerification_pkey" PRIMARY KEY ("LabReportVerificationId"),
CONSTRAINT "LabReportVerification_NewLabBookingDetailId_fkey" FOREIGN KEY ("NewLabBookingDetailId")
REFERENCES public."NewLabBookingDetail" ("NewLabBookingDetailId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "LabReportVerification_ApprovedBy_fkey" FOREIGN KEY ("ApprovedBy")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."LabReportVerification"
OWNER to postgres;
\ No newline at end of file
alter table "InventoryProduct" drop column if exists "SupplierId",drop column if exists "MaxQuantity",
drop column if exists "MinQuantity", drop column if exists "ReorderLevelQuantity",drop column if exists "RackId",
drop column if exists "SaleUnit",drop column if exists "SaleUnitQuantity";
CREATE TABLE "InventoryDepartment" (
"InventoryDepartmentId" serial primary key,
"Name" varchar(300) NULL,
"Active" bool NULL DEFAULT true,
"CreatedBy" int4 NULL,
"CreatedDate" timestamp NULL,
"ModifiedBy" int4 NULL,
"ModifiedDate" timestamp NULL,
"LocationId" int4 NULL,
CONSTRAINT "InventoryDepartment_CreatedBy_fkey" FOREIGN KEY ("CreatedBy") REFERENCES "Account"("AccountId"),
CONSTRAINT "InventoryDepartment_LocationId_fkey" FOREIGN KEY ("LocationId") REFERENCES "Location"("LocationId"),
CONSTRAINT "InventoryDepartment_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy") REFERENCES "Account"("AccountId")
);
CREATE TABLE "InventoryDepartmentUser" (
"InventoryDepartmentUserId" serial4 NOT NULL,
"InventoryDepartmentId" int4 NULL,
"AccountId" int4 NULL,
CONSTRAINT "InventoryDepartmentUser_pkey" PRIMARY KEY ("InventoryDepartmentUserId"),
CONSTRAINT "InventoryDepartmentUser_InventoryDepartmentId_fkey" FOREIGN KEY ("InventoryDepartmentId") REFERENCES "InventoryDepartment"("InventoryDepartmentId")
);
\ No newline at end of file
CREATE TABLE "InventoryIssuedStockHeader" (
"InventoryIssuedStockHeaderId" bigserial primary key,
"IssuedDate" timestamp NULL,
"IssuedBy" int4 NULL,
"HandOverTo" int4 NULL,
"Comment" text NULL,
"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId"),
"ReceivedBy" int4 NULL,
"ReceivedDate" timestamp NULL,
"IssueHeaderId" int4 null references "IssueHeader"("IssueHeaderId"),
"IssueNumber" text NULL
);
CREATE TABLE "InventoryIssuedStockDetail" (
"InventoryIssuedStockDetailId" bigserial primary key,
"InventoryIssuedStockHeaderId" int8 references "InventoryIssuedStockHeader"("InventoryIssuedStockHeaderId"),
"InventoryProductId" int4 references "InventoryProduct"("InventoryProductId"),
"TaxId" int4 NULL,
"QuantityIn" int4 NULL,
"BatchNumber" varchar(50) NULL,
"ExpiryDate" date NULL,
"PurchaseRate" numeric(8, 2) NULL,
"InventoryStockId" int4 null references "InventoryStock"("InventoryStockId")
);
CREATE TABLE "InventoryProductRack" (
"InventoryProductRackId" serial primary key,
"RackName" text NULL,
"CreatedBy" int4 NULL,
"CreatedDate" timestamp NULL,
"ModifiedBy" int4 NULL,
"ModifiedDate" timestamp NULL,
"InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId"),
"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId")
);
CREATE TABLE "InventoryProductDetail" (
"InventoryProductDetailId" serial primary key,
"InventoryProductRackId" int references "InventoryProductRack"("InventoryProductRackId"),
"ROQ" int4 NULL,
"ROL" int4 NULL,
"InventoryProductId" int4 references "InventoryProduct"("InventoryProductId"),
"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId"),
"InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId"),
"CreatedBy" int4 NULL,
"CreatedDate" timestamp NULL,
"ModifiedBy" int4 NULL,
"ModifiedDate" timestamp null
);
CREATE TABLE "InventoryDepartmentConsumption" (
"InventoryDepartmentConsumptionId" serial primary key,
"InventoryDepartmentalStockId" int references "InventoryDepartmentalStock"("InventoryDepartmentalStockId"),
"QuantityConsumed" int4 NOT NULL,
"ConsumedBy" int4 NULL,
"CreatedDate" timestamp NULL,
"ReasonForConsumption" varchar(300) NULL,
"CreatedBy" int4 NULL,
"QuantityBeforeConsumption" int
);
create table if not exists "InventoryWareHouse"
("InventoryWareHouseId" serial primary key,"Name" text, "Active" boolean default true,"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
alter table "InventoryWareHouse" add column "LocationId" int references "Location"("LocationId");
create table if not exists "InventoryWareHouseUser"(
"InventoryWareHouseUserId" serial primary key, "InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId" ),
"AccountId" int references "Account"("AccountId"));
insert into "InventoryLogType" ("InventoryLogTypeId","LogTypeName", "Active") values (15,'WareHouse',true);
alter table "InventoryPurchaseDetail" drop column "SerialNo";
alter table "InventoryPurchaseHeader" add column "InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId");
-- Not sure
alter table "InventoryPurchaseHeader" add column "LocationId" int references "Location"("LocationId");
----
alter table "InventoryStock" add column "InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId");
-- --> Dont forget to add the update querry for existing data
CREATE TABLE "InventoryDepartmentalStock" (
"InventoryDepartmentalStockId" serial primary Key,
"InventoryProductId" int references "InventoryProduct"("InventoryProductId"),
"TaxId" int4 REFERENCES "LookupValue"("LookupValueId"),
"QuantityIn" int4 NULL,
"QuantityOut" int4 NULL,
"BatchNumber" varchar(50) NULL,
"ExpiryDate" date NULL,
"PurchaseRate" numeric(8, 2) NULL,
"InventoryStockId" int references "InventoryStock"("InventoryStockId"),
"CreatedBy" int4 NULL,
"CreatedDate" timestamp NULL,
"ModifiedBy" int4 NULL,
"ModifiedDate" timestamp null,
"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId")
);
alter table "IndentHeader" add column "InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId");
alter table "IssueHeader" add column "InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId");
-- FUNCTION: public.udf_DailySalesReportByMedication(text, text, text, text, text, integer, date, date, integer)
--
DROP FUNCTION public."udf_DailySalesReportByMedication"(text, text, text, text, text, text, date, date, integer);
CREATE OR REPLACE FUNCTION public."udf_DailySalesReportByMedication"(
"productName" text DEFAULT NULL::text,
"genericName" text DEFAULT NULL::text,
"categoryName" text DEFAULT NULL::text,
"companyName" text DEFAULT NULL::text,
"supplierName" text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("PharmacyProductId" integer, "ProductName" character varying, "BatchNumber" character varying, "GenericName" character varying, "CategoryName" character varying, "CompanyName" text, "SupplierName" text, "SaleQuantity" bigint, "Mrp" numeric, "Discount" numeric, "TotalAmount" numeric, "PaidVia" character varying, "PaymentNumber" character varying, "SaleDate" timestamp without time zone, "PurchaseValue" numeric, "PurchaseUnitQty" integer, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select A."PharmacyProductId",A."ProductName",A."BatchNumber",A."GenericName",A."CategoryName ",A."CompanyName"
,A."SupplierName"
,sum(A."Quantity") "SaleQuantity",A."Mrp",A."OverallDiscount" "Discount",sum(A."NetAmount") "TotalAmount"
,A."PaidVia",A."PaymentNumber",A."SaleDate" , TRUNC((A."PPD_NetAmount"/A."PPD_Quantity"),2) as "PurchaseValue"
,A."PurchaseUnitQty",A."LocationName"
from (
select PS."PharmacyProductId",PP."ProductName",PRS."BatchNumber",pp."GenericName",ci."Name" "CategoryName ",c."Name" "CompanyName",s."Name" "SupplierName"
,PH."SaleDate",PS."Quantity",PRS."Mrp",Ps."Discount" "OverallDiscount",PS."NetAmount" , PT."PayTypeName" as "PaidVia", PH."PaymentNumber",
ppd."NetAmount" as "PPD_NetAmount",ppd."Quantity" as "PPD_Quantity",L."Name" as "LocationName"
,pp."PurchaseUnitQty"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyPurchaseDetail" Ppd on ppd."PharmacyStockId"=prs."PharmacyStockId" and ppd."PharmacyProductId"=PRS."PharmacyProductId"
join "PharmacyPurchaseHeader" pph on pph."PharmacyPurchaseHeaderId"=Ppd."PharmacyPurchaseHeaderId"
join "Supplier" s on s."SupplierId"=pph."SupplierId"
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "productName" ='' then 1=1 when "productName" is null then 1=1 else PP."ProductName" ilike '%'||"productName"||'%' end and
case when "genericName" ='' then 1=1 when "genericName" is null then 1=1 else pp."GenericName" ilike '%'||"genericName"||'%' end and
case when "categoryName" ='' then 1=1 when "categoryName" is null then 1=1 else ci."Name" ilike '%'||"categoryName"||'%' end and
case when "companyName" ='' then 1=1 when "companyName" is null then 1=1 else c."Name" ilike '%'||"companyName"||'%' end and
case when "supplierName" ='' then 1=1 when "supplierName" is null then 1=1 else s."Name" ilike '%'||"supplierName"||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" ::date <=PH."SaleDate"::date and PH."SaleDate"::date <="toDate" ::date end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PS."PharmacyProductId",PP."ProductName",PRS."BatchNumber",PH."SaleDate"
,pp."GenericName",ci."Name",c."Name" ,s."Name" ,PS."Quantity",PS."NetAmount",PRS."Mrp",Ps."Discount" ,PT."PayTypeName" , PH."PaymentNumber",
ppd."NetAmount", ppd."Quantity",pp."PurchaseUnitQty",L."Name") A
group by A."PharmacyProductId",A."ProductName",A."BatchNumber",A."GenericName",A."CategoryName ",
A."CompanyName",A."SupplierName",A."Mrp",A."OverallDiscount",A."PaidVia",A."PaymentNumber",A."SaleDate", (A."PPD_NetAmount"/A."PPD_Quantity") , A."PurchaseUnitQty",
A."LocationName"
order by A."ProductName"
;
END
$BODY$;
--ALTER FUNCTION public."udf_DailySalesReportByMedication"(text, text, text, text, text, integer, date, date, integer)
-- OWNER TO postgres;
-- FUNCTION: public.udf_PatientMedicationReport(integer, text, text, text, text, timestamp without time zone, timestamp without time zone, text)
--
DROP FUNCTION public."udf_PatientMedicationReport"(integer, text, text, text, text, timestamp without time zone, timestamp without time zone, text);
CREATE OR REPLACE FUNCTION public."udf_PatientMedicationReport"(
"patientId" integer DEFAULT NULL::integer,
"uMRNo" text DEFAULT NULL::text,
"patientMobile" text DEFAULT NULL::text,
"billNumber" text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PatientName" text, "UMRNo" character varying, "PatientMobile" character varying,
"BillNumber" character varying, "BillType" character varying, "SaleDate" timestamp without time zone,
"OverallNetAmount" numeric, "ProductName" character varying, "GenericName" character varying,
"CategoryName" character varying, "CompanyName" text, "BatchNumber" character varying,
"PaidVia" character varying, "PaymentNumber" character varying, "Quantity" integer, "NetAmount" numeric, "TotalAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select P."FullName" "PatientName",P."UMRNo",p."Mobile" "PatientMobile" ,Ph."BillNumber",PH."BillType",
PH."CreatedDate" "SaleDate",PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" "CategoryName ",c."Name" "CompanyName",PRS."BatchNumber", PT."PayTypeName" as "PaidVia",PH."PaymentNumber" ,sum(PS."Quantity")::int "Quantity",
PS."NetAmount" ,sum(PS."NetAmount") "TotalAmount"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Patient" P on P."PatientId"=ph."PatientId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
--where p."UMRNo" ='UMR21050206'
where case when "uMRNo" ='' then 1=1 when "uMRNo" is null then 1=1 else p."UMRNo" ilike '%'||"uMRNo"||'%' end and
--case when "patientName" ='' then 1=1 when "patientName" is null then 1=1 else P."FullName" ilike '%'||"patientName"||'%' end and
case when "patientId" is null then 1=1 else P."PatientId"="patientId" end and
case when "patientMobile" ='' then 1=1 when "patientMobile" is null then 1=1 else p."Mobile" ilike '%'||"patientMobile"||'%' end and
case when "billNumber" ='' then 1=1 when "billNumber" is null then 1=1 else Ph."BillNumber" ilike '%'||"billNumber"||'%' end
and case when "payTypeId" is null then 1=1 else PT."PayTypeId" ="payTypeId" end
and case when "fromDate" is null then 1=1 else "fromDate" <= PH."CreatedDate" and PH."CreatedDate" <= "toDate" end
and case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
GROUP BY GROUPING SETS(( P."FullName",P."UMRNo",p."Mobile" ,Ph."BillNumber",PH."CreatedDate",PH."BillType",
PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" ,c."Name" ,PRS."BatchNumber",PT."PayTypeName", PH."PaymentNumber" ,PS."Quantity",PS."NetAmount" ),
( P."FullName",Ph."BillNumber",PH."BillType"), ())
order by Ph."CreatedDate" desc
;
END
$BODY$;
--ALTER FUNCTION public."udf_PatientMedicationReport"(integer, text, text, text, text, timestamp without time zone, timestamp without time zone, text)
-- OWNER TO postgres;
--select * from "PharmacySaleHeader"
\ No newline at end of file
-- FUNCTION: public.udf_PharmacyBills_FinalReport(text, integer, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text, boolean)
--
DROP FUNCTION public."udf_PharmacyBills_FinalReport"(text, integer, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text, boolean);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_FinalReport"(
"billNumber" text DEFAULT NULL::text,
"accountId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text,
"pharmacyBillType" boolean DEFAULT NULL::boolean)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying,
"PaidVia" character varying, "PaymentNumber" character varying, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "ProviderName" character varying, "CreatedByName" text, "RoleName" character varying, "TotalAmount" numeric, "SaleReturnHeaderId" integer, "OverallTaxes" numeric, "RetailName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",PH."PaymentNumber",PH."SaleDate" "SaleDate",PH."PatientName",
PH."Mobile" ,Ph."UMRNo",PH."ProviderName",ph."CreatedByName",
ph."Role", PH."OverallNetAmount",PH."SaleReturnHeaderId" ,PH."OverallTaxes",PH."RetailName"
from
(
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",PH."CreatedDate" "SaleDate",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",PH."ProviderName",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."OverallNetAmount",true "PharmacyBillType",null "SaleReturnHeaderId",PH."OverallTaxes",
RP."RetailName"
from "PharmacySaleHeader" PH
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "accountId" is null then 1=1 else PH."CreatedBy"="accountId" end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" = "providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName", PH."PaymentNumber",PH."SaleDate", PH."OverallNetAmount",
PH."PatientName",PH."ProviderName",Pa."UMRNo",A."FullName"
,R."RoleName",RP."RetailName"
union
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",srh."ReturnDate" "SaleDate",PH."PatientName",
Ph."Mobile" ,Pa."UMRNo",PH."ProviderName",A."FullName"
"CreatedByName",R."RoleName" "Role", -srh."OverallNetAmount" "TotalAmount",false "PharmacyBillType"
,srh."SaleReturnHeaderId",srh."OverallTaxes",
RP."RetailName"
from "SaleReturnHeader" srh
Join "PharmacySaleHeader" ph on ph."PharmacySaleHeaderId"= srh."PharmacySaleHeaderId"
join "Account" A on A."AccountId"=srh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "accountId" is null then 1=1 else srh."CreatedBy"="accountId" end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" = "providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else srh."ReturnDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else srh."ReturnDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else ph."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName", PH."PaymentNumber",srh."ReturnDate", srh."OverallNetAmount",
PH."PatientName",Pa."Mobile",Pa."UMRNo",PH."ProviderName",A."FullName"
,R."RoleName",srh."SaleReturnHeaderId", RP."RetailName"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."SaleDate" desc, PH."PharmacySaleHeaderId";
END
$BODY$;
--ALTER FUNCTION public."udf_PharmacyBills_FinalReport"(text, integer, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text, boolean)
-- OWNER TO postgres;
-- FUNCTION: public.udf_PharmacyBills_Report(text, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text)
--
DROP FUNCTION public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_Report"(
"billNumber" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying,
"SaleDate" timestamp without time zone, "PatientName" character varying,
"PatientMobile" character varying, "UMRNo" character varying, "PaidVia" character varying, "PaymentNumber" character varying,
"CreatedByName" text, "RoleName" character varying, "ProviderName" character varying,
"TotalAmount" numeric, "RetailName" text, "OverallTaxes" numeric,
"LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."CreatedDate" "SaleDate",PH."PatientName",PH."Mobile"
,Pa."UMRNo",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."ProviderName", PH."OverallNetAmount" ,RP."RetailName",PH."OverallTaxes",L."Name" as "LocationName"
from "PharmacySaleHeader" PH
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
--join "Provider" pr on pr."ProviderId"::text=PH."ProviderId"::text
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" ="providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."SaleDate", PH."OverallNetAmount",PH."PatientName",PH."Mobile",Pa."UMRNo",PT."PayTypeName", PH."PaymentNumber", A."FullName"
,R."RoleName" ,PH."ProviderName",RP."RetailName",PH."OverallTaxes",L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
--ALTER FUNCTION public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, character varying, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text)
-- OWNER TO postgres;
-- FUNCTION: public.udf_PharmacySales_Report(timestamp without time zone, timestamp without time zone, integer, character varying, text)
--
DROP FUNCTION public."udf_PharmacySales_Report"(timestamp without time zone, timestamp without time zone, integer, character varying, text);
CREATE OR REPLACE FUNCTION public."udf_PharmacySales_Report"(
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("SaleDate" timestamp without time zone, "TotalAmount" numeric,
"TotalTaxes" numeric, "TotalDiscount" numeric, "TotalNetAmount" numeric,
"PaidVia" character varying,"PaymentNumber" character varying, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."SaleDate" , sum(PH."Total") "Total", sum(PH."OverallTaxes") "OverallTaxes",
sum(PH."OverallDiscount") "OverallDiscount",
sum(PH."OverallNetAmount") "OverallNetAmount", PT."PayTypeName" as "PaidVia",PH."PaymentNumber",
L."Name" as "LocationName"
from "PharmacySaleHeader" PH
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end
and case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end
and case when "createdBy" is null then 1=1 else PH."CreatedBy"="createdBy" end
and case when "payTypeId" is null then 1=1 else PT."PayTypeId" ="payTypeId" end
and case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."SaleDate",PT."PayTypeName",PH."PaymentNumber" ,L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
--ALTER FUNCTION public."udf_PharmacySales_Report"(timestamp without time zone, timestamp without time zone, integer, character varying, text)
-- OWNER TO postgres;
-----------------------PharmacySaleHeader--------------------
--------------------------------------------------------------------
alter table "PharmacySaleHeader" drop column if exists "PayTypeId";
alter table "PharmacySaleHeader"
add column if not exists "PayTypeId" integer references "PayType"("PayTypeId");
---------------------------
alter table "PharmacySaleHeader" drop column if exists "PaymentNumber";
alter table "PharmacySaleHeader"
add column if not exists "PaymentNumber" character varying(50)
--------------------
update "PharmacySaleHeader" set "PaidVia" = null where "PaidVia"= ''
-----------------------------------------------------
with T as(
select PSH."PharmacySaleHeaderId",PT."PayTypeId" from "PharmacySaleHeader" PSH
join "PayType" PT on lower(PSH."PaidVia") = lower(PT."PayTypeValue")
)
update "PharmacySaleHeader" P set "PayTypeId" = T."PayTypeId" from T where P."PharmacySaleHeaderId" = T."PharmacySaleHeaderId";
--------------------------------------------------------------------------
--------------------------------------------------------
-----------------------------LAbBookingHeader----------------------------------
---------------------------------------------
alter table "LabBookingHeader" drop column if exists "PayTypeId";
alter table "LabBookingHeader"
add column if not exists "PayTypeId" integer references "PayType"("PayTypeId");
---------------------------
alter table "LabBookingHeader" drop column if exists "PaymentNumber";
alter table "LabBookingHeader"
add column if not exists "PaymentNumber" character varying(50)
-------------------------------------------------------
with T as(
select LBH."LabBookingHeaderId",PT."PayTypeId" from "LabBookingHeader" LBH
join "PayType" PT on lower(LBH."PaidVia") = lower(PT."PayTypeValue")
)
update "LabBookingHeader" L set "PayTypeId" = T."PayTypeId" from T where L."LabBookingHeaderId" = T."LabBookingHeaderId";
-------------------------
alter table "PackageModule"
add column "Complimentary" numeric(8,2),
add column "Exclusions" character varying(1000) ;
------------------------------------------------------------------------------------------------------------------------------
create sequence "DoctorSpecializationChargeModuleCategory_DoctorSpecializationChargeModuleCategoryId_seq"
---------------------------------------------------------------------------------------------------------------------------
-- Table: public.DoctorSpecializationChargeModuleCategory
-- DROP TABLE IF EXISTS public."DoctorSpecializationChargeModuleCategory";
CREATE TABLE IF NOT EXISTS public."DoctorSpecializationChargeModuleCategory"
(
"DoctorSpecializationChargeModuleCategoryId" integer NOT NULL DEFAULT nextval('"DoctorSpecializationChargeModuleCategory_DoctorSpecializationChargeModuleCategoryId_seq"'::regclass),
"Active" boolean DEFAULT true,
"ChargeTypesId" integer,
"ModulesMasterId" integer,
"ChargeModuleTemplateId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_pkey" PRIMARY KEY ("DoctorSpecializationChargeModuleCategoryId"),
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ChargeTypesId_fkey" FOREIGN KEY ("ChargeTypesId")
REFERENCES public."ChargeTypes" ("ChargeTypesId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ChargeModuleTemplateId_fkey" FOREIGN KEY ("ChargeModuleTemplateId")
REFERENCES public."ChargeModuleTemplate" ("ChargeModuleTemplateId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."DoctorSpecializationChargeModuleCategory"
OWNER to postgres;
-----------------------------------------------------------------------------------------------------------------------------------------------------
create sequence "DoctorSpecializationChargeModuleDetails_DoctorSpecializationChargeModuleDetailsId_seq"
-----------------------------------------------------------------------------------------------------------------------------------------------------
-- Table: public.DoctorSpecializationChargeModuleDetails
-- DROP TABLE IF EXISTS public."DoctorSpecializationChargeModuleDetails";
CREATE TABLE IF NOT EXISTS public."DoctorSpecializationChargeModuleDetails"
(
"DoctorSpecializationChargeModuleDetailsId" bigint NOT NULL DEFAULT nextval('"DoctorSpecializationChargeModuleDetails_DoctorSpecializationChargeModuleDetailsId_seq"'::regclass),
"SpecializationId" integer NOT NULL,
"ConsultationTypeId" integer NOT NULL,
"ProviderId" integer,
"DoctorSpecializationChargeModuleCategoryId" integer,
"Amount" numeric(10,2),
"LocationId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_pkey" PRIMARY KEY ("DoctorSpecializationChargeModuleDetailsId"),
CONSTRAINT "DoctorSpecializationChargeModuleDetails_DoctorSpecializationChargeModuleCategoryId_fkey" FOREIGN KEY ("DoctorSpecializationChargeModuleCategoryId")
REFERENCES public."DoctorSpecializationChargeModuleCategory" ("DoctorSpecializationChargeModuleCategoryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_ConsultationTypeId_fkey" FOREIGN KEY ("ConsultationTypeId")
REFERENCES public."ConsultationType" ("ConsultationTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."DoctorSpecializationChargeModuleDetails"
OWNER to postgres;
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE "LabServices"
DROP CONSTRAINT "FK_LabServices_LabHeaderId";
------------------------------------------------------
ALTER TABLE "LabServices"
DROP COLUMN "LabHeaderId";
-------------------------------------------------------
ALTER TABLE "NewLabBookingDetail"
ADD COLUMN IF NOT EXISTS "LabServicesId" integer;
-------------------------------------------------------
\ No newline at end of file
alter table "LabMainDetail"
add column "ModulesMasterId" int,
add CONSTRAINT "LabMainDetail_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION ;
---------------------------------------------------------------------------
alter table "ScanTestMaster"
add column "ModulesMasterId" int,
add CONSTRAINT "ScanTestMaster_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION ;
----------------------------------------------------------------------------
alter table "Surgery"
add column "ModulesMasterId" int,
add CONSTRAINT "Surgery_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION ;
----------------------------------------------------------------------------
alter table "Room"
add column "ModulesMasterId" int,
add CONSTRAINT "Room_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION ;
------------------------------------------------------------------------------
\ No newline at end of file
Alter table "Charge"
drop column "Cost",
drop column "OpCost";
---------------------------------------
Alter table "Charge"
Add Column "ModulesMasterId" integer;
----------------------------------------------
Alter table "Charge"
Add Constraint "FK_Charge_ModulesMasterId" FOREIGN KEY ("ModulesMasterId") REFERENCES "ModulesMaster" ("ModulesMasterId");
--------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
\ No newline at end of file
insert into "LabBookingStatus"("Status","Active")
values('RemovedDoctor',true);
\ 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
-------------------------------------------------------------------------------------------------------------------------
create sequence "DoctorSpecializationMap_DoctorSpecializationMapId_seq"
--------------------------------------------------------------------------------------------
create table "DoctorSpecializationMap"(
"DoctorSpecializationMapId" integer DEFAULT nextval('"DoctorSpecializationMap_DoctorSpecializationMapId_seq"'::regclass),
"SpecializationId" int,
"ConsultationTypeId" int,
"ProviderId" int,
"FollowUpDays" int,
"FollowUpDaysLimit" int,
CONSTRAINT "DoctorSpecializationMap_pkey" PRIMARY KEY ("DoctorSpecializationMapId"),
CONSTRAINT "DoctorSpecializationMap_SpecializationId" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationMap_ConsultationTypeId_fkey" FOREIGN KEY ("ConsultationTypeId")
REFERENCES public."ConsultationType" ("ConsultationTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationMap_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
-------------------------------------------------------------------------------------------------------
DROP TABLE IF EXISTS public."DoctorSpecializationChargeModuleDetails";
-------------------------------------------------------------------------------------------------------
DROP TABLE IF EXISTS public."DoctorSpecializationChargeModuleCategory";
-------------------------------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."DoctorSpecializationChargeModuleCategory"
(
"DoctorSpecializationChargeModuleCategoryId" integer NOT NULL DEFAULT nextval('"DoctorSpecializationChargeModuleCategory_DoctorSpecializationCh"'::regclass),
"Active" boolean DEFAULT true,
"ChargeTypesId" integer,
"ModulesMasterId" integer,
"ChargeModuleTemplateId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_pkey" PRIMARY KEY ("DoctorSpecializationChargeModuleCategoryId"),
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ChargeModuleTemplateId" FOREIGN KEY ("ChargeModuleTemplateId")
REFERENCES public."ChargeModuleTemplate" ("ChargeModuleTemplateId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ChargeTypesId_fkey" FOREIGN KEY ("ChargeTypesId")
REFERENCES public."ChargeTypes" ("ChargeTypesId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleCategory_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
--------------------------------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."DoctorSpecializationChargeModuleDetails"
(
"DoctorSpecializationChargeModuleDetailsId" bigint NOT NULL DEFAULT nextval('"DoctorSpecializationChargeModuleDetails_DoctorSpecializationCha"'::regclass),
"ReferenceId" integer not null,
"DoctorSpecializationChargeModuleCategoryId" integer,
"Amount" numeric(10,2),
"LocationId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_pkey" PRIMARY KEY ("DoctorSpecializationChargeModuleDetailsId"),
CONSTRAINT "DoctorSpecializationChargeModuleDetails_ReferenceId_fkey" FOREIGN KEY ("ReferenceId")
REFERENCES public."DoctorSpecializationMap" ("DoctorSpecializationMapId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_DoctorSpecializationCha" FOREIGN KEY ("DoctorSpecializationChargeModuleCategoryId")
REFERENCES public."DoctorSpecializationChargeModuleCategory" ("DoctorSpecializationChargeModuleCategoryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorSpecializationChargeModuleDetails_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
---------------------------------------------------------------------------------------------------------
TRUNCATE TABLE "Machine";
----------------------------------------------------------------------------------
alter table "LabParameterHeader"
add column "MachineId" bigint ,
add column "MachineParameterName" character varying(255),
add CONSTRAINT "FK_LabParameterHeader_MachineId" FOREIGN KEY ("MachineId")
REFERENCES public."Machine" ("MachineId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
\ No newline at end of file
create sequence "PaymentMapHelper_PaymentMapId_seq"
------------------------------------------------------------------------------------------------------
create table "PaymentMapHelper"(
"PaymentMapHelperId" integer DEFAULT nextval('"PaymentMapHelper_PaymentMapId_seq"'::regclass),
"PaymentInitiationLogId" integer,
"BillId" integer,
CONSTRAINT "PaymentMapHelper_pkey" PRIMARY KEY ("PaymentMapHelperId"),
CONSTRAINT "FK_PaymentMapHelper_PaymentInitiationLogId" FOREIGN KEY ("PaymentInitiationLogId")
REFERENCES public."PaymentInitiationLog" ("PaymentInitiationLogId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
\ No newline at end of file
alter table "LabBookingDetail" add column "Barcode" boolean;
alter table "LabBookingDetail" add column "BarcodeGeneratedBy" integer;
alter table "LabBookingDetail" add column "BarcodeGeneratedDate" timestamp without time zone;
alter table "LabBookingPackageDetail" add column "IsBarcode" boolean;
alter table "LabBookingPackageDetail" add column "BarcodeGeneratedBy" integer;
alter table "LabBookingPackageDetail" add column "BarcodeGeneratedDate" timestamp without time zone;
\ No newline at end of file
create table "LabDepartment"("LabDepartmentId" serial primary key,"DepartmentName" text,"Description" text,"Active" bool default true,
"CreatedBy" int references "Account"("AccountId"),"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),"ModifiedDate" timestamp without time zone
);
\ No newline at end of file
alter table "LabTemplateDetail" add column "LabParameterHeaderId" int references "LabParameterHeader"("LabParameterHeaderId");
-----------------------
drop table "LabMainDetailCharge";
----------
CREATE OR REPLACE FUNCTION public."fetch_LabParameterDetails_on_conditions"(agetype text DEFAULT NULL::text, headerid integer DEFAULT NULL::integer, fromage integer DEFAULT NULL::integer, gendervalue text DEFAULT NULL::text)
RETURNS TABLE("LabParameterDetailId" bigint, "LabParameterHeaderId" integer, "Gender" character varying, "FromAgeType" character varying, "ToAge" integer, "ToAgeType" character varying, "MinValue" numeric, "MaxValue" numeric, "MinCriticalValue" numeric, "MaxCriticalValue" numeric, "UnitId" integer, "UnitName" character varying)
LANGUAGE plpgsql
AS $function$
declare labdata INTEGER := 0;
BEGIN
select count(*) into labdata
from "LabParameterDetail" a
where a."LabParameterHeaderId" = HeaderId and a."FromAgeType" = AgeType
and case when Gendervalue= '' then 1=1
when Gendervalue is null then 1=1
when Gendervalue= 'Male' then a."Gender" ='Male'
when Gendervalue= 'Female' then a."Gender" ='Female'
else coalesce(a."Gender",'All') = 'All' END
and (FromAge >= a."FromAge" and FromAge <= a."ToAge");
return query
with cts as (
select a."LabParameterDetailId" ,a."LabParameterHeaderId",a."Gender" ,a."FromAgeType" ,a."ToAge" , a."ToAgeType" , a."MinValue" , a."MaxValue" ,
a."MinCriticalValue" , a."MaxCriticalValue" , a."UnitId", lv."Name" as "UnitName"
from "LabParameterDetail" a
join "LookupValue" lv on lv."LookupValueId" = a."UnitId"
where a."LabParameterHeaderId" = HeaderId and a."FromAgeType" = AgeType
and case when Gendervalue= '' then 1=1
when Gendervalue is null then 1=1
when Gendervalue= 'Male' then a."Gender" ='Male'
when Gendervalue= 'Female' then a."Gender" ='Female'
else coalesce(a."Gender",'All') = 'All' END
and (FromAge >= a."FromAge" and FromAge <= a."ToAge") )
select * from cts
union
select a."LabParameterDetailId" ,a."LabParameterHeaderId",a."Gender" ,a."FromAgeType" ,a."ToAge" , a."ToAgeType" , a."MinValue" , a."MaxValue" ,
a."MinCriticalValue" , a."MaxCriticalValue" , a."UnitId", lv."Name" as "UnitName"
from "LabParameterDetail" a
join "LookupValue" lv on lv."LookupValueId" = a."UnitId"
where a."LabParameterHeaderId" = HeaderId and a."FromAgeType" = AgeType
and (FromAge >= a."FromAge" and FromAge <= a."ToAge") and labdata = 0;
END
$function$
;
---------
\ No newline at end of file
CREATE OR REPLACE FUNCTION public."fetch_LabParameterDetails_on_conditions"(
AgeType text DEFAULT NULL::text,
HeaderId integer DEFAULT NULL::integer,
FromAge integer DEFAULT NULL::integer,
Gendervalue text DEFAULT NULL::text
)
RETURNS TABLE("LabParameterDetailId" bigint,"LabParameterHeaderId" int,"Gender" varchar,"FromAgeType" varchar,"ToAge" int,"ToAgeType" varchar,
"MinValue" numeric,"MaxValue" numeric,"MinCriticalValue" numeric,"MaxCriticalValue" numeric, "UnitId" int,"UnitName" varchar )
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
declare labdata INTEGER := 0;
BEGIN
select count(*) into labdata
from "LabParameterDetail" a
where a."LabParameterHeaderId" = HeaderId and a."FromAgeType" = AgeType
and case when Gendervalue= '' then 1=1
when Gendervalue is null then 1=1
when Gendervalue= 'M' then a."Gender" ='M'
when Gendervalue= 'F' then a."Gender" ='F'
else coalesce(a."Gender",'All') = 'All' END
and (FromAge >= a."FromAge" and FromAge <= a."ToAge");
return query
with cts as (
select a."LabParameterDetailId" ,a."LabParameterHeaderId",a."Gender" ,a."FromAgeType" ,a."ToAge" , a."ToAgeType" , a."MinValue" , a."MaxValue" ,
a."MinCriticalValue" , a."MaxCriticalValue" , a."UnitId", lv."Name" as "UnitName"
from "LabParameterDetail" a
join "LookupValue" lv on lv."LookupValueId" = a."UnitId"
where a."LabParameterHeaderId" = HeaderId and a."FromAgeType" = AgeType
and case when Gendervalue= '' then 1=1
when Gendervalue is null then 1=1
when Gendervalue= 'M' then a."Gender" ='M'
when Gendervalue= 'F' then a."Gender" ='F'
else coalesce(a."Gender",'All') = 'All' END
and (FromAge >= a."FromAge" and FromAge <= a."ToAge") )
select * from cts
union
select a."LabParameterDetailId" ,a."LabParameterHeaderId",a."Gender" ,a."FromAgeType" ,a."ToAge" , a."ToAgeType" , a."MinValue" , a."MaxValue" ,
a."MinCriticalValue" , a."MaxCriticalValue" , a."UnitId", lv."Name" as "UnitName"
from "LabParameterDetail" a
join "LookupValue" lv on lv."LookupValueId" = a."UnitId"
where a."LabParameterHeaderId" = HeaderId and a."FromAgeType" = AgeType
and (FromAge >= a."FromAge" and FromAge <= a."ToAge") and labdata = 0;
END
$BODY$;
------------------
create table "LabTemplateObservedValue"(
"LabTemplateObservedValueId" bigserial primary key,
"NewLabBookingDetailId" int references "NewLabBookingDetail"("NewLabBookingDetailId"),
"LabMainDetailId" int references "LabMainDetail"("LabMainDetailId"),
"LabTemplateHeaderId" int references "LabTemplateHeader"("LabTemplateHeaderId"),
"MethodText" text,
"InterpretationText" text,
"Active" boolean default true
);
alter table "LabTemplateObservedValue" add column "CreatedBy" int references "Account"("AccountId"),
add column "CreatedDate" timestamp without time zone;
------------------------
\ No newline at end of file
alter table "PatientRegistrationDetail" add column "PayTypeId" int references "PayType"("PayTypeId");
--------
update "PatientRegistrationDetail" set "PayTypeId" = 1;
----------
\ No newline at end of file
Drop table if exists "LabParameterHeader" cascade;
create table "LabParameterHeader"(
"LabParameterHeaderId" serial primary key,
"ParameterName" text,
"DisplayName" text,
"ReferenceOutput" text,
"Active" bool default true,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
Drop table if exists "LabParameterDetail" cascade;
create table "LabParameterDetail"(
"LabParameterDetailId" bigserial primary key,
"LabParameterHeaderId" int references "LabParameterHeader"("LabParameterHeaderId" ),
"Gender" varchar(30) default null,
"FromAge" int default null,
"FromAgeType" varchar(250) default null,
"ToAge" int default null,
"ToAgeType" varchar(250) default null,
"MinValue" numeric(8,2) default null,
"MaxValue" numeric(8,2) default null,
"MinCriticalValue" numeric(8,2) default null,
"MaxCriticalValue" numeric(8,2) default null,
"UnitId" int references "LookupValue"("LookupValueId")
);
Drop table if exists "LabComponentHeader" cascade;
create table "LabComponentHeader"(
"LabComponentHeaderId" serial primary key,
"ComponentName" text,
"ComponentId" text,
"Active" bool default true,
"CreatedBy" int4 null REFERENCES "Account"("AccountId"),
"CreatedDate" timestamp NULL,
"ModifiedBy" int4 null REFERENCES "Account"("AccountId"),
"ModifiedDate" timestamp NULL
);
Drop table if exists "LabComponentDetail" cascade;
create table "LabComponentDetail"(
"LabComponentDetailId" serial primary key,
"LabComponentHeaderId" int references "LabComponentHeader"("LabComponentHeaderId"),
"LabParameterHeaderId" int references "LabParameterHeader"("LabParameterHeaderId"),
"Priority" int
);
\ No newline at end of file
drop table if exists "LabTemplateHeader" cascade;
create table "LabTemplateHeader"(
"LabTemplateHeaderId" serial primary key,
"TemplateName" text,
"TemplateId" text,
"Active" boolean default true,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
drop table if exists "LabTemplateDetail" cascade;
create table "LabTemplateDetail"(
"LabTemplateDetailId" serial primary key,
"LabTemplateHeaderId" int references "LabTemplateHeader"("LabTemplateHeaderId"),
"LabComponentHeaderId" int references "LabComponentHeader"("LabComponentHeaderId"),
"Priority" int
);
drop table if exists "LabParameterMethod" cascade;
create table "LabParameterMethod"(
"LabParameterMethodId" serial primary key,
"MethodName" text
);
alter table "LabParameterHeader" add column "LabParameterMethodId" int references "LabParameterMethod"("LabParameterMethodId");
\ No newline at end of file
alter table "LabTemplateHeader" add column
"IsMethod" bool default false,
add column "MethodText" text,
add column "IsInterpretation" bool default false,
add column "InterpretationText" text;
----------
drop table if exists "LabSampleType" cascade;
create table "LabSampleType"(
"LabSampleTypeId" serial primary key,
"TypeName" text
);
drop table if exists "LabMainDetail" cascade;
create table "LabMainDetail"(
"LabMainDetailId" serial primary key,
"TestName" text,
"LabDepartmentId" int references "LabDepartment"("LabDepartmentId"),
"TestCode" text,
"LabSampleTypeId" int references "LabSampleType"("LabSampleTypeId"),
"Active" bool default true,
"IsInternalLab" bool default true,
"IsExternalLab" bool default false,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
drop table if exists "LabMainDetailCharge" cascade;
create table "LabMainDetailCharge"(
"LabMainDetailChargeId" bigserial primary key,
"LabMainDetailId" int references "LabMainDetail"("LabMainDetailId"),
"ChargeCategoryId" int references "ChargeCategory"("ChargeCategoryId"),
"Rate" numeric(10,2),
"LocationId" int references "Location"("LocationId")
);
drop table if exists "LabMainDetailTemplate" cascade;
create table "LabMainDetailTemplate"(
"LabMainDetailTemplateId" bigserial primary key,
"LabMainDetailId" int references "LabMainDetail"("LabMainDetailId"),
"LabTemplateHeaderId" int references "LabTemplateHeader"("LabTemplateHeaderId"),
"Priority" int
);
CREATE TABLE "Machine" (
"MachineId" bigserial NOT NULL,
"MachineCode" varchar(255) NULL,
"MachineName" varchar(255) NULL,
"Active" bool NULL DEFAULT true,
"CreatedBy" int8 NOT NULL,
"CreatedDate" timestamp NOT NULL,
"ModifiedBy" int8 NULL,
"ModifiedDate" timestamp NULL,
CONSTRAINT "Machine_pkey" PRIMARY KEY ("MachineId"),
CONSTRAINT "FK_Machine_CreatedBy" FOREIGN KEY ("CreatedBy") REFERENCES "Account"("AccountId")
);
\ No newline at end of file
create table "LabBookingStatus"(
"LabBookingStatusId" serial primary key,
"Status" text,
"Active" boolean default true
);
insert into "LabBookingStatus"("Status" ,"Active") values ('Booked',true),
('Cancelled',true);
alter table "LabBookingStatus" add column "RowColor" text;
create table "NewLabBookingHeader"(
"NewLabBookingHeaderId" serial primary key,
"RequisitionNumber" text,
"Type" varchar(10),
"PatientId" int references "Patient"("PatientId"),
"PatientName" varchar(250),
"Mobile" varchar(15),
"DoctorName" varchar(250),
"DoctorId" int references "Provider"("ProviderId"),
"EmployeeId" int references "Account"("AccountId"),
"LocationId" int references "Location"("LocationId"),
"OverallTotalAmount" numeric(8,2),
"OverallDiscount" numeric(8,2),
"OverallNetAmount" numeric(8,2),
"OverallDiscountPercentage" int,
"PayTypeId" int references "PayType"("PayTypeId"),
"PaymentNumber" text,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone,
"Active" boolean default true
);
create table "NewLabBookingDetail"(
"NewLabBookingDetailId" serial primary key,
"NewLabBookingHeaderId" int references "NewLabBookingHeader"("NewLabBookingHeaderId"),
"LabMainDetailId" int references "LabMainDetail"("LabMainDetailId"),
"ChargeCategoryId" int references "ChargeCategory"("ChargeCategoryId"),
"LabBookingStatusId" int references "LabBookingStatus"("LabBookingStatusId"),
"DiscountPercentage" int,
"DiscountAmount" numeric(8,2),
"TotalAmount" numeric(8,2),
"NetAmount" numeric(8,2)
);
create table "LabBookingTimeLine"(
"LabBookingTimeLineId" serial primary key,
"NewLabBookingHeaderId" int references "NewLabBookingHeader"("NewLabBookingHeaderId"),
"LabBookingStatusId" int references "LabBookingStatus"("LabBookingStatusId"),
"Comment" text,
"CommentedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone
);
\ No newline at end of file
create table "LabSampleCollection"(
"LabSampleCollectionId" serial primary key,
"NewLabBookingDetailId" int references "NewLabBookingDetail"("NewLabBookingDetailId"),
"SampleCollectedBy" int references "Account"("AccountId"),
"CollectionDate" timestamp without time zone,
"IsBarcodeGenerated" boolean default false,
"BarcodeGeneratedBy" int references "Account"("AccountId"),
"BarcodeDate" timestamp without time zone
);
----------------------------------
insert into "LabBookingStatus" ("Status","Active")
values
('SampleCollected', true),
('SampleTransfered', true),
('SampleRecieved', true);
\ No newline at end of file
create table "LabTransferHeader"(
"LabTransferHeaderId" serial primary key,
"TransferNumber" text,
"TransferedBy" int references "Account"("AccountId"),
"TransferedDate" timestamp without time zone,
"TransferedLocationId" int references "Location"("LocationId")
);
create table "LabTransferDetail"(
"LabTransferDetailId" serial primary key,
"LabTransferHeaderId" int references "LabTransferHeader"("LabTransferHeaderId"),
"NewLabBookingDetailId" int references "NewLabBookingDetail"("NewLabBookingDetailId")
);
alter table "LabTransferHeader" add column "ReceivedBy" int references "Account"("AccountId"),
add column "ReceivedDate" timestamp without time zone;
Create table "LabParameterObservedValue"("LabParameterObservedValueId" bigserial primary key,
"NewLabBookingDetailId" int references "NewLabBookingDetail"("NewLabBookingDetailId"),
"LabTemplateHeaderId" int references "LabTemplateHeader"("LabTemplateHeaderId"),
"LabComponentHeaderId" int references "LabComponentHeader"("LabComponentHeaderId"),
"LabParameterHeaderId" int references "LabParameterHeader"("LabParameterHeaderId"),
"ObservedValue" text,
"LabParameterDetailId" int references "LabParameterDetail"("LabParameterDetailId"));
Alter table "LabParameterObservedValue"
add column "CreatedBy" int references "Account"("AccountId"),
add column "CreatedDate" timestamp without time zone,
add column "Active" boolean default true;
----------------
insert into "LabBookingStatus" ("Status","Active") values ('ParameterAdded',true);
------------------
\ No newline at end of file
ALTER TABLE "LabParameterHeader"
ADD COLUMN "Text" VARCHAR;
------------------------------------------------------------
ALTER TABLE "LabParameterDetail"
ADD COLUMN "RangeText" VARCHAR;
------------------------------------------------
\ No newline at end of file
alter table "Patient"
add column if not exists "RelationType" text,
add column if not exists "OccupationDetail" text;
alter table "PatientFamily"
add column if not exists "OccupationDetails" text;
\ No newline at end of file
CREATE TABLE "ChargeModuleTemplate" (
"ChargeModuleTemplateId" serial4 NOT NULL,
"StartDate" timestamp NULL,
"EndDate" timestamp NULL,
"Active" bool NULL DEFAULT true,
"TemplateName" text NULL,
"CreatedBy" int4 NULL,
"CreatedDate" timestamp NULL,
"ModifiedBy" int4 NULL,
"ModifiedDate" timestamp NULL,
"LocationId" int4 NULL,
CONSTRAINT "ChargeModuleTemplate_pkey" PRIMARY KEY ("ChargeModuleTemplateId"),
CONSTRAINT "ChargeModuleTemplate_CreatedBy_fkey" FOREIGN KEY ("CreatedBy") REFERENCES "Account"("AccountId"),
CONSTRAINT "ChargeModuleTemplate_LocationId_fkey" FOREIGN KEY ("LocationId") REFERENCES "Location"("LocationId"),
CONSTRAINT "ChargeModuleTemplate_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy") REFERENCES "Account"("AccountId")
);
-----------------------
CREATE TABLE "ChargeModuleCategory" (
"ChargeModuleCategoryId" serial4 NOT NULL,
"Active" bool NULL DEFAULT true,
"ChargeCategoryId" int4 NULL,
"ModulesMasterId" int4 NULL,
"ChargeModuleTemplateId" int4 NULL,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp,
CONSTRAINT "ChargeModuleCategory_pkey" PRIMARY KEY ("ChargeModuleCategoryId"),
CONSTRAINT "ChargeModuleCategory_ChargeCategoryId_fkey" FOREIGN KEY ("ChargeCategoryId") REFERENCES "ChargeCategory"("ChargeCategoryId"),
CONSTRAINT "ChargeModuleCategory_ChargeModuleTemplateId_fkey" FOREIGN KEY ("ChargeModuleTemplateId") REFERENCES "ChargeModuleTemplate"("ChargeModuleTemplateId"),
CONSTRAINT "ChargeModuleCategory_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId") REFERENCES "ModulesMaster"("ModulesMasterId")
);
-------------
create table "ChargeModuleDetails"(
"ChargeModuleDetailsId" bigserial primary key,
"ReferenceId" int not null,
"ChargeModuleCategoryId" int references "ChargeModuleCategory"("ChargeModuleCategoryId"),
"Amount" numeric(10,2),
"LocationId" int references "Location"("LocationId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp
);
--------------------
alter table "ChargeModuleTemplate" add column "IsInUse" boolean default false;
------------------
alter table "ExcelUploadHistory" add column "LocationId" int references "Location"("LocationId");
ALTER SEQUENCE "LabLogType_LabLogTypeId_seq" RESTART WITH 6;
insert into "LabLogType" ("LogTypeName","Active") values('SMSReport',true),
('LabDepartment',true);
-------------------------
Alter table "LabHeader" add column if not exists "LabDepartmentId" int references "LabDepartment"("LabDepartmentId");
insert into "LabDepartment" ("DepartmentName","Active","CreatedBy" ,"CreatedDate")
values ('Radiology',true,1029,now());
update "LabHeader" set "LabDepartmentId" = 1;
alter table "LabHeader" alter column "LabDepartmentId" set not null;
-------------
\ No newline at end of file
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
ALTER SEQUENCE "Country_CountryId_seq" RESTART WITH 4;
INSERT INTO public."Country"
("CountryName", "ISOCode", "CountryCode","Active", "CreatedBy", "CreatedDate","Currency","CurrencySymbol")
VALUES('Other', 'OTH', '00', true, 1029, now(),'0TH','!');
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, "referredBy" text DEFAULT NULL::text, "referredByName" text DEFAULT NULL::text, mobile text DEFAULT NULL::text, "paymentType" text DEFAULT NULL::text, "fromDate" date DEFAULT NULL::date, "toDate" date DEFAULT NULL::date, "pageIndex" integer DEFAULT 0, "pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "FollowUpForAppointmentId" integer, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "ReferredBy" 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, "TotalAppointments" bigint, "TotalAmount" bigint, "ReceiptCreatedByName" text, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" text)
LANGUAGE plpgsql
AS $function$
BEGIN
return query
with cts as (select coalesce(A."DepartmentId"::text,'GrandTotal') "DepartmentId",
A."ProviderId"::text as "ProviderId",
A."AppointmentDate" ,
A."FollowUpForAppointmentId",
A."AppointmentNo",A."PatientId" "PatientId",Pa."ReferredBy",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
A."PaymentType",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
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 "referredBy" is null then 1=1 when "referredBy" ='' then 1=1 else Pa."ReferredBy" ilike'%'||"referredBy" ||'%' 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 "paymentType" is null then 1=1 when "paymentType" ='' then 1=1 else A."PaymentType" ilike'%'||"paymentType"||'%' end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",Pa."ReferredBy"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
A."PaymentType",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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",
A."FollowUpForAppointmentId",A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else Pa."ReferredBy"::varchar end as "ReferredBy",
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."TotalAppointments",A."TotalAmount",
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"
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"
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$function$
;
Create table "HWCPatient" ("HWCPatientId" serial primary key, "HWCName" varchar(250), "Description" text, "LocationId" int references "Location"("LocationId"),
"Active" boolean default true,"CreatedBy" int references "Account"("AccountId"),"CreatedDate" timestamp without time zone,"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone);
insert into "LogType"("LogTypeId","LogTypeName","Active") values(50,'HWCPatients',true);
alter table "Patient" add column "HWCPatientId" int references "HWCPatient"("HWCPatientId");
Alter table "HWCPatient" add column "RowColor" text;
------------------
drop function "udf_FetchPatients_For_QuickSchedule"(character varying,character varying,character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_QuickSchedule"(filter character varying DEFAULT NULL::text, "patientMobile" character varying DEFAULT NULL::text, "patientName" 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, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone,
"isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean,"HWCName" varchar,"HWCPatientId" int,"Description" text,"RowColor" text)
LANGUAGE plpgsql
AS $function$
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"
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" ,
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT('https://hims-devv.s3.amazonaws.com/', 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 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
$function$
;
-------------
Create table "PatientRegistrationCharge"("PatientRegistrationChargeId" serial primary key,
"LocationId" int references "Location"("LocationId"),
"Charge" numeric(8,2),"Active" boolean default true,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone);
CREATE TABLE "PatientRegistrationDetail"
(
"PatientRegistrationDetailId" serial primary key,
"Charge" numeric(8,2),
"PatientId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
CONSTRAINT "PatientRegistrationDetail_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PatientRegistrationDetail_PatientId_fkey" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
\ No newline at end of file
-- FUNCTION: public.udf_fetchAvailableDates(integer)
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 PARALLEL UNSAFE
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(case when (A."Availability" is null or A."Availability"='') then '[]' else (A."Availability"::json)end) "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$;
ALTER FUNCTION public."udf_fetchAvailableDates"(integer)
OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, integer, integer)
--
--
DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, 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,
"referredBy" text DEFAULT NULL::text,
"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,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "FollowUpForAppointmentId" integer, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "ReferredBy" 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, "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)
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."FollowUpForAppointmentId",
A."AppointmentNo",A."PatientId" "PatientId",Pa."ReferredBy",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
PT."PayTypeName" as "PaymentType",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::text as "TotalAmountStr" ,
sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
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 "referredBy" is null then 1=1 when "referredBy" ='' then 1=1 else Pa."ReferredBy" ilike'%'||"referredBy" ||'%' 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
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",Pa."ReferredBy"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
PT."PayTypeName",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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",
A."FollowUpForAppointmentId",A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else Pa."ReferredBy"::varchar end as "ReferredBy",
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."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"
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"
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, integer, integer)
-- OWNER TO postgres;
DROP FUNCTION public."udf_FetchPatients_For_QuickSchedule"(character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_QuickSchedule"(
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, "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"
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" ,
(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 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$;
-- FUNCTION: public.udf_uiReport_Receipts_Admissions_Location(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
--
DROP FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(
"accountId" integer[] DEFAULT NULL::integer[],
"providerId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"roleId" integer[] DEFAULT NULL::integer[],
"admissionNo" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"receiptId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("ReceiptCreatedBy" text, "RoleName" character varying, "ReceiptDate" timestamp without time zone, "ReceiptId" text, "AdmissionNo" text, "AdmissionDate" date, "AdmissionTime" text, "PatientName" text, "UMRNo" character varying, "PatientMobile" character varying, "ProviderName" character varying, "PayTypeName" character varying, "PaidAmount" numeric, "RefundAmount" numeric, "BalanceAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."FullName",'GrandTotal') "ReceiptCreatedBy",A."RoleName",A."CreatedDate"
"ReceiptDate",coalesce(A."ReceiptId"::text,'Total')"ReceiptId"
,A."AdmissionNo",A."AdmissionDate"::date as "AdmissionDate",to_char(A."AdmissionDate" , 'HH12:MI PM' ) "AdmissionTime",
A."PatientName" "PatientName" ,A."UMRNo",A."Mobile" , A."ProviderName" "ProviderName",
A."PayTypeName",sum(A."PaidAmount") "PaidAmount",sum(A."RefundAmount") "RefundAmount"
,sum(A."PaidAmount")-sum(A."RefundAmount") "BalanceAmount"
from (
select R."ReceiptId",A."FullName",Rl."RoleName",R."CreatedDate" "CreatedDate",
coalesce(case when "ReceiptTypeId"=1 then R."Cost" end,0) as "PaidAmount" ,
coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount" ,Ad."AdmissionNo",ad."AdmissionDate",
ad."AdmissionTime",Ad."LocationId",
pa."FullName" "PatientName",pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",
pt."PayTypeName" from "Receipt" R
join "Admission" ad on Ad."AdmissionId"=R."AdmissionId" and ad."Active" is not false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
join "Patient" pa on Ad."PatientId"=pa."PatientId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" pt on pt."PayTypeId"=R."PayTypeId"
where R."Active" is not false and
case when "accountId" is null then 1=1 else R."CreatedBy" = any("accountId") end
and case when "providerId" is null then 1=1 else pr."ProviderId" = "providerId" end
and case when "locationId" is null then 1=1 else Ad."LocationId" = "locationId" end
and case when "roleId" is null then 1=1 else A."RoleId" = any("roleId") end
and case when "admissionNo" is null then 1=1 else Ad."AdmissionNo" ilike'%'|| "admissionNo"||'%' end
and case when "patientId" is null then 1=1 else pa."PatientId" = "patientId" end
and case when "uMRNo" is null then 1=1 else pa."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pa."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "receiptId" is null then 1=1 else R."ReceiptId" = "receiptId" end
and case when "createdBy" is null then 1=1 else R."CreatedBy" = "createdBy" end
and
case when "payTypeId" is null then 1=1 else R."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=R."CreatedDate" and R."CreatedDate" <="toDate" end
) A
GROUP BY GROUPING SETS((A."ReceiptId",A."RoleName",A."FullName",A."CreatedDate",A."PayTypeName",A."AdmissionNo",
A."AdmissionDate",A."AdmissionTime",A."PatientName",A."UMRNo",A."Mobile",A."ProviderName" ), (A."FullName",
A."CreatedDate"), ())
order by A."FullName"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_Receipts_Appointments_Location(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- DROP FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(
"accountId" integer[] DEFAULT NULL::integer[],
"providerId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"roleId" integer[] DEFAULT NULL::integer[],
"appointmentNo" character varying DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"receiptId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("ReceiptCreatedBy" text, "RoleName" character varying, "ReceiptDate" timestamp without time zone, "ReceiptId" text, "AppointmentNo" character varying, "FollowUpForAppointmentId" integer, "AppointmentDate" date, "AppointmentTime" text, "PatientName" text, "UMRNo" character varying, "PatientMobile" character varying, "ProviderName" character varying, "PaymentType" character varying, "PayTypeName" character varying, "PaidAmount" numeric, "RefundAmount" numeric, "BalanceAmount" numeric, "AppointmentId" integer, "IsAppointmentReceipt" boolean)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."FullName",'GrandTotal') "ReceiptCreatedBy",A."RoleName",A."CreatedDate" "ReceiptDate",
coalesce(A."ReceiptId"::text,'Total')"ReceiptId"
,A."AppointmentNo",A."FollowUpForAppointmentId",A."AppointmentDate"::date as "AppointmentDate", to_char(
A."AppointmentTime" , 'HH12:MI PM' ) "AppointmentTime",
A."PatientName" "PatientName",A."UMRNo",A."Mobile", A."ProviderName" as "ProviderName",A."PaymentType"
,A."PayTypeName",sum(A."PaidAmount") "PaidAmount",sum(A."RefundAmount") "RefundAmount"
,sum(A."PaidAmount")-sum(A."RefundAmount") "BalanceAmount",A."AppointmentId",A."IsAppointmentReceipt"
from (
select R."ReceiptId",A."FullName",Rl."RoleName",R."CreatedDate" "CreatedDate",
coalesce(case when "ReceiptTypeId"=1 then R."Cost" end,0) as "PaidAmount" ,
coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount" ,Ad."FollowUpForAppointmentId",
Ad."AppointmentDate",Ad."AppointmentNo", Ad."AppointmentTime",Ad."LocationId",
pa."FullName" "PatientName",Pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",Ad."PaymentType",
pt."PayTypeName",R."AppointmentId",R."IsAppointmentReceipt" from "Receipt" R
join "Appointment" ad on Ad."AppointmentId"=R."AppointmentId" and ad."Status" <> 'C' and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
join "Patient" pa on Ad."PatientId"=pa."PatientId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" pt on pt."PayTypeId"=R."PayTypeId"
where R."Active" <> false and
case when "accountId" is null then 1=1 else R."CreatedBy" = any("accountId") end
and case when "providerId" is null then 1=1 else pr."ProviderId" = "providerId" end
and case when "locationId" is null then 1=1 else Ad."LocationId" = "locationId" end
and case when "roleId" is null then 1=1 else A."RoleId" = any("roleId") end and
case when "appointmentNo" is null then 1=1 else Ad."AppointmentNo" ilike '%' || "appointmentNo" ||'%' end and
case when "patientId" is null then 1=1 else pa."PatientId" = "patientId" end
and case when "uMRNo" is null then 1=1 else pa."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pa."Mobile" ilike'%'|| "patientMobile"||'%' end
and
case when "receiptId" is null then 1=1 else R."ReceiptId" = "receiptId" end
and
case when "createdBy" is null then 1=1 else R."CreatedBy" = "createdBy" end
and
case when "payTypeId" is null then 1=1 else pt."PayTypeId" = "payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=R."CreatedDate" and R."CreatedDate" <="toDate" and R."Active" is not false end
) A
GROUP BY GROUPING SETS((A."ReceiptId",A."RoleName",A."FullName",A."CreatedDate",A."PaymentType",A."PayTypeName",
A."FollowUpForAppointmentId",A."AppointmentDate",A."AppointmentNo"
,A."AppointmentTime",A."PatientName",A."UMRNo",A."Mobile",A."ProviderName",A."AppointmentId",
A."IsAppointmentReceipt"), (A."FullName"), ())
order by A."FullName"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, text, text, text, text, date, date, integer, integer)
--
--
--
DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, text, date, date, 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,
"referredBy" text DEFAULT NULL::text,
"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,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text,
"ProviderName" character varying, "FollowUpForAppointmentId" integer,
"AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer,
"ReferredBy" 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, "TotalAppointments" bigint, "
TotalAmount" bigint, "ReceiptCreatedByName" text, "
ReceiptDate" timestamp without time zone, "ReceiptId" integer,
"StreetAdress" character varying, "City" character varying,
"State" character varying, "FatherOrHusband" 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."FollowUpForAppointmentId",
A."AppointmentNo",A."PatientId" "PatientId",Pa."ReferredBy",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
PT."PayTypeName" as "PaymentType",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
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 "referredBy" is null then 1=1 when "referredBy" ='' then 1=1 else Pa."ReferredBy" ilike'%'||"referredBy" ||'%' 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
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",Pa."ReferredBy"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
PT."PayTypeName",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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",
A."FollowUpForAppointmentId",A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else Pa."ReferredBy"::varchar end as "ReferredBy",
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."TotalAppointments",A."TotalAmount",
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"
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"
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, text, date, date, integer, integer)
-- OWNER TO postgres;
create table "WebNotificationLogType"(
"WebNotificationLogTypeId" serial primary key,
"LogType" varchar(250),
"IsClickable" boolean default false,
"Description" varchar(300)
);
insert into "WebNotificationLogType" ("LogType","IsClickable","Description")
values('Alert',false,'This is for alert'),
('View',true,'This is for view and clickable');
-----------------------------
create table "WebNotificationPriority"(
"WebNotificationPriorityId" serial primary key,
"Priority" varchar(250),
"Active" boolean default true
);
insert into "WebNotificationPriority"("Priority") values ('High'),('Medium'),('Low');
create table "WebNotification"(
"WebNotificationId" serial primary key,
"Message" text,
"WebNotificationPriorityId" int references "WebNotificationPriority"("WebNotificationPriorityId"),
"WebNotificationLogTypeId" int references "WebNotificationLogType"("WebNotificationLogTypeId"),
"CreatedDate" timestamp without time zone,
"RedirectionLink" text,
"AllowedRoles" text,
"AllowedAccounts" text,
"IsRead" boolean default true
);
--------
Alter table "WebNotification" add column "PatientId" int references "Patient"("PatientId");
------------------
Alter table "WebNotification" add column "ReferenceId" bigint;
-----------
\ No newline at end of file
alter table "OTRegister"
drop column "CaseType"
--------------------------------
alter table "OTRegister"
add column "CaseTypeId" integer,
ADD CONSTRAINT "FK_OTRegister_CaseTypeId_fkey" FOREIGN KEY ("CaseTypeId")
REFERENCES public."CaseType" ("CaseTypeId")
\ No newline at end of file
ALTER TABLE "OTRegister"
ADD COLUMN "Status" character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT 'B'::bpchar
ALTER TABLE "OTRegister"
ADD COLUMN "Reason" text COLLATE pg_catalog."default"
ALTER TABLE "OTRegister"
add COLUMN "LocationId" integer,
add CONSTRAINT "OTRegister_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
alter table "OTRegister"
add column "OldAppointmentDate" timestamp(6) without time zone
\ No newline at end of file
-- SEQUENCE: public.AccountCredential_AccountCredentialId_seq
-- DROP SEQUENCE IF EXISTS public."AccountCredential_AccountCredentialId_seq";
CREATE SEQUENCE IF NOT EXISTS public."OTRegister_OTRegisterId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
DROP TABLE IF EXISTS public."OTRegister";
CREATE TABLE IF NOT EXISTS public."OTRegister"
(
"OTRegisterId" integer NOT NULL DEFAULT nextval('"OTRegister_OTRegisterId_seq"'::regclass),
"PatientId" integer NOT NULL,
"SurgeryId" integer NOT NULL,
"ProviderId" integer NOT NULL,
"AssitantId" integer NOT NULL,
"AnaesthetistId" integer NOT NULL,
"AnaesthesiaTypeId" integer NOT NULL,
"NurseId" integer NOT NULL,
"SurgeryTypeId" integer NOT NULL,
"CaseType" character varying(10) COLLATE pg_catalog."default",
"Diagnosis" character varying(20) COLLATE pg_catalog."default",
"Remarks" character varying(30) COLLATE pg_catalog."default",
"Active" boolean NOT NULL DEFAULT true,
"OREntryDate" timestamp(6) without time zone NOT NULL,
"SignInDate" timestamp(6) without time zone NOT NULL,
"SignOutDate" timestamp(6) without time zone NOT NULL,
"ShiftWardToDate" timestamp(6) without time zone NOT NULL,
"Address" character varying(80) COLLATE pg_catalog."default",
"CreatedBy" integer,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"OTRoomId" integer,
CONSTRAINT "OTRegister_pkey" PRIMARY KEY ("OTRegisterId"),
CONSTRAINT "FK_IdProof_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_IdProof_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_OTRegister_PatientId" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_OTRoom_Surgery_fkey" FOREIGN KEY ("OTRoomId")
REFERENCES public."OTRoom" ("OTRoomId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRegister_AnaesthesiaTypeId_fkey" FOREIGN KEY ("AnaesthesiaTypeId")
REFERENCES public."AnaesthesiaType" ("AnaesthesiaTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRegister_AnaesthetistId_fkey" FOREIGN KEY ("AnaesthetistId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRegister_AssitantId_fkey" FOREIGN KEY ("AssitantId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRegister_NurseId_fkey" FOREIGN KEY ("NurseId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRegister_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRegister_SurgeryId_fkey" FOREIGN KEY ("SurgeryId")
REFERENCES public."Surgery" ("SurgeryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."OTRegister"
OWNER to postgres;
---------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."AnaesthesiaType_AnaesthesiaType_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
CREATE TABLE IF NOT EXISTS public."AnaesthesiaType"
(
"AnaesthesiaTypeId" bigint NOT NULL DEFAULT nextval('"AnaesthesiaType_AnaesthesiaType_seq"'::regclass),
"Name" character varying(255) COLLATE pg_catalog."default",
"Active" boolean DEFAULT true,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "AnaesthesiaType_pkey" PRIMARY KEY ("AnaesthesiaTypeId"),
CONSTRAINT "FK_AnaesthesiaType_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_AnaesthesiaType_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
---------------------------------------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."CaseType_CaseypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1
CREATE TABLE IF NOT EXISTS public."CaseType"
(
"CaseTypeId" integer NOT NULL DEFAULT nextval('"CaseType_CaseypeId_seq"'::regclass),
"CaseName" character varying(100) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "CaseType_pkey" PRIMARY KEY ("CaseTypeId")
)
-----------------------------------------------------
INSERT INTO public."LogType"(
"LogTypeId", "LogTypeName", "Active")
VALUES (71,'OTRegister', true);
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."OTRoomSurgeryMap_OTRoomSurgeryMapId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
CREATE TABLE IF NOT EXISTS public."OTRoomSurgeryMap"
(
"OTRoomSurgeryMapId" bigint NOT NULL DEFAULT nextval('"OTRoomSurgeryMap_OTRoomSurgeryMapId_seq"'::regclass),
"OTRoomId" integer NOT NULL,
"SurgeryId" integer NOT NULL,
"LocationId" integer NOT NULL,
CONSTRAINT "OTRoomSurgeryMap_pkey" PRIMARY KEY ("OTRoomSurgeryMapId"),
CONSTRAINT "OTRoomSurgeryMap_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRoomSurgeryMap_OTRoomId_fkey" FOREIGN KEY ("OTRoomId")
REFERENCES public."OTRoom" ("OTRoomId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRoomSurgeryMapp_SurgeryId_fkey" FOREIGN KEY ("SurgeryId")
REFERENCES public."Surgery" ("SurgeryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
\ No newline at end of file
CREATE TABLE IF NOT EXISTS public."ToggleSetting"
(
"ToggleSettingId" integer NOT NULL DEFAULT nextval('"ToggleSetting_ToggleSettingId_seq"'::regclass),
"Name" text COLLATE pg_catalog."default",
"JsonData" text COLLATE pg_catalog."default",
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "ToggleSetting_pkey" PRIMARY KEY ("ToggleSettingId")
)
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
CREATE TABLE "PatientChatBox" (
"PatientChatBoxId" serial NOT NULL,
"CreatedBy" int4 NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"Message" text NOT NULL,
"AppointmentId" int4 NOT NULL,
CONSTRAINT "PatientChatBoxId_pkey" PRIMARY KEY ("PatientChatBoxId")
);
-- public."PatientChatBox" foreign keys
ALTER TABLE public."PatientChatBox" ADD CONSTRAINT "PatientChatBoxId_AppointmentId_fkey" FOREIGN KEY ("AppointmentId") REFERENCES "Appointment"("AppointmentId");
ALTER TABLE public."PatientChatBox" ADD CONSTRAINT "PatientChatBoxId_CreatedBy_fkey" FOREIGN KEY ("CreatedBy") REFERENCES "Account"("AccountId");
----------
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."PatientExcelHistory_UserExcelHistoryId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- Table: public.PatientExcelHistory
-- DROP TABLE IF EXISTS public."PatientExcelHistory";
CREATE TABLE IF NOT EXISTS public."PatientExcelHistory"
(
"PatientExcelHistoryId" integer NOT NULL DEFAULT nextval('"PatientExcelHistory_UserExcelHistoryId_seq"'::regclass),
"SheetName" text COLLATE pg_catalog."default",
"UploadedBy" integer,
"CreatedDate" timestamp without time zone,
"LocationId" integer,
"AddedPatients" text COLLATE pg_catalog."default",
CONSTRAINT "PatientExcelHistory_pkey" PRIMARY KEY ("PatientExcelHistoryId"),
CONSTRAINT "PatientExcelHistory_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PatientExcelHistory_UploadedBy_fkey" FOREIGN KEY ("UploadedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
\ No newline at end of file
INSERT INTO public."PaymentModule"(
"PaymentModuleId", "Name", "Active")
VALUES (6, 'Admission', true);
\ No newline at end of file
-------------------------------------------------------------
----------------------------APpointmnet Table----------------------------------
--------------------------------------------------
alter table "Appointment" drop column if exists "PayTypeId";
alter table "Appointment"
add column if not exists "PayTypeId" integer references "PayType"("PayTypeId");
--------------------------------------
ALTER TABLE "PayType"
ALTER COLUMN "PayTypeValue" TYPE varchar(255);
-------------------------------------------------------
with T as(
select A."AppointmentId",PT."PayTypeId" from "Appointment" A
join "PayType" PT on lower(A."PaymentType") = lower(PT."PayTypeValue")
)
update "Appointment" P set "PayTypeId" = T."PayTypeId" from T where P."AppointmentId" = T."AppointmentId";
--------------------------------------------------------
-----------------------------LAbBookingHeader----------------------------------
---------------------------------------------
alter table "LabBookingHeader" drop column if exists "PayTypeId";
alter table "LabBookingHeader"
add column if not exists "PayTypeId" integer references "PayType"("PayTypeId");
---------------------------
with T as(
select LBH."LabBookingHeaderId",PT."PayTypeId" from "LabBookingHeader" LBH
join "PayType" PT on lower(LBH."PaidVia") = lower(PT."PayTypeValue")
)
update "LabBookingHeader" L set "PayTypeId" = T."PayTypeId" from T where L."LabBookingHeaderId" = T."LabBookingHeaderId";
--------------------------------------------------------------------------
\ 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
ALter table "PharmacyProduct" add column if not exists "MedicationId" text;
--------------------------
Create table if not exists "ModuleDepartmentDetail"("ModuleDepartmentDetailId" serial primary key,"ModuleName" text,
"DepartmentId" int references "Department"("DepartmentId"),
"Active" boolean default true,
"CreatedBy" int references "Account"("AccountId"),"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),"ModifiedDate" timestamp without time zone
);
Create table if not exists "ModuleDepartmentUser"("ModuleDepartmentUserId" serial primary key,"ModuleDepartmentDetailId" int references "ModuleDepartmentDetail"("ModuleDepartmentDetailId"),
"AccountId" int references "Account"("AccountId"));
--------------------
Alter table "ModuleDepartmentDetail" add column "LocationId" int references "Location"("LocationId");
-----------------
-- FUNCTION: public.udf_fetchAvailableDates(integer)
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 PARALLEL UNSAFE
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(case when (A."Availability" is null or A."Availability"='') then '[]' else (A."Availability"::json)end) "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$;
ALTER FUNCTION public."udf_fetchAvailableDates"(integer)
OWNER TO postgres;
drop TABLE if exists "PharmacyProductDetail";
drop TABLE if exists "PharmacyDepartmentalStock";
DROP TABLE if exists "ModuleDepartmentUser";
DROP TABLE if exists "ModuleDepartmentDetail";
-------------------
Create table "PharmacyDepartment"("PharmacyDepartmentId" serial Primary Key,"Name" varchar(300),"Active" boolean default true,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone,
"LocationId" int references "Location"("LocationId")
);
CREATE TABLE "PharmacyDepartmentUser"
(
"PharmacyDepartmentUserId" serial primary key,
"PharmacyDepartmentId" int references "PharmacyDepartment"("PharmacyDepartmentId"),
"AccountId" int
);
-----------------
Create table "PharmacyProductRack"("PharmacyProductRackId" serial Primary Key,
"RackName" text,"LocationId" int references "Location"("LocationId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
--------------
CREATE TABLE "PharmacyDepartmentalStock"
(
"PharmacyDepartmentalStockId" serial primary key,
"PharmacyProductId" integer,
"TaxId" integer,
"QuantityIn" integer,
"QuantityOut" integer,
"BatchNumber" character varying(50) COLLATE pg_catalog."default",
"ExpiryDate" date,
"PurchaseRate" numeric(8,2),
"Mrp" numeric(8,2),
"Barcode" character varying(50) COLLATE pg_catalog."default",
"PharmacyStockId" integer,
"PharmacyRetailStockId" integer references "PharmacyRetailStock"("PharmacyRetailStockId"),
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"PharmacyDepartmentId" int references "PharmacyDepartment"("PharmacyDepartmentId"),
CONSTRAINT "PharmacyDepartmentalStock_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PharmacyDepartmentalStock_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PharmacyDepartmentalStock_PharmacyProductId_fkey" FOREIGN KEY ("PharmacyProductId")
REFERENCES public."PharmacyProduct" ("PharmacyProductId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PharmacyDepartmentalStock_PharmacyStockId_fkey" FOREIGN KEY ("PharmacyStockId")
REFERENCES public."PharmacyStock" ("PharmacyStockId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "PharmacyDepartmentalStock_TaxId_fkey" FOREIGN KEY ("TaxId")
REFERENCES public."LookupValue" ("LookupValueId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
------------------------------------------
Create table "PharmacyProductDetail"("PharmacyProductDetailId" serial primary key,
"PharmacyProductRackId" int references "PharmacyProductRack"("PharmacyProductRackId"),
"ROQ" int,"ROL" int,"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"PharmacyStockId" int references "PharmacyStock"("PharmacyStockId"),
"PharmacyRetailStockId" int references "PharmacyRetailStock"("PharmacyRetailStockId"),
"PharmacyDepartmentalStockId" int references "PharmacyDepartmentalStock"("PharmacyDepartmentalStockId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone
);
-----------------------
Alter table "IndentHeader" add column "PharmacyDepartmentId" int references "PharmacyDepartment"("PharmacyDepartmentId");
--------------------------
alter table "PharmacyProduct" add column "Suppliers" text;
-------------
alter table "PharmacyProductDetail" add column "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");
alter table "PharmacyProductRack" add column "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");
--------------------------
----ImpQuery
with cts as(
select distinct count(ps."PharmacyProductId" ) over(partition by ps."PharmacyWareHouseId") as "Count",ps."PharmacyWareHouseId",ps."PharmacyProductId" from "PharmacyStock" ps
)
insert into "PharmacyProductDetail" ( "ROQ", "ROL", "PharmacyProductId", "CreatedBy", "CreatedDate", "PharmacyWareHouseId")
select coalesce(pp."MinQuantity",100) as "ROQ", coalesce(pp."RolQuantity",100) as "ROL",
c."PharmacyProductId",pp."CreatedBy",now() as "CreatedDate",c."PharmacyWareHouseId"
from "PharmacyProduct" pp
join cts c on c."PharmacyProductId" = pp."PharmacyProductId"
----Done---
create table "ProductRaiseStatus"(
"ProductRaiseStatusId" serial primary key,
"Status" varchar(250)
);
insert into "ProductRaiseStatus" ("Status") values
('Raised'),
('Rejected'),
('Completed');
--------
create table "ProductGroupForTender"(
"ProductGroupForTenderId" serial primary key,
"PharmacyProductId" int REFERENCES "PharmacyProduct"("PharmacyProductId"),
"ProductRaiseStatusId" int references "ProductRaiseStatus"("ProductRaiseStatusId"),
"PharmacyDepartmentId" int REFERENCES "PharmacyDepartment"("PharmacyDepartmentId"),
"RetailPharmacyId" int REFERENCES "RetailPharmacy"("RetailPharmacyId"),
"PharmacyWareHouseId" int REFERENCES "PharmacyWareHouse"("PharmacyWareHouseId"),
"Active" bool default true,
"CreatedBy" int REFERENCES "Account"("AccountId"),
"CreatedDate" timestamp without time zone
);
\ No newline at end of file
insert into "ProductRaiseStatus" ("Status") values ('Accepted');
------------------------------------------
alter table "ProductGroupForTender" add column "ApprovedBy" int references "Account"("AccountId") ,
add column"ApprovedDate" timestamp without time zone;
------------
alter table "PharmacyWareHouse" add column "CentralWarehouseLocationId" int references "Location"("LocationId");
-------------
alter table "RequestIndentHeader" add column "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");
-- important
-- oncomplition
--drop table "RequestIndentStatus"
alter table "RequestIndentHeader" drop column "RequestIndentStatusId",drop column "RequestIndentTypeId";
alter table "RequestIndentHeader" add column "ProductRaiseStatusId" int references "ProductRaiseStatus"("ProductRaiseStatusId");
insert into "ProductRaiseStatus" ("Status") values ('Pending');
insert into "ProductRaiseStatus" ("Status") values ('IndentRaised');
insert into "ProductRaiseStatus" ("Status") values ('IndentApproved');
------------
drop table if exists "RequestIndentDetail";
create table "RequestIndentDetail"(
"RequestIndentDetailId" bigserial primary key,
"RequestIndentHeaderId" int references "RequestIndentHeader"("RequestIndentHeaderId"),
"Quantity" int,
"ProductGroupForTenderId" int references "ProductGroupForTender"("ProductGroupForTenderId")
);
---------
\ No newline at end of file
alter table "PharmacyProductDetail" drop column "PharmacyRetailStockId";
alter table "PharmacyProductDetail" add column "RetailPharmacyId" int references "RetailPharmacy"("RetailPharmacyId");
alter table "PharmacyProductRack" drop column "LocationId";
alter table "PharmacyProductRack" add column "RetailPharmacyId" int references "RetailPharmacy"("RetailPharmacyId");
alter table "PharmacyProductRack" add column "PharmacyDepartmentId" int references "PharmacyDepartment"("PharmacyDepartmentId");
-- Creating table for acknowledgment of issued products.
create table "PharmacyIssuedStockHeader"(
"PharmacyIssuedStockHeaderId" bigserial primary key,
"IssuedDate" timestamp without time zone,
"IssuedBy" int references "Account"("AccountId"),
"HandOverTo" int references "Account"("AccountId"),
"Comment" text,
"RetailWareHouseLinkId" int references "RetailWareHouseLink"("RetailWareHouseLinkId") default null,
"PharmacyDepartmentId" int references "PharmacyDepartment"("PharmacyDepartmentId") default null,
"ReceivedBy" int references "Account"("AccountId") default null,
"ReceivedDate" timestamp without time zone default null
);
alter table "PharmacyIssuedStockHeader" add column "IssueHeaderId" int references "IssueHeader"("IssueHeaderId");
alter table "PharmacyIssuedStockHeader" add column "IssueNumber" text;
CREATE TABLE "PharmacyIssuedStockDetail" (
"PharmacyIssuedStockDetailId" bigserial primary key,
"PharmacyIssuedStockHeaderId" bigint references "PharmacyIssuedStockHeader"("PharmacyIssuedStockHeaderId"),
"PharmacyProductId" int4 NULL,
"TaxId" int4 NULL,
"QuantityIn" int4 NULL,
"BatchNumber" varchar(50) NULL,
"ExpiryDate" date NULL,
"PurchaseRate" numeric(8, 2) NULL,
"Mrp" numeric(8, 2) NULL,
"Barcode" varchar(50) NULL,
"PharmacyStockId" int4 NULL
);
------------------
drop table if exists "PharmacyProductDetail";
--------
Create table "PharmacyProductDetail"("PharmacyProductDetailId" serial primary key,
"PharmacyProductRackId" int references "PharmacyProductRack"("PharmacyProductRackId"),
"ROQ" int,"ROL" int,"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"PharmacyStockId" int references "PharmacyStock"("PharmacyStockId"),
"PharmacyRetailStockId" int references "PharmacyRetailStock"("PharmacyRetailStockId"),
"PharmacyDepartmentId" int references "PharmacyDepartment"("PharmacyDepartmentId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone
);
----------
\ No newline at end of file
CREATE OR REPLACE FUNCTION public."udf_PharmacyPurchaseReport1"("billNumber" text DEFAULT NULL::text, "billType" text DEFAULT NULL::text, "createdBy" integer DEFAULT NULL::integer, "supplierId" integer DEFAULT NULL::integer, "paidVia" text DEFAULT NULL::text, "dueDate" 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, "pharmacyBillType" boolean DEFAULT NULL::boolean, "pharmacyWareHouseId" integer DEFAULT NULL::integer, "locationId" text DEFAULT NULL::text)
RETURNS TABLE("PharmacyPurchaseHeaderId" integer, "DueDate" timestamp without time zone, "BillNumber" character varying, "BillType" character varying, "BillDate" timestamp without time zone, "CreatedByName" text, "RoleName" character varying, "SupplierName" text, "NetAmount" numeric, "WareHouseName" text, "LocationName" character varying)
LANGUAGE plpgsql
AS $function$
BEGIN
return query
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",PH."BillDate",ph."CreatedByName",
ph."Role",ph."SupplierName", PH."NetAmount",PH."WareHouseName",PH."LocationName" from
(
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",PH."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName",PH."Netamount" "NetAmount",true "PharmacyBillType"
,PW."WareHouseName",L."Name" as "LocationName"
from "PharmacyPurchaseHeader" PH
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "Account" A on A."AccountId"=ph."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacyWareHouse" PW on PW."PharmacyWareHouseId"=PH."PharmacyWareHouseId"
left join "Location" L on L."LocationId" = PW."LocationId"
left join "PharmacyPurchaseReturnHeader" pr on pr."PharmacyPurchaseHeaderId" = PH."PharmacyPurchaseHeaderId"
where
case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
-- case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end
case when "supplierId" is null then 1=1 else ph."SupplierId" = "supplierId"::int end and
case when "paidVia" is null then 1=1 else PH."BillType" ilike '%' || "paidVia" ||'%' end and
case when "dueDate" is null then 1=1 else "dueDate" =PH."DueDate"::date end
and case when "fromDate" is null then 1=1
else (PH."CreatedDate" >= "fromDate" and PH."CreatedDate" <= "toDate") end and
case when "pharmacyWareHouseId" is null then 1=1 else PW."PharmacyWareHouseId" = "pharmacyWareHouseId" end and
case when "locationId" is null then 1=1 else (PW."LocationId" = "locationId"::int or PW."LocationId" is null) end
group by PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate", PH."Netamount",S."Name",S."SupplierId",
A."FullName" ,R."RoleName",PW."WareHouseName",L."Name"
union
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",prh."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName", -prh."OverallNetamount" "Netamount",false "PharmacyBillType"
,PW."WareHouseName",L."Name" as "LocationName"
from "PharmacyPurchaseReturnHeader" prh
join "Account" A on A."AccountId"=prh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
Join "PharmacyPurchaseHeader" ph on ph."PharmacyPurchaseHeaderId"= prh."PharmacyPurchaseHeaderId"
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyWareHouse" PW on PW."PharmacyWareHouseId" =ph."PharmacyWareHouseId"
left join "Location" L on L."LocationId" = PW."LocationId"
where
case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
-- case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end
case when "supplierId" is null then 1=1 else ph."SupplierId" = "supplierId"::int end
and case when "paidVia" is null then 1=1 else PH."BillType" ilike '%' || "paidVia" ||'%' end and
case when "dueDate" is null then 1=1 else "dueDate" =PH."DueDate"::date end
--and case when "fromDate" is null then 1=1 else PH."BillDate" >= "fromDate" end
--and case when "toDate" is null then 1=1 else PH."BillDate" <= "toDate" end
and case when "fromDate" is null then 1=1
else (PH."CreatedDate" >= "fromDate" and PH."CreatedDate" <= "toDate") end and
case when "pharmacyWareHouseId" is null then 1=1 else PW."PharmacyWareHouseId" = "pharmacyWareHouseId" end and
case when "locationId" is null then 1=1 else (PW."LocationId" = "locationId"::int or PW."LocationId" is null) end
group by PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",prh."CreatedDate",A."FullName"
,R."RoleName" ,S."Name" ,s."SupplierId", prh."OverallNetamount",PW."WareHouseName",L."Name"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."BillDate" desc, PH."PharmacyPurchaseHeaderId";
END
$function$
;
-- FUNCTION: public.udf_PharmacyPurchaseReport(text, text, integer, text, text, date, timestamp without time zone, timestamp without time zone, boolean, integer, text)
-- DROP FUNCTION IF EXISTS public."udf_PharmacyPurchaseReport1"(text, text, integer, integer, text, date, timestamp without time zone, timestamp without time zone, boolean, integer, text);
CREATE OR REPLACE FUNCTION public."udf_PharmacyPurchaseReport1"(
"billNumber" text DEFAULT NULL::text,
"billType" text DEFAULT NULL::text,
"createdBy" integer DEFAULT NULL::integer,
"supplierId" integer DEFAULT NULL::integer,
"paidVia" text DEFAULT NULL::text,
"dueDate" 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,
"pharmacyBillType" boolean DEFAULT NULL::boolean,
"pharmacyWareHouseId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PharmacyPurchaseHeaderId" integer, "DueDate" timestamp without time zone, "BillNumber" character varying, "BillType" character varying, "BillDate" timestamp without time zone, "CreatedByName" text, "RoleName" character varying, "SupplierName" text, "NetAmount" numeric, "WareHouseName" text, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",PH."BillDate",ph."CreatedByName",
ph."Role",ph."SupplierName", PH."NetAmount",PH."WareHouseName",PH."LocationName" from
(
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",PH."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName",PH."Netamount" "NetAmount",true "PharmacyBillType"
,PW."WareHouseName",L."Name" as "LocationName"
from "PharmacyPurchaseHeader" PH
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "Account" A on A."AccountId"=ph."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacyWareHouse" PW on PW."PharmacyWareHouseId"=PH."PharmacyWareHouseId"
join "Location" L on L."LocationId" = PW."LocationId"
left join "PharmacyPurchaseReturnHeader" pr on pr."PharmacyPurchaseHeaderId" = PH."PharmacyPurchaseHeaderId"
where
case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
-- case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end
case when "supplierId" is null then 1=1 else ph."SupplierId" = "supplierId"::int end and
case when "paidVia" is null then 1=1 else PH."BillType" ilike '%' || "paidVia" ||'%' end and
case when "dueDate" is null then 1=1 else "dueDate" =PH."DueDate"::date end
and case when "fromDate" is null then 1=1
else (PH."CreatedDate" >= "fromDate" and PH."CreatedDate" <= "toDate") end and
case when "pharmacyWareHouseId" is null then 1=1 else PW."PharmacyWareHouseId" = "pharmacyWareHouseId" end and
case when "locationId" is null then 1=1 else PW."LocationId" = "locationId"::int end
group by PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate", PH."Netamount",S."Name",S."SupplierId",
A."FullName" ,R."RoleName",PW."WareHouseName",L."Name"
union
select PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",prh."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName", -prh."OverallNetamount" "Netamount",false "PharmacyBillType"
,PW."WareHouseName",L."Name" as "LocationName"
from "PharmacyPurchaseReturnHeader" prh
join "Account" A on A."AccountId"=prh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
Join "PharmacyPurchaseHeader" ph on ph."PharmacyPurchaseHeaderId"= prh."PharmacyPurchaseHeaderId"
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyWareHouse" PW on PW."PharmacyWareHouseId" =ph."PharmacyWareHouseId"
join "Location" L on L."LocationId" = PW."LocationId"
where
case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
-- case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end
case when "supplierId" is null then 1=1 else ph."SupplierId" = "supplierId"::int end
and case when "paidVia" is null then 1=1 else PH."BillType" ilike '%' || "paidVia" ||'%' end and
case when "dueDate" is null then 1=1 else "dueDate" =PH."DueDate"::date end
--and case when "fromDate" is null then 1=1 else PH."BillDate" >= "fromDate" end
--and case when "toDate" is null then 1=1 else PH."BillDate" <= "toDate" end
and case when "fromDate" is null then 1=1
else (PH."CreatedDate" >= "fromDate" and PH."CreatedDate" <= "toDate") end and
case when "pharmacyWareHouseId" is null then 1=1 else PW."PharmacyWareHouseId" = "pharmacyWareHouseId" end and
case when "locationId" is null then 1=1 else PW."LocationId" = "locationId"::int end
group by PH."PharmacyPurchaseHeaderId" ,PH."DueDate",PH."BillNumber",PH."BillType",prh."CreatedDate",A."FullName"
,R."RoleName" ,S."Name" ,s."SupplierId", prh."OverallNetamount",PW."WareHouseName",L."Name"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."BillDate" desc, PH."PharmacyPurchaseHeaderId";
END
$BODY$;
ALTER FUNCTION public."udf_PharmacyPurchaseReport1"(text, text, integer, integer, text, date, timestamp without time zone, timestamp without time zone, boolean, integer, text)
OWNER TO postgres;
Alter table "PharmacyProductDetail" add column "ModifiedBy" int references "Account"("AccountId");
Alter table "PharmacyProductDetail" add column "ModifiedDate" timestamp without time zone;
\ No newline at end of file
alter table "PharmacyProductDetail" drop column "PharmacyStockId" ;
\ No newline at end of file
INSERT INTO "Settings" ("Name", "Active", "Type", "Value", "ImageUrl", "Description", "Numeral") VALUES('Direct Stock Credit To Retail', true, 'Pharmacy', NULL, NULL, 'This setting will be used to enable direct stock credit to retail store whenever purchase bill will be added.', NULL);
INSERT INTO "Settings" ("Name", "Active", "Type", "Value", "ImageUrl", "Description", "Numeral") VALUES('Sales Bill Discount Display', true, 'Pharmacy', NULL, NULL, 'This will be used to show/hide discount option in Pharmacy', NULL);
--------------------------
alter table "PharmacyStock" add column "IsIGST" boolean default false,add column "IsSGST" boolean default false;
------
alter table "PharmacyRetailStock" add column "IsIGST" boolean default false,add column "IsSGST" boolean default false;
update "PharmacyStock" set "IsSGST" = true where "IsIGST" = false ;
update "PharmacyRetailStock" set "IsSGST" = true where "IsIGST" = false ;
--------------------
\ No newline at end of file
-- SEQUENCE: public.ProviderBreak_ProviderBreakId_seq
-- DROP SEQUENCE IF EXISTS public."ProviderBreak_ProviderBreakId_seq";
CREATE SEQUENCE IF NOT EXISTS public."ProviderBreak_ProviderBreakId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."srrrreeeeeer_ProviderBreakId_seq"
OWNER TO postgres;
------------------------------------
-- Table: public.ProviderBreak
-- DROP TABLE IF EXISTS public."ProviderBreak";
CREATE TABLE IF NOT EXISTS public."ProviderBreak"
(
"ProviderBreakId" integer NOT NULL DEFAULT nextval('"ProviderBreak_ProviderBreakId_seq"'::regclass),
"ProviderId" integer NOT NULL,
"LocationId" integer NOT NULL,
"ConsultationTypeId" integer,
"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,
"StartDate" character varying COLLATE pg_catalog."default",
"EndDate" character varying COLLATE pg_catalog."default",
"SpecializationId" integer,
"BreakDay" text COLLATE pg_catalog."default",
"StartTime" text COLLATE pg_catalog."default",
"EndTime" text COLLATE pg_catalog."default",
"BreakDate" text COLLATE pg_catalog."default",
"BreakType" character varying COLLATE pg_catalog."default",
"BreakBlock" character varying COLLATE pg_catalog."default",
CONSTRAINT "ProviderBreak_pkey" PRIMARY KEY ("ProviderBreakId"),
CONSTRAINT "FK_ProviderBreak_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "ProviderBreak_ConsultationTypeId_fkey" FOREIGN KEY ("ConsultationTypeId")
REFERENCES public."ConsultationType" ("ConsultationTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderBreak_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderBreak_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderBreak"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderBreak"."ProviderBreakId"
IS ' ';
----------
\ No newline at end of file
alter table "Location" add column "Active" boolean default true;
-----------------------------------
alter table "Location" add column "PracticeId" int references "Practice"("PracticeId");
--select * from "Practice" p order by 1 desc;
--update "Location" set "PracticeId" = 26
---------
alter table "Provider" drop column "PracticeLocationId";
alter table "ProviderLocation" drop column "PracticeLocationId";
alter table "ProviderLocation" add column "LocationId" int references "Location"("LocationId");
--select * from "Location" ;
--update "ProviderLocation" set "LocationId" = 2;
alter table "ProviderLocation" alter column "LocationId" set not null;
alter table "Location" add column "CountryId" int references "Country"("CountryId");
select * from "Country";
update "Location" set "CountryId" = 1;
alter table "Location" alter column "CountryId" set not null;
alter table "User" drop column "ProviderLocationId";
alter table "User" add column "ProviderLocationId" int references "ProviderLocation"("ProviderLocationId");
create table "ProviderMedicationGroup"(
"ProviderMedicationGroupId" serial primary key,
"TagName" text,
"SpecializationId" int references "Specialization"("SpecializationId") default null,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
CREATE TABLE "ProviderMedicationMaster" (
"ProviderMedicationMasterId" serial primary key,
"ProviderMedicationGroupId" int references "ProviderMedicationGroup"("ProviderMedicationGroupId"),
"PharmacyProductId" int4 NULL,
"Duration" int4 NOT NULL,
"DurationType" varchar(10) NOT NULL,
"IsMorning" bool NULL DEFAULT false,
"IsAfternoon" bool NULL DEFAULT false,
"IsNight" bool NULL DEFAULT false,
"MorningDosage" text NULL,
"AfternoonDosage" text NULL,
"NightDosage" text NULL,
"Dosage" int4 NOT NULL,
"Instruction" text NULL
);
create table "ProviderMedicationMap"(
"ProviderMedicationMapId" serial primary key,
"ProviderId" int references "Provider"("ProviderId"),
"Active" boolean default true,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
alter table "ProviderMedicationMap" add column "ProviderMedicationMasterId" int references "ProviderMedicationMaster"("ProviderMedicationMasterId");
create table "ProviderConsultationRoom"(
"ProviderConsultationRoomId" serial primary Key,
"ProviderId" int references "Provider" ("ProviderId"),
"RoomId" int references "Room"("RoomId"), "LocationId" int references "Location"("LocationId")
);
-------------
\ No newline at end of file
alter table "ObEncounter"
add column "AncCard" text
============================
alter table "ObEncounter"
add column "Covid" text
========================
alter table "ObEncounter" ADD "Measure" text;
alter table "ObEncounter" ADD "GeneralExamination" text;
alter table "ObEncounter" ADD "Breech" text;
\ No newline at end of file
Truncate table "WebNotification";
ALTER TABLE "WebNotification" ADD CONSTRAINT "WebNotification_Unq_ReferenceId_TypeId" UNIQUE ("ReferenceId","WebNotificationTypeId");
----------
Alter table "LabBookingDetail" add column if not exists "VerifiedByDoctorId" int references "Provider"("ProviderId");
alter table "LabBookingPackageDetail" add column if not exists "VerifiedByDoctorId" int references "Provider"("ProviderId");
-----------
ALTER TABLE "LabBookingDetail"
ADD "SampleCollectedBy" integer Null;
ALTER TABLE "LabBookingDetail"
ADD CONSTRAINT "FK_LabBookingDetail_SampleCollectedBy" FOREIGN KEY ("SampleCollectedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
---------------------------------
-- SCHEMA: mobile
-- DROP SCHEMA IF EXISTS mobile ;
CREATE SCHEMA IF NOT EXISTS mobile
AUTHORIZATION postgres;
\ No newline at end of file
-- ----------------------------
-- Table structure for ActionType
-- ----------------------------
CREATE SEQUENCE "mobile"."ActionType_Seq";
DROP TABLE IF EXISTS "mobile"."ActionType";
CREATE TABLE "mobile"."ActionType" (
"ActionTypeId" int4 NOT NULL DEFAULT nextval('"mobile"."ActionType_Seq"'::regclass),
"Name" varchar(255) COLLATE "pg_catalog"."default"
)
;
-- ----------------------------
-- Records of ActionType
-- ----------------------------
INSERT INTO "mobile"."ActionType" VALUES (1, 'QM_CheckIn');
INSERT INTO "mobile"."ActionType" VALUES (2, 'QM_Start');
INSERT INTO "mobile"."ActionType" VALUES (3, 'QM_Complete');
-- ----------------------------
-- Primary Key structure for table ActionType
-- ----------------------------
ALTER TABLE "mobile"."ActionType" ADD CONSTRAINT "ActionType_pkey" PRIMARY KEY ("ActionTypeId");
-- ----------------------------
-- Table structure for InformationLog
-- ----------------------------
CREATE SEQUENCE "mobile"."InformationLog_Seq";
DROP TABLE IF EXISTS "mobile"."InformationLog";
CREATE TABLE "mobile"."InformationLog" (
"InformationLogId" int4 NOT NULL DEFAULT nextval('"mobile"."InformationLog_Seq"'::regclass),
"Uuid" text COLLATE "pg_catalog"."default",
"ActionTypeId" int4,
"SupportId" int4,
"Message" text COLLATE "pg_catalog"."default",
"Date" timestamp(0) DEFAULT now(),
"SupportIdName" text COLLATE "pg_catalog"."default"
)
;
-- ----------------------------
-- Primary Key structure for table InformationLog
-- ----------------------------
ALTER TABLE "mobile"."InformationLog" ADD CONSTRAINT "InformationLog_pkey" PRIMARY KEY ("InformationLogId");
-- ----------------------------
-- Foreign Keys structure for table InformationLog
-- ----------------------------
ALTER TABLE "mobile"."InformationLog" ADD CONSTRAINT "FK_ActionTypeId" FOREIGN KEY ("ActionTypeId") REFERENCES "mobile"."ActionType" ("ActionTypeId") ON DELETE CASCADE ON UPDATE CASCADE;
INSERT INTO "public"."QueueStatus" ("QueueStatusId", "Name") VALUES (7, 'Not Started');
ALTER TABLE ONLY public."Appointment" ALTER COLUMN "QueueStatusId" SET DEFAULT 7;
ALTER TABLE public."Appointment"
ADD COLUMN "QueueStartDate" timestamp without time zone;
ALTER TABLE public."Appointment"
ADD COLUMN "QueueEndDate" timestamp without time zone;
UPDATE "Appointment" SET "QueueStatusId" = 7;
\ No newline at end of file
ALTER TABLE public."Appointment"
ADD COLUMN "WaitingCount" integer;
\ No newline at end of file
UPDATE "public"."QueueStatus" SET "Name" = 'In Room' WHERE "QueueStatusId" = 2;
ALTER TABLE public."Appointment"
ADD COLUMN "TokenNumber" integer NOT NULL DEFAULT 0;
\ No newline at end of file
insert into "QueueStatus" ("QueueStatusId","Name") VALUES (8,'Move to Queue')
\ 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"
ALTER TABLE "ReceiptAreaTypeId" RENAME TO "ReceiptAreaType";
------------------------------------------------------------
INSERT INTO public."ReceiptAreaType"("ReceiptAreaTypeId", "Name")
VALUES (12, 'AdmissionReceipt'),(13, 'AdmissionReceiptRefund');
\ No newline at end of file
-- Table: public.ReferralDoctor
-- DROP TABLE public."ReferralDoctor";
CREATE TABLE public."ReferralDoctor"
(
"ReferralDoctorId" integer NOT NULL DEFAULT nextval('"Referral_Doctor_Master_Seq"'::regclass),
"Salutation" character varying(10) COLLATE pg_catalog."default",
"FirstName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"LastName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Mobile" character varying(10) COLLATE pg_catalog."default",
"Email" text COLLATE pg_catalog."default",
"Active" boolean DEFAULT true,
"LocationId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "ReferralDoctor_pkey" PRIMARY KEY ("ReferralDoctorId"),
CONSTRAINT "ReferralDoctor_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ReferralDoctor_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ReferralDoctor_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE public."ReferralDoctor"
OWNER to postgres;
\ No newline at end of file
////////////////Alter query for Patient Table////////////////
ALTER TABLE "PatientReferredBy"
ADD "LocationId" integer,
ADD "CreatedBy" bigint NULL ,
ADD "CreatedDate" timestamp without time zone NULL ,
ADD "ModifiedBy" bigint,
ADD "ModifiedDate" timestamp without time zone
///////////////////////////////////////////////////////////////////
UPDATE public."PatientReferredBy"
SET "CreatedBy" =1029,
"CreatedDate"='2022-05-18 17:20:48.435787', "LocationId" =4
/////////////////////////////////////////////////////////////////////////
ALTER TABLE "PatientReferredBy" ALTER COLUMN "CreatedBy" SET NOT NULL;
ALTER TABLE "PatientReferredBy" ALTER COLUMN "CreatedDate" SET NOT NULL;
ALTER TABLE "PatientReferredBy" ALTER COLUMN "LocationId" SET NOT NULL;
\ No newline at end of file
-- FUNCTION: public.udf_Doctor_Revenue_location(integer, integer, timestamp without time zone, timestamp without time zone)
-- DROP FUNCTION IF EXISTS public."udf_Doctor_Revenue_location"(integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_Doctor_Revenue_location"(
providerid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("AccountId" integer, "DoctorName" text, "AppointmentCashTotal" numeric, "AppointmentCardTotal" numeric, "AppointmentAmount" numeric, "AdmissionCashTotal" numeric, "AdmissionCardTotal" numeric, "AdmissionAmount" numeric, "LabCash" numeric, "LabCard" numeric, "LabAmount" numeric, "PharmacySaleCash" numeric, "PharmacySaleCard" numeric, "PharmacyAmount" numeric, "TotalCash" numeric, "TotalCard" numeric, "Total" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."ProviderId",a."FullName" "DoctorName",ac."RoleId"
from "Provider" a
JOIN "Account" ac on ac."ReferenceId"=a."ProviderId" and ac."RoleId"=3
JOIN "LocationAccountMap" LAM on LAM."AccountId"=ac."AccountId"
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
)
,actappointmentamount as (
select a."ProviderId",sum(A."CashTotal") "AppointmentCashTotal",sum(A."CardTotal") "AppointmentCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") appointmentamount from (
select ap."ProviderId" "ProviderId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Active" =true
where
case when providerId is null then 1=1 else ap."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
AND A."ReceiptTypeId"=1
and A."Active"<>false and A."AppointmentId" is not null
and coalesce(A."IsRefunded",false) <>true and ap."Status" <> 'C' and
case when "fromDate" is null then 1=1
else (A."CreatedDate" >= "fromDate" and A."CreatedDate" <= "toDate") end )a
group by a."ProviderId"
)
,refundappointmentamount as (
select a."ProviderId" ,sum(A."CashTotal") "AppointmentRefCashTotal",sum(A."CardTotal") "AppointmentRefCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") refappointmentamount from (
select ap."ProviderId" "ProviderId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Status" <> 'C' and ap."Active" =true
where case when providerId is null then 1=1 else ap."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and A."Active"<>false and A."AppointmentId" is not null
and coalesce(A."IsRefunded",false) = true and
case when "fromDate" is null then 1=1
else (A."CreatedDate" >= "fromDate" and A."CreatedDate" <= "toDate") end ) a
group by a."ProviderId"
)
,appointmentamount as (
select A."ProviderId",
coalesce(A."AppointmentCashTotal",0) - coalesce(B."AppointmentRefCashTotal",0) as "AppointmentCashTotal" ,
coalesce(A."AppointmentCardTotal",0) - coalesce(B."AppointmentRefCardTotal",0) as "AppointmentCardTotal" ,
coalesce(A.appointmentamount,0) - coalesce(B.refappointmentamount,0) as "AppointmentAmount" from actappointmentamount A
left join refundappointmentamount B on A."ProviderId"=B."ProviderId"
)
,actadmissionamount as (
select a."ProviderId" , sum(A."CashTotal") "AdmissionCashTotal",sum(A."CardTotal") "AdmissionCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") "AdmissionAmount" from (
select ad."ProviderId" "ProviderId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when providerId is null then 1=1 else ad."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
and case when "fromDate" is null then 1=1
else (adr."CreatedDate" >= "fromDate" and adr."CreatedDate" <= "toDate") end )a
group by a."ProviderId"
)
,refadmissionamount as (
select a."ProviderId" , sum(A."CashTotal") "AdmissionRefCashTotal",sum(A."CardTotal") "AdmissionRefCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") "AdmissionRefAmount" from (
select ad."ProviderId" "ProviderId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when providerId is null then 1=1 else ad."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
and case when "fromDate" is null then 1=1
else (adr."CreatedDate" >= "fromDate" and adr."CreatedDate" <= "toDate") end )a
group by a."ProviderId"
)
,admissionamount as (
select A."ProviderId" ,
coalesce(A."AdmissionCashTotal",0) - coalesce(B."AdmissionRefCashTotal",0) "AdmissionCashTotal",
coalesce(A."AdmissionCardTotal",0) - coalesce(B."AdmissionRefCardTotal",0) "AdmissionCardTotal",
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A
left join refadmissionamount B on A."ProviderId"=B."ProviderId"
)
,LabAmount as (
select a."ProviderId",sum(a."Cash") "LabCash",sum(a."Card") "LabCard" ,sum(a."Cash")+sum(a."Card")"LabAmount" from(
select a."ProviderId",
case when "PaidVia"='Cash' then coalesce(ar."NetAmount",0) else 0 end "Cash"
,case when "PaidVia"<>'Cash' then coalesce(ar."NetAmount",0) else 0 end "Card"
from "Provider" a
join "LabBookingHeader" ar on trim(lower(ar."DoctorName")) = trim(lower(a."FullName")) and ar."Active" <> false
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
AND case when "fromDate" is null then 1=1
else (ar."CreatedDate" >= "fromDate" and ar."CreatedDate" <= "toDate") end)a
group by a."ProviderId" )
,PharmaSaleAmount as (
select a."ProviderId", sum(a."Cash") "PharmaSaleCash",sum(a."Card") "PharmaSaleCard" , sum(a."Cash")+ sum(a."Card")
"PharmaSaleAmount" from (
select a."ProviderId",
case when "PaidVia"='Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when "PaidVia"<>'Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Provider" a
join "PharmacySaleHeader" ar on ar."ProviderId"=a."ProviderId"
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."SaleDate" >= "fromDate" and ar."SaleDate" <= "toDate") end )a
group by a."ProviderId"
)
,PharmaReturnAmount as (
select a."ProviderId", sum(a."Cash") "PharmaReturnCash",sum(a."Card") "PharmaReturnCard" ,sum(a."Cash")+sum(a."Card") "PharmaReturnAmount" from(
select a."ProviderId", case when ar."PaidVia"='Cash' then coalesce(srh."OverallNetAmount",0) else 0 end "Cash"
,case when ar."PaidVia"='Card' then coalesce(srh."OverallNetAmount",0) else 0 end "Card"
from "Provider" a
join "PharmacySaleHeader" ar on ar."ProviderId"=a."ProviderId"
left join "SaleReturnHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (srh."ReturnDate" >= "fromDate" and srh."ReturnDate" <= "toDate") end )a
group by a."ProviderId"
)
,PharmaAmount as (
select a."ProviderId",
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."ProviderId"=b."ProviderId"
)
select distinct a."ProviderId",a."DoctorName"::text "DoctorName",
ap."AppointmentCashTotal",ap."AppointmentCardTotal",ap."AppointmentAmount",
ad."AdmissionCashTotal",ad."AdmissionCardTotal",ad."AdmissionAmount",
lb."LabCash", lb."LabCard",lb."LabAmount",
sum(pa."PharmaSaleCash") over(partition by a."ProviderId") "PharmacySaleCash",
sum(pa."PharmaSaleCard") over(partition by a."ProviderId") "PharmacySaleCard",
sum(pa."PharmaAmount") over(partition by a."ProviderId") "PharmacyAmount",
coalesce(ap."AppointmentCashTotal",0)+ coalesce(ad."AdmissionCashTotal",0)+coalesce(lb."LabCash",0)+coalesce(sum(pa."PharmaSaleCash") over(partition by a."ProviderId") ,0) "TotalCash",
coalesce(ap."AppointmentCardTotal",0)+ coalesce(ad."AdmissionCardTotal",0)+coalesce(lb."LabCard",0)+coalesce(sum(pa."PharmaSaleCard") over(partition by a."ProviderId"),0) "TotalCard",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(partition by a."ProviderId"),0) "Total"
from accountdata a
left join appointmentamount ap on ap."ProviderId"=a."ProviderId"
left join admissionamount ad on ad."ProviderId"=a."ProviderId"
left join LabAmount lb on lb."ProviderId"=a."ProviderId"
left join PharmaAmount pa on pa."ProviderId"=a."ProviderId"
;
end
$BODY$;
ALTER FUNCTION public."udf_Doctor_Revenue_location"(integer, integer, timestamp without time zone, timestamp without time zone)
OWNER TO postgres;
-- FUNCTION: public.udf_Employee_Revenue_Location(integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- DROP FUNCTION IF EXISTS public."udf_Employee_Revenue_Location"(integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_Employee_Revenue_Location"(
accountid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer,
roleid integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("AccountId" integer, "EmployeeName" text, "RoleName" character varying, "AppointmentCashTotal" numeric, "AppointmentCardTotal" numeric, "AppointmentAmount" numeric, "AdmissionCashTotal" numeric, "AdmissionCardTotal" numeric, "AdmissionAmount" numeric, "LabCash" numeric, "LabCard" numeric, "LabAmount" numeric, "PharmacySaleCash" numeric, "PharmacySaleCard" numeric, "PharmacyAmount" numeric, "TotalCash" numeric, "TotalCard" numeric, "Total" 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 "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" and rol."RoleName"<>'Patient'
where case when accountid is null then 1=1 else a."AccountId"=accountid end
and case when roleid is null then 1=1 else a."RoleId"=roleid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
)
,actappointmentamount as (
select a."AccountId",sum(A."CashTotal") "AppointmentCashTotal",sum(A."CardTotal") "AppointmentCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") appointmentamount from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end and A."ReceiptTypeId"=1
and A."Active"<>false and A."AppointmentId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) <>true and ap."Status" <> 'C' and
case when "fromDate" is null then 1=1
else (A."CreatedDate" >= "fromDate" and A."CreatedDate" <= "toDate") end )a
group by a."AccountId"
)
,refundappointmentamount as (
select a."AccountId" ,sum(A."CashTotal") "AppointmentRefCashTotal",sum(A."CardTotal") "AppointmentRefCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") refappointmentamount from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Status" <> 'C' and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end
and A."Active"<>false and A."AppointmentId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) = true and
case when "fromDate" is null then 1=1
else (A."CreatedDate" >= "fromDate" and A."CreatedDate" <= "toDate") end ) a
group by a."AccountId"
)
,appointmentamount as (
select A."AccountId",
coalesce(A."AppointmentCashTotal",0) - coalesce(B."AppointmentRefCashTotal",0) as "AppointmentCashTotal" ,
coalesce(A."AppointmentCardTotal",0) - coalesce(B."AppointmentRefCardTotal",0) as "AppointmentCardTotal" ,
coalesce(A.appointmentamount,0) - coalesce(B.refappointmentamount,0) as "AppointmentAmount" from actappointmentamount A
left join refundappointmentamount B on A."AccountId"=B."AccountId"
)
,actadmissionamount as (
select a."AccountId" , sum(A."CashTotal") "AdmissionCashTotal",sum(A."CardTotal") "AdmissionCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") "AdmissionAmount" from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate" >= "fromDate" and adr."CreatedDate" <= "toDate") end )a
group by a."AccountId"
)
,refadmissionamount as (
select a."AccountId" , sum(A."CashTotal") "AdmissionRefCashTotal",sum(A."CardTotal") "AdmissionRefCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") "AdmissionRefAmount" from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate" >= "fromDate" and adr."CreatedDate" <= "toDate") end )a
group by a."AccountId"
)
,admissionamount as (
select A."AccountId" ,
coalesce(A."AdmissionCashTotal",0) - coalesce(B."AdmissionRefCashTotal",0) "AdmissionCashTotal",
coalesce(A."AdmissionCardTotal",0) - coalesce(B."AdmissionRefCardTotal",0) "AdmissionCardTotal",
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A
left join refadmissionamount B on A."AccountId"=B."AccountId"
)
,LabAmount as (
select a."AccountId",sum(a."Cash") "LabCash",sum(a."Card") "LabCard" ,sum(a."Cash")+sum(a."Card")"LabAmount" from(
select a."AccountId",
case when "PaidVia"='Cash' then coalesce(ar."NetAmount",0) else 0 end "Cash"
,case when "PaidVia"<>'Cash' then coalesce(ar."NetAmount",0) else 0 end "Card"
from "Account" a
join "LabBookingHeader" ar on ar."CreatedBy" = a."AccountId" and ar."Active" <> false
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."CreatedDate" >= "fromDate" and ar."CreatedDate" <= "toDate") end)a
group by a."AccountId" )
,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 "PaidVia"='Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when "PaidVia"<>'Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."SaleDate" >= "fromDate" and ar."SaleDate" <= "toDate") 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."PaidVia"='Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PaidVia"='Card' then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when accountid is null then 1=1 else ar."CreatedBy"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."ReturnDate" >= "fromDate" and ar."ReturnDate" <= "toDate") 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 a."AccountId",a."EmployeeName",a."RoleName",
ap."AppointmentCashTotal",ap."AppointmentCardTotal",ap."AppointmentAmount",
ad."AdmissionCashTotal",ad."AdmissionCardTotal",ad."AdmissionAmount",
lb."LabCash", lb."LabCard",lb."LabAmount",
sum(pa."PharmaSaleCash") over(partition by a."AccountId") "PharmacySaleCash",
sum(pa."PharmaSaleCard") over(partition by a."AccountId") "PharmacySaleCard",
sum(pa."PharmaAmount") over(partition by a."AccountId") "PharmacyAmount",
coalesce(ap."AppointmentCashTotal",0)+ coalesce(ad."AdmissionCashTotal",0)+coalesce(lb."LabCash",0)+coalesce(sum(pa."PharmaSaleCash") over(partition by a."AccountId") ,0) "TotalCash",
coalesce(ap."AppointmentCardTotal",0)+ coalesce(ad."AdmissionCardTotal",0)+coalesce(lb."LabCard",0)+coalesce(sum(pa."PharmaSaleCard") over(partition by a."AccountId"),0) "TotalCard",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(partition by a."AccountId"),0) "Total"
from accountdata a
left join appointmentamount ap on ap."AccountId"=a."AccountId"
left join admissionamount ad on ad."AccountId"=a."AccountId"
left join LabAmount lb on lb."AccountId"=a."AccountId"
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."udf_Employee_Revenue_Location"(integer, integer, integer, timestamp without time zone, timestamp without time zone)
OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_fetch_Admissions_Locations(text, integer, integer[], integer[], date, integer, character varying, text, text, character varying, integer, date, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_uiReport_fetch_Admissions_Locations"(text, integer, integer[], integer[], date, integer, character varying, text, text, character varying, integer, date, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_uiReport_fetch_Admissions_Locations"(
"admissionNo" text DEFAULT NULL::text,
locationid integer DEFAULT NULL::integer,
"departmentId" integer[] DEFAULT NULL::integer[],
"providerId" integer[] DEFAULT NULL::integer[],
"fromDate" date DEFAULT NULL::date,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"referredBy" text DEFAULT NULL::text,
"referredByName" text DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"dischargeStatusId" integer DEFAULT NULL::integer,
"toDate" date DEFAULT NULL::date,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentName" text, "ProviderName" text, "AdmissionId" text, "AdmissionNo" text, "AdmissionDate" timestamp without time zone, "AdmissionTime" time without time zone, "PatientName" text, "ReferredBy" character varying, "ReferredByName" character varying, "UMRNo" character varying, "PatientMobile" character varying, "PatientAge" smallint, "PatientGender" character, "ProviderAge" smallint, "ProviderGender" character, "WardName" character varying, "RoomName" character varying, "BedNumber" character varying, "AttendantName" character varying, "AttendantRelationWithPatient" character varying, "AttendantContactNo" character varying, "IsDischarged" boolean, "DischargeDate" date, "DischargeTime" time without time zone, "DischargeStatus" character varying, "IsMaternity" boolean, "EncounterId" integer, "SurgeryName" character varying, "ProviderThumbnailUrl" text, "PatientThumbnailUrl" text, "TotalAdmission" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."DepartmentName"::text,'GrandTotal')"DepartmentName" ,A."ProviderName" "ProviderName",
coalesce(A."AdmissionId"::text,'Total'), A."AdmissionNo", A."AdmissionDate" , A."AdmissionTime",
A."PatientName" ,A."ReferredBy",A."ReferredByName",A."UMRNo",A."Mobile" as "PatientMobile" , A."PatientAge" , A."PatientGender" ,
A."ProviderAge" , A."ProviderGender" , A."WardName" , A."RoomName" , A."BedNumber"
, A."AttendantName" , A."AttendantRelationWithPatient" , A."AttendantContactNo" , A."IsDischarged", A."DischargeDate" , A."DischargeTime"
, A."DischargeStatus", A."IsMaternity" , A."EncounterId" , A."SurgeryName" , A."ProviderThumbnailUrl" , A."PatientThumbnailUrl"
,Count(A."AdmissionNo") "TotalAddmissions"
from (
select A."AdmissionId",A."AdmissionNo",A."AdmissionDate",A."AdmissionTime",
Pa."FullName" "PatientName",Pa."ReferredBy",Pa."ReferredByName",Pa."UMRNo",pa."Mobile",Pa."Age" "PatientAge",Pa."Gender" as "PatientGender",Pr."Age" "ProviderAge",Pr."Gender" as "ProviderGender",
Pr."FullName"::text "ProviderName",D."DepartmentName"::text "DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName" "AttendantName",A."AttendantRelationWithPatient" "AttendantRelationWithPatient",A."AttendantContactNo" "AttendantContactNo"
,case when ds."DischargeId" is not null then true else false end as "IsDischarged",ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus"
,A."IsMaternity",A."EncounterId",st."SurgeryName",
(CASE WHEN pr."ThumbnailUrl" IS NOT NULL THEN CONCAT('{this.amazonS3Configuration.BucketURL}', pr."Guid", '/', pr."ThumbnailUrl") ELSE NULL END) AS "ProviderThumbnailUrl",
(CASE WHEN pa."ThumbnailUrl" IS NOT NULL THEN CONCAT('{this.amazonS3Configuration.BucketURL}', pa."Guid", '/', pa."ThumbnailUrl") ELSE NULL END) AS "PatientThumbnailUrl"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId"
left join "DischargeStatus" dss on dss."DischargeStatusId"=ds."DischargeStatusId"
where
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END AND
case when "departmentId" is null then 1=1 else A."DepartmentId" = any("departmentId") end and
case when "providerId" is null then 1=1 else A."ProviderId" = any("providerId") end and
case when "admissionNo" is null then 1=1 when "admissionNo" ='' then 1=1 else A."AdmissionNo" ilike'%'||"admissionNo" ||'%' end
and case when "patientId" is null then 1=1 else Pa."PatientId"="patientId" end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike'%'||"uMRNo"||'%' end and
case when "referredBy" is null then 1=1 when "referredBy" ='' then 1=1 else Pa."ReferredBy" ilike'%'||"referredBy" ||'%' end and
case when "referredByName" is null then 1=1 when "referredByName" ='' then 1=1 else Pa."ReferredByName" ilike'%'||"referredByName" ||'%' end and
case when "patientMobile" is null then 1=1 else Pa."Mobile" ilike'%'||"patientMobile"||'%' end and
case when "dischargeStatusId" is null then 1=1 else dss."DischargeStatusId"="dischargeStatusId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate"::date and A."AdmissionDate"::date <="toDate" end
) A
GROUP BY GROUPING SETS((A."AdmissionId" , A."AdmissionNo" , A."AdmissionDate" , A."AdmissionTime",
A."PatientName" ,A."ReferredBy",A."ReferredByName", A."PatientAge" , A."PatientGender" ,
A."ProviderAge" , A."ProviderGender" , A."ProviderName" , A."DepartmentName" , A."WardName" , A."RoomName" , A."BedNumber"
, A."AttendantName" , A."AttendantRelationWithPatient" , A."AttendantContactNo" , A."IsDischarged", A."DischargeDate" , A."DischargeTime"
, A."DischargeStatus", A."IsMaternity" , A."EncounterId" , A."SurgeryName" , A."ProviderThumbnailUrl" , A."PatientThumbnailUrl",A."UMRNo",A."Mobile" ), (A."DepartmentName",A."ProviderName"), ())
-- order by A."DepartmentName",A."ProviderName"
ORDER BY A."AdmissionNo"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Admissions_Locations"(text, integer, integer[], integer[], date, integer, character varying, text, text, character varying, integer, date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, text, text, text, text, date, date, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, text, date, date, 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,
"referredBy" text DEFAULT NULL::text,
"referredByName" text DEFAULT NULL::text,
mobile text DEFAULT NULL::text,
"paymentType" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "FollowUpForAppointmentId" integer, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "ReferredBy" 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, "TotalAppointments" bigint, "TotalAmount" bigint, "ReceiptCreatedByName" text, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" 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."FollowUpForAppointmentId",
A."AppointmentNo",A."PatientId" "PatientId",Pa."ReferredBy",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
A."PaymentType",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Amount")::bigint as "TotalAmount" ,
Pa."FatherOrHusband"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
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 "referredBy" is null then 1=1 when "referredBy" ='' then 1=1 else Pa."ReferredBy" ilike'%'||"referredBy" ||'%' 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 "paymentType" is null then 1=1 when "paymentType" ='' then 1=1 else A."PaymentType" ilike'%'||"paymentType"||'%' end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",Pa."ReferredBy"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
A."PaymentType",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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",
A."FollowUpForAppointmentId",A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else Pa."ReferredBy"::varchar end as "ReferredBy",
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."TotalAppointments",A."TotalAmount",
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"
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"
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, text, date, date, integer, integer)
OWNER TO postgres;
CREATE SEQUENCE "QueueStatus_QueueStatusId_seq";
-- ----------------------------
-- Table structure for QueueStatus
-- ----------------------------
DROP TABLE IF EXISTS "public"."QueueStatus";
CREATE TABLE "public"."QueueStatus" (
"QueueStatusId" int4 NOT NULL DEFAULT nextval('"QueueStatus_QueueStatusId_seq"'::regclass),
"Name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL
)
;
-- ----------------------------
-- Records of QueueStatus
-- ----------------------------
INSERT INTO "public"."QueueStatus" VALUES (2, 'In Progress');
INSERT INTO "public"."QueueStatus" VALUES (3, 'Next');
INSERT INTO "public"."QueueStatus" VALUES (4, 'Waiting');
INSERT INTO "public"."QueueStatus" VALUES (1, 'Calling');
INSERT INTO "public"."QueueStatus" VALUES (5, 'Completed');
INSERT INTO "public"."QueueStatus" VALUES (6, 'Not Attended');
-- ----------------------------
-- Primary Key structure for table QueueStatus
-- ----------------------------
ALTER TABLE "public"."QueueStatus" ADD CONSTRAINT "QueueStatus_pkey" PRIMARY KEY ("QueueStatusId");
CREATE TABLE IF NOT EXISTS "Settings"
(
"SettingsId" serial primary Key,
"Name" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Active" boolean default true
);
insert into "Settings"("Name") values ('Appointment Booked SMS') ;
insert into "Settings"("Name") values ('Appointment Cancelled SMS') ;
insert into "Settings" ("Name","Active","Type")values('Patient Validation',false,'Toggle Setting')
insert into "Settings" ("Name","Active","Type")values('IsPrintLogo',false,'Logo Setting')
ALTER TABLE "Floor" ADD COLUMN IF NOT EXISTS "LocationId" INT REFERENCES "Location"("LocationId");
UPDATE "Floor" SET "LocationId"=(Select "LocationId" from "Location" where "Name"='Parigi');
ALTER TABLE "Floor" ALTER COLUMN "LocationId" SET NOT NULL;
\ No newline at end of file
create sequence "TagDoctor_TagDoctorId_seq";
CREATE TABLE "TagDoctor"
(
"TagDoctorId" bigint NOT NULL DEFAULT nextval('"TagDoctor_TagDoctorId_seq"'::regclass),
"ProviderId" bigint not null ,
"Designation" character varying(255) ,
"DoctorUnitMasterId" bigint not null,
CONSTRAINT "TagDoctor_pkey" PRIMARY KEY ("TagDoctorId"),
CONSTRAINT "FK_TagDoctor_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_TagDoctor_DoctorUnitMasterId" FOREIGN KEY ("DoctorUnitMasterId")
REFERENCES public."DoctorUnitMaster" ("DoctorUnitMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
\ 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);
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,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "FollowUpForAppointmentId" integer, "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)
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."FollowUpForAppointmentId",
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"
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
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 "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
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",PRB."Name"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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",
A."FollowUpForAppointmentId",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"
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
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer, integer)
-- OWNER TO postgres;
alter table "Appointment" add column "IsEncounter" BOOLEAN;
UPDATE "Appointment" SET "IsEncounter" = true WHERE "QueueStatusId" = 5;
\ No newline at end of file
-- FUNCTION: public.udf_doctor_new_revenue(integer, integer, date, date)
-- DROP FUNCTION public.udf_doctor_new_revenue(integer, integer, date, date);
CREATE OR REPLACE FUNCTION public.udf_doctor_new_revenue(
providerid integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date)
RETURNS TABLE("AccountId" integer, "DoctorName" text, "AppointmentCashTotal" numeric, "AppointmentCardTotal" numeric, "AppointmentUPITotal" numeric, "AppointmentOnlineTotal" numeric, "AppointmentChequeTotal" numeric, "AppointmentPaytmTotal" numeric, "AppointmentAmount" numeric, "AdmissionCashTotal" numeric, "AdmissionCardTotal" numeric, "AdmissionUPITotal" numeric, "AdmissionOnlineTotal" numeric, "AdmissionChequeTotal" numeric, "AdmissionPaytmTotal" numeric, "AdmissionAmount" numeric, "LabCash" numeric, "LabCard" numeric, "LabUPI" numeric, "LabOnline" numeric, "LabCheque" numeric, "LabPaytm" numeric, "LabAmount" numeric, "PharmacySaleCash" numeric, "PharmacySaleCard" numeric, "PharmacySaleUPI" numeric, "PharmacySaleOnline" numeric, "PharmacySaleCheque" numeric, "PharmacySalePaytm" numeric, "PharmacyAmount" numeric, "TotalCash" numeric, "TotalCard" numeric, "TotalUPI" numeric, "TotalOnline" numeric, "TotalCheque" numeric, "TotalPaytm" numeric, "Total" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select P."ProviderId",P."FullName" "DoctorName"
from "Provider" P
join "ProviderLocation" PL on PL."ProviderId"=P."ProviderId"
where case when providerId is null then 1=1 else P."ProviderId"=providerId end
and case when "locationId" is null then 1=1 else PL."LocationId"= "locationId" end
)
,actappointmentamount as (
select a."ProviderId",sum(A."CashTotal") "AppointmentCashTotal",sum(A."CardTotal") "AppointmentCardTotal",
sum(A."UPITotal") "AppointmentUPITotal",sum(A."OnlineTotal") "AppointmentOnlineTotal",
sum(A."ChequeTotal") "AppointmentChequeTotal",sum(A."PaytmTotal") "AppointmentPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") appointmentamount
from (
select ap."ProviderId" "ProviderId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal" ,
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Active" =true
where
case when providerId is null then 1=1 else ap."ProviderId"=providerId end and
A."ReceiptTypeId"=1
and A."Active"<>false and A."AppointmentId" is not null
and coalesce(A."IsRefunded",false) <>true and ap."Status" <> 'C'
and case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
)a
group by a."ProviderId"
)
,refundappointmentamount as (
select a."ProviderId" ,
sum(A."CashTotal") "AppointmentRefCashTotal",sum(A."CardTotal") "AppointmentRefCardTotal",
sum(A."UPITotal") "AppointmentRefUPITotal",sum(A."OnlineTotal") "AppointmentRefOnlineTotal",
sum(A."ChequeTotal") "AppointmentRefChequeTotal",sum(A."PaytmTotal") "AppointmentRefPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") refappointmentamount
from (
select ap."ProviderId" "ProviderId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal",
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Status" <> 'C' and ap."Active" =true
where case when providerId is null then 1=1 else ap."ProviderId"=providerId end
and A."Active"<>false and A."AppointmentId" is not null
and coalesce(A."IsRefunded",false) = true
and case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
) a
group by a."ProviderId"
)
,appointmentamount as (
select A."ProviderId",
coalesce(A."AppointmentCashTotal",0) - coalesce(B."AppointmentRefCashTotal",0) as "AppointmentCashTotal" ,
coalesce(A."AppointmentCardTotal",0) - coalesce(B."AppointmentRefCardTotal",0) as "AppointmentCardTotal" ,
coalesce(A."AppointmentUPITotal",0) - coalesce(B."AppointmentRefUPITotal",0) as "AppointmentUPITotal" ,
coalesce(A."AppointmentOnlineTotal",0) - coalesce(B."AppointmentRefOnlineTotal",0) as "AppointmentOnlineTotal" ,
coalesce(A."AppointmentChequeTotal",0) - coalesce(B."AppointmentRefChequeTotal",0) as "AppointmentChequeTotal" ,
coalesce(A."AppointmentPaytmTotal",0) - coalesce(B."AppointmentRefPaytmTotal",0) as "AppointmentPaytmTotal" ,
coalesce(A.appointmentamount,0) - coalesce(B.refappointmentamount,0) as "AppointmentAmount"
from actappointmentamount A
left join refundappointmentamount B on A."ProviderId"=B."ProviderId"
)
,
actadmissionamount as (
select a."ProviderId" , sum(A."CashTotal") "AdmissionCashTotal",sum(A."CardTotal") "AdmissionCardTotal",
sum(A."UPITotal") "AdmissionUPITotal",sum(A."OnlineTotal") "AdmissionOnlineTotal",
sum(A."ChequeTotal") "AdmissionChequeTotal",sum(A."PaytmTotal") "AdmissionPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") "AdmissionAmount"
from (
select ad."ProviderId" "ProviderId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal",
case when adr."PayTypeId"=3 then coalesce(adr."Cost",0) else 0 end "UPITotal" ,
case when adr."PayTypeId"=4 then coalesce(adr."Cost",0) else 0 end "OnlineTotal",
case when adr."PayTypeId"=5 then coalesce(adr."Cost",0) else 0 end "ChequeTotal" ,
case when adr."PayTypeId"=6 then coalesce(adr."Cost",0) else 0 end "PaytmTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when providerId is null then 1=1 else ad."ProviderId"=providerId end and
adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
and case when "fromDate" is null then 1=1
else (adr."CreatedDate"::date >= "fromDate" and adr."CreatedDate"::date <= "toDate") end
)a
group by a."ProviderId"
)
,refadmissionamount as (
select a."ProviderId" , sum(A."CashTotal") "AdmissionRefCashTotal",sum(A."CardTotal") "AdmissionRefCardTotal",
sum(A."UPITotal") "AdmissionRefUPITotal",sum(A."OnlineTotal") "AdmissionRefOnlineTotal",
sum(A."ChequeTotal") "AdmissionRefChequeTotal",sum(A."PaytmTotal") "AdmissionRefPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal") + sum(A."ChequeTotal")+ sum(A."PaytmTotal") "AdmissionRefAmount"
from (
select ad."ProviderId" "ProviderId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal" ,
case when adr."PayTypeId"=3 then coalesce(adr."Cost",0) else 0 end "UPITotal" ,
case when adr."PayTypeId"=4 then coalesce(adr."Cost",0) else 0 end "OnlineTotal" ,
case when adr."PayTypeId"=5 then coalesce(adr."Cost",0) else 0 end "ChequeTotal" ,
case when adr."PayTypeId"=6 then coalesce(adr."Cost",0) else 0 end "PaytmTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when providerId is null then 1=1 else ad."ProviderId"=providerId end and
adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
and case when "fromDate" is null then 1=1
else (adr."CreatedDate"::date >= "fromDate" and adr."CreatedDate"::date <= "toDate") end
)a
group by a."ProviderId"
)
,admissionamount as (
select A."ProviderId" ,
coalesce(A."AdmissionCashTotal",0) - coalesce(B."AdmissionRefCashTotal",0) "AdmissionCashTotal",
coalesce(A."AdmissionCardTotal",0) - coalesce(B."AdmissionRefCardTotal",0) "AdmissionCardTotal",
coalesce(A."AdmissionUPITotal",0) - coalesce(B."AdmissionRefUPITotal",0) "AdmissionUPITotal",
coalesce(A."AdmissionOnlineTotal",0) - coalesce(B."AdmissionRefOnlineTotal",0) "AdmissionOnlineTotal",
coalesce(A."AdmissionChequeTotal",0) - coalesce(B."AdmissionRefChequeTotal",0) "AdmissionChequeTotal",
coalesce(A."AdmissionPaytmTotal",0) - coalesce(B."AdmissionRefPaytmTotal",0) "AdmissionPaytmTotal",
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A
left join refadmissionamount B on A."ProviderId"=B."ProviderId"
)
,LabAmount as (
select a."ProviderId",sum(a."Cash") "LabCash",sum(a."Card") "LabCard" ,
sum(a."UPI") "LabUPI",sum(a."Online") "LabOnline" ,
sum(a."Cheque") "LabCheque",sum(a."Paytm") "LabPaytm" ,
sum(a."Cash")+sum(a."Card") +sum(a."UPI")+sum(a."Online")+sum(a."Cheque")+sum(a."Paytm")"LabAmount"
from(
select a."ProviderId",
case when ar."PayTypeId"=1 then coalesce(ar."NetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(ar."NetAmount",0) else 0 end "Card"
,case when ar."PayTypeId"=3 then coalesce(ar."NetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(ar."NetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(ar."NetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(ar."NetAmount",0) else 0 end "Paytm"
from "Provider" a
join "LabBookingHeader" ar on trim(lower(ar."DoctorName")) = trim(lower(a."FullName")) and ar."Active" <> false
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
and case when "fromDate" is null then 1=1
else (ar."CreatedDate"::date >= "fromDate" and ar."CreatedDate"::date <= "toDate") end
)a
group by a."ProviderId" )
, PharmaSaleAmount as (
select a."ProviderId", 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."ProviderId",
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"
,case when ar."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Provider" a
join "PharmacySaleHeader" ar on ar."ProviderId"=a."ProviderId"
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
and case when "fromDate" is null then 1=1
else (ar."SaleDate"::date >= "fromDate" and ar."SaleDate"::date <= "toDate") end
)a
group by a."ProviderId"
)
,PharmaReturnAmount as (
select a."ProviderId", 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."ProviderId",
case when ar."PayTypeId"=1 then coalesce(srh."OverallNetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(srh."OverallNetAmount",0) else 0 end "Card"
,case when ar."PayTypeId"=3 then coalesce(srh."OverallNetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(srh."OverallNetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(srh."OverallNetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(srh."OverallNetAmount",0) else 0 end "Paytm"
from "Provider" a
join "PharmacySaleHeader" ar on ar."ProviderId"=a."ProviderId"
left join "SaleReturnHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when providerId is null then 1=1 else a."ProviderId"=providerId end
and case when "fromDate" is null then 1=1
else (srh."ReturnDate"::date >= "fromDate" and srh."ReturnDate"::date <= "toDate") end
)a
group by a."ProviderId"
)
,PharmaAmount as (
select a."ProviderId",
coalesce(a."PharmaSaleCash",0) - coalesce(b. "PharmaReturnCash",0) as "PharmaSaleCash" ,
coalesce(a."PharmaSaleCard",0) - coalesce(b. "PharmaReturnCard",0) as "PharmaSaleCard" ,
coalesce(a."PharmaSaleUPI",0) - coalesce(b. "PharmaReturnUPI",0) as "PharmaSaleUPI" ,
coalesce(a."PharmaSaleOnline",0) - coalesce(b. "PharmaReturnOnline",0) as "PharmaSaleOnline" ,
coalesce(a."PharmaSaleCheque",0) - coalesce(b. "PharmaReturnCheque",0) as "PharmaSaleCheque" ,
coalesce(a."PharmaSalePaytm",0) - coalesce(b. "PharmaReturnPaytm",0) as "PharmaSalePaytm" ,
coalesce(a."PharmaSaleAmount",0) - coalesce(b. "PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."ProviderId"=b."ProviderId"
)
select distinct a."ProviderId",a."DoctorName"::text "DoctorName",
ap."AppointmentCashTotal",ap."AppointmentCardTotal",ap."AppointmentUPITotal",ap."AppointmentOnlineTotal", ap."AppointmentChequeTotal",ap."AppointmentPaytmTotal", ap."AppointmentAmount",
ad."AdmissionCashTotal",ad."AdmissionCardTotal",ad."AdmissionUPITotal",ad."AdmissionOnlineTotal", ad."AdmissionChequeTotal",ad."AdmissionPaytmTotal", ad."AdmissionAmount",
lb."LabCash", lb."LabCard",lb."LabUPI", lb."LabOnline",lb."LabCheque", lb."LabPaytm",lb."LabAmount",
sum(pa."PharmaSaleCash") over(partition by a."ProviderId") "PharmacySaleCash",
sum(pa."PharmaSaleCard") over(partition by a."ProviderId") "PharmacySaleCard",
sum(pa."PharmaSaleUPI") over(partition by a."ProviderId") "PharmacySaleUPI",
sum(pa."PharmaSaleOnline") over(partition by a."ProviderId") "PharmacySaleOnline",
sum(pa."PharmaSaleCheque") over(partition by a."ProviderId") "PharmacySaleCheque",
sum(pa."PharmaSalePaytm") over(partition by a."ProviderId") "PharmacySalePaytm",
sum(pa."PharmaAmount") over(partition by a."ProviderId") "PharmacyAmount",
coalesce(ap."AppointmentCashTotal",0)+ coalesce(ad."AdmissionCashTotal",0)+coalesce(lb."LabCash",0)+coalesce(sum(pa."PharmaSaleCash") over(partition by a."ProviderId") ,0) "TotalCash",
coalesce(ap."AppointmentCardTotal",0)+ coalesce(ad."AdmissionCardTotal",0)+coalesce(lb."LabCard",0)+coalesce(sum(pa."PharmaSaleCard") over(partition by a."ProviderId"),0) "TotalCard",
coalesce(ap."AppointmentUPITotal",0)+ coalesce(ad."AdmissionUPITotal",0)+coalesce(lb."LabUPI",0)+coalesce(sum(pa."PharmaSaleUPI") over(partition by a."ProviderId") ,0) "TotalUPI",
coalesce(ap."AppointmentOnlineTotal",0)+ coalesce(ad."AdmissionOnlineTotal",0)+coalesce(lb."LabOnline",0)+coalesce(sum(pa."PharmaSaleOnline") over(partition by a."ProviderId"),0) "TotalOnline",
coalesce(ap."AppointmentChequeTotal",0)+ coalesce(ad."AdmissionChequeTotal",0)+coalesce(lb."LabCheque",0)+coalesce(sum(pa."PharmaSaleCheque") over(partition by a."ProviderId") ,0) "TotalCheque",
coalesce(ap."AppointmentPaytmTotal",0)+ coalesce(ad."AdmissionPaytmTotal",0)+coalesce(lb."LabPaytm",0)+coalesce(sum(pa."PharmaSalePaytm") over(partition by a."ProviderId"),0) "TotalPaytm",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)+coalesce(sum(pa."PharmaAmount") over(partition by a."ProviderId"),0) "Total"
from accountdata a
left join appointmentamount ap on ap."ProviderId"=a."ProviderId"
left join admissionamount ad on ad."ProviderId"=a."ProviderId"
left join LabAmount lb on lb."ProviderId"=a."ProviderId"
left join PharmaAmount pa on pa."ProviderId"=a."ProviderId"
;
end
$BODY$;
--ALTER FUNCTION public.udf_doctor_new_revenue(integer, integer, date, date)
-- OWNER TO postgres;
-- FUNCTION: public.udf_pharmacypatientbills_finalreport(text, integer, integer, character varying, character varying, integer, integer, integer, date, date, text, integer, text, boolean)
-- DROP FUNCTION public.udf_pharmacypatientbills_finalreport(text, integer, integer, character varying, character varying, integer, integer, integer, date, date, text, integer, text, boolean);
CREATE OR REPLACE FUNCTION public.udf_pharmacypatientbills_finalreport(
"billNumber" text DEFAULT NULL::text,
"accountId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text,
"pharmacyBillType" boolean DEFAULT NULL::boolean)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying, "PaidVia" character varying, "PaymentNumber" character varying, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "ProviderName" character varying, "CreatedByName" text, "RoleName" character varying, "TotalAmount" numeric, "SaleReturnHeaderId" integer, "OverallTaxes" numeric, "RetailName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."PaidVia",PH."PaymentNumber",PH."SaleDate" "SaleDate",PH."PatientName",
PH."Mobile" ,Ph."UMRNo",PH."ProviderName",ph."CreatedByName",
ph."Role", PH."OverallNetAmount",PH."SaleReturnHeaderId" ,PH."OverallTaxes",PH."RetailName"
from
(
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",PH."CreatedDate" "SaleDate",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",PH."ProviderName",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."OverallNetAmount",true "PharmacyBillType",null "SaleReturnHeaderId",PH."OverallTaxes",
RP."RetailName"
from "PharmacySaleHeader" PH
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "accountId" is null then 1=1 else PH."CreatedBy"="accountId" end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" = "providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else "fromDate"<= PH."SaleDate"::date end and
case when "toDate" is null then 1=1 else PH."SaleDate"::date<= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName", PH."PaymentNumber",PH."SaleDate", PH."OverallNetAmount",
PH."PatientName",PH."ProviderName",Pa."UMRNo",A."FullName"
,R."RoleName",RP."RetailName"
union
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",srh."ReturnDate" "SaleDate",PH."PatientName",
Ph."Mobile" ,Pa."UMRNo",PH."ProviderName",A."FullName"
"CreatedByName",R."RoleName" "Role", -srh."OverallNetAmount" "TotalAmount",false "PharmacyBillType"
,srh."SaleReturnHeaderId",srh."OverallTaxes",
RP."RetailName"
from "SaleReturnHeader" srh
Join "PharmacySaleHeader" ph on ph."PharmacySaleHeaderId"= srh."PharmacySaleHeaderId"
join "Account" A on A."AccountId"=srh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "accountId" is null then 1=1 else srh."CreatedBy"="accountId" end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" = "providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else srh."ReturnDate"::date >= "fromDate" end and
case when "toDate" is null then 1=1 else srh."ReturnDate"::date <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else ph."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PT."PayTypeName", PH."PaymentNumber",srh."ReturnDate", srh."OverallNetAmount",
PH."PatientName",Pa."Mobile",Pa."UMRNo",PH."ProviderName",A."FullName"
,R."RoleName",srh."SaleReturnHeaderId", RP."RetailName"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."SaleDate" desc, PH."PharmacySaleHeaderId";
END
$BODY$;
--ALTER FUNCTION public.udf_pharmacypatientbills_finalreport(text, integer, integer, character varying, character varying, integer, integer, integer, date, date, text, integer, text, boolean)
-- OWNER TO postgres;
-- 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 IF EXISTS 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, "FirstName" character varying, "MiddleName" character varying, "LastName" 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."FirstName"::varchar end as "FirstName",
case when A."AppointmentNo" is null then null else Pa."MiddleName"::varchar end as "MiddleName",
case when A."AppointmentNo" is null then null else Pa."LastName"::varchar end as "LastName",
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."RespectiveId"=A."AppointmentId" and R."ReceiptAreaTypeId"=4
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;
-- FUNCTION: public.udf_uiReport_Receipts_Admissions_Location(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
--
DROP FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(
"accountId" integer[] DEFAULT NULL::integer[],
"providerId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"roleId" integer[] DEFAULT NULL::integer[],
"admissionNo" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"receiptId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("ReceiptCreatedBy" text, "RoleName" character varying,
"ReceiptDate" timestamp without time zone, "ReceiptId" text, "AdmissionNo" text,
"AdmissionDate" date, "AdmissionTime" text, "PatientName" text,
"UMRNo" character varying, "PatientMobile" character varying,
"ProviderName" character varying, "PayTypeName" character varying,"PaymentDetails" character varying,
"PaidAmount" numeric, "RefundAmount" numeric, "BalanceAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."FullName",'GrandTotal') "ReceiptCreatedBy",A."RoleName",A."CreatedDate"
"ReceiptDate",coalesce(A."ReceiptId"::text,'Total')"ReceiptId"
,A."AdmissionNo",A."AdmissionDate"::date as "AdmissionDate",to_char(A."AdmissionDate" , 'HH12:MI PM' ) "AdmissionTime",
A."PatientName" "PatientName" ,A."UMRNo",A."Mobile" , A."ProviderName" "ProviderName",
A."PayTypeName",A."PaymentDetails",sum(A."PaidAmount") "PaidAmount",sum(A."RefundAmount") "RefundAmount"
,sum(A."PaidAmount")-sum(A."RefundAmount") "BalanceAmount"
from (
select R."ReceiptId",A."FullName",Rl."RoleName",R."CreatedDate" "CreatedDate",
coalesce(case when "ReceiptTypeId"=1 then R."Cost" end,0) as "PaidAmount" ,
coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount" ,Ad."AdmissionNo",ad."AdmissionDate",
ad."AdmissionTime",Ad."LocationId",
pa."FullName" "PatientName",pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",
pt."PayTypeName",R."PaymentDetails"
from "Receipt" R
join "Admission" ad on Ad."AdmissionId"=R."AdmissionId" and ad."Active" is not false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
join "Patient" pa on Ad."PatientId"=pa."PatientId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" pt on pt."PayTypeId"=R."PayTypeId"
where R."Active" is not false and
case when "accountId" is null then 1=1 else R."CreatedBy" = any("accountId") end
and case when "providerId" is null then 1=1 else pr."ProviderId" = "providerId" end
and case when "locationId" is null then 1=1 else Ad."LocationId" = "locationId" end
and case when "roleId" is null then 1=1 else A."RoleId" = any("roleId") end
and case when "admissionNo" is null then 1=1 else Ad."AdmissionNo" ilike'%'|| "admissionNo"||'%' end
and case when "patientId" is null then 1=1 else pa."PatientId" = "patientId" end
and case when "uMRNo" is null then 1=1 else pa."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pa."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "receiptId" is null then 1=1 else R."ReceiptId" = "receiptId" end
and case when "createdBy" is null then 1=1 else R."CreatedBy" = "createdBy" end
and
case when "payTypeId" is null then 1=1 else R."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=R."CreatedDate" and R."CreatedDate" <="toDate" end
) A
GROUP BY GROUPING SETS((A."ReceiptId",A."RoleName",A."FullName",A."CreatedDate",A."PayTypeName",A."PaymentDetails",A."AdmissionNo",
A."AdmissionDate",A."AdmissionTime",A."PatientName",A."UMRNo",A."Mobile",A."ProviderName" ), (A."FullName",
A."CreatedDate"), ())
order by A."FullName"
;
END-- FUNCTION: public.udf_uiReport_Receipts_Admissions_Location(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
--
DROP FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(
"accountId" integer[] DEFAULT NULL::integer[],
"providerId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"roleId" integer[] DEFAULT NULL::integer[],
"admissionNo" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"receiptId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("ReceiptCreatedBy" text, "RoleName" character varying,
"ReceiptDate" timestamp without time zone, "ReceiptId" text, "AdmissionNo" text,
"AdmissionDate" date, "AdmissionTime" text, "PatientName" text,
"UMRNo" character varying, "PatientMobile" character varying,
"ProviderName" character varying, "PayTypeName" character varying,"PaymentDetails" character varying,
"PaidAmount" numeric, "RefundAmount" numeric, "BalanceAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."FullName",'GrandTotal') "ReceiptCreatedBy",A."RoleName",A."CreatedDate"
"ReceiptDate",coalesce(A."ReceiptId"::text,'Total')"ReceiptId"
,A."AdmissionNo",A."AdmissionDate"::date as "AdmissionDate",to_char(A."AdmissionDate" , 'HH12:MI PM' ) "AdmissionTime",
A."PatientName" "PatientName" ,A."UMRNo",A."Mobile" , A."ProviderName" "ProviderName",
A."PayTypeName",A."PaymentDetails",sum(A."PaidAmount") "PaidAmount",sum(A."RefundAmount") "RefundAmount"
,sum(A."PaidAmount")-sum(A."RefundAmount") "BalanceAmount"
from (
select R."ReceiptId",A."FullName",Rl."RoleName",R."CreatedDate" "CreatedDate",
coalesce(case when "ReceiptTypeId"=1 then R."Cost" end,0) as "PaidAmount" ,
coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount" ,Ad."AdmissionNo",ad."AdmissionDate",
ad."AdmissionTime",Ad."LocationId",
pa."FullName" "PatientName",pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",
pt."PayTypeName",R."PaymentDetails"
from "Receipt" R
join "Admission" ad on Ad."AdmissionId"=R."AdmissionId" and ad."Active" is not false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
join "Patient" pa on Ad."PatientId"=pa."PatientId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" pt on pt."PayTypeId"=R."PayTypeId"
where R."Active" is not false and
case when "accountId" is null then 1=1 else R."CreatedBy" = any("accountId") end
and case when "providerId" is null then 1=1 else pr."ProviderId" = "providerId" end
and case when "locationId" is null then 1=1 else Ad."LocationId" = "locationId" end
and case when "roleId" is null then 1=1 else A."RoleId" = any("roleId") end
and case when "admissionNo" is null then 1=1 else Ad."AdmissionNo" ilike'%'|| "admissionNo"||'%' end
and case when "patientId" is null then 1=1 else pa."PatientId" = "patientId" end
and case when "uMRNo" is null then 1=1 else pa."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pa."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "receiptId" is null then 1=1 else R."ReceiptId" = "receiptId" end
and case when "createdBy" is null then 1=1 else R."CreatedBy" = "createdBy" end
and
case when "payTypeId" is null then 1=1 else R."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=R."CreatedDate" and R."CreatedDate" <="toDate" end
) A
GROUP BY GROUPING SETS((A."ReceiptId",A."RoleName",A."FullName",A."CreatedDate",A."PayTypeName",A."PaymentDetails",A."AdmissionNo",
A."AdmissionDate",A."AdmissionTime",A."PatientName",A."UMRNo",A."Mobile",A."ProviderName" ), (A."FullName",
A."CreatedDate"), ())
order by A."FullName"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- OWNER TO postgres;
$BODY$;
--ALTER FUNCTION public."udf_uiReport_Receipts_Admissions_Location"(integer[], integer, integer, integer[], text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_Receipts_Appointments_Location(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
--
DROP FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(
"accountId" integer[] DEFAULT NULL::integer[],
"providerId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"roleId" integer[] DEFAULT NULL::integer[],
"appointmentNo" character varying DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"receiptId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("ReceiptCreatedBy" text, "RoleName" character varying, "ReceiptDate" timestamp without time zone, "ReceiptId" text, "AppointmentNo" character varying, "FollowUpForAppointmentId" integer, "AppointmentDate" date, "AppointmentTime" text, "PatientName" text, "UMRNo" character varying, "PatientMobile" character varying, "ProviderName" character varying, "PaymentType" character varying, "PayTypeName" character varying, "PaymentDetails" character varying, "PaidAmount" numeric, "RefundAmount" numeric, "BalanceAmount" numeric, "AppointmentId" integer, "IsAppointmentReceipt" boolean)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."FullName",'GrandTotal') "ReceiptCreatedBy",A."RoleName",A."CreatedDate" "ReceiptDate",
coalesce(A."ReceiptId"::text,'Total')"ReceiptId"
,A."AppointmentNo",A."FollowUpForAppointmentId",A."AppointmentDate"::date as "AppointmentDate", to_char(
A."AppointmentTime" , 'HH12:MI PM' ) "AppointmentTime",
A."PatientName" "PatientName",A."UMRNo",A."Mobile", A."ProviderName" as "ProviderName",A."PaymentType"
,A."PayTypeName",A."PaymentDetails",sum(A."PaidAmount") "PaidAmount",sum(A."RefundAmount") "RefundAmount"
,sum(A."PaidAmount")-sum(A."RefundAmount") "BalanceAmount",A."AppointmentId",A."IsAppointmentReceipt"
from (
select R."ReceiptId",A."FullName",Rl."RoleName",R."CreatedDate" "CreatedDate",
coalesce(case when "ReceiptTypeId"=1 then R."Cost" end,0) as "PaidAmount" ,
coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount" ,Ad."FollowUpForAppointmentId",
Ad."AppointmentDate",Ad."AppointmentNo", Ad."AppointmentTime",Ad."LocationId",
pa."FullName" "PatientName",Pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",Ad."PaymentType",
pt."PayTypeName",ad."PaymentNumber" as "PaymentDetails" , R."AppointmentId",R."IsAppointmentReceipt"
from "Receipt" R
join "Appointment" ad on Ad."AppointmentId"=R."AppointmentId" and ad."Status" <> 'C' and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
join "Patient" pa on Ad."PatientId"=pa."PatientId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" pt on pt."PayTypeId"=R."PayTypeId"
where R."Active" <> false and
case when "accountId" is null then 1=1 else R."CreatedBy" = any("accountId") end
and case when "providerId" is null then 1=1 else pr."ProviderId" = "providerId" end
and case when "locationId" is null then 1=1 else Ad."LocationId" = "locationId" end
and case when "roleId" is null then 1=1 else A."RoleId" = any("roleId") end and
case when "appointmentNo" is null then 1=1 else Ad."AppointmentNo" ilike '%' || "appointmentNo" ||'%' end and
case when "patientId" is null then 1=1 else pa."PatientId" = "patientId" end
and case when "uMRNo" is null then 1=1 else pa."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pa."Mobile" ilike'%'|| "patientMobile"||'%' end
and
case when "receiptId" is null then 1=1 else R."ReceiptId" = "receiptId" end
and
case when "createdBy" is null then 1=1 else R."CreatedBy" = "createdBy" end
and
case when "payTypeId" is null then 1=1 else pt."PayTypeId" = "payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=R."CreatedDate" and R."CreatedDate" <="toDate" and R."Active" is not false end
) A
GROUP BY GROUPING SETS((A."ReceiptId",A."RoleName",A."FullName",A."CreatedDate",A."PaymentType",A."PayTypeName",A."PaymentDetails"
,A."FollowUpForAppointmentId",A."AppointmentDate",A."AppointmentNo"
,A."AppointmentTime",A."PatientName",A."UMRNo",A."Mobile",A."ProviderName",A."AppointmentId",
A."IsAppointmentReceipt"), (A."FullName"), ())
order by A."FullName"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_Receipts_Appointments_Location(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
--
DROP FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(
"accountId" integer[] DEFAULT NULL::integer[],
"providerId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer,
"roleId" integer[] DEFAULT NULL::integer[],
"appointmentNo" character varying DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"uMRNo" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"receiptId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("ReceiptCreatedBy" text, "RoleName" character varying,
"ReceiptDate" timestamp without time zone, "ReceiptId" text,
"AppointmentNo" character varying, "FollowUpForAppointmentId" integer,
"AppointmentDate" date, "AppointmentTime" text, "PatientName" text,
"UMRNo" character varying, "PatientMobile" character varying,
"ProviderName" character varying, "PaymentType" character varying,
"PayTypeName" character varying,"PaymentDetails" character varying, "PaidAmount" numeric, "RefundAmount" numeric,
"BalanceAmount" numeric, "AppointmentId" integer, "IsAppointmentReceipt" boolean)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select coalesce(A."FullName",'GrandTotal') "ReceiptCreatedBy",A."RoleName",A."CreatedDate" "ReceiptDate",
coalesce(A."ReceiptId"::text,'Total')"ReceiptId"
,A."AppointmentNo",A."FollowUpForAppointmentId",A."AppointmentDate"::date as "AppointmentDate", to_char(
A."AppointmentTime" , 'HH12:MI PM' ) "AppointmentTime",
A."PatientName" "PatientName",A."UMRNo",A."Mobile", A."ProviderName" as "ProviderName",A."PaymentType"
,A."PayTypeName",A."PaymentDetails",sum(A."PaidAmount") "PaidAmount",sum(A."RefundAmount") "RefundAmount"
,sum(A."PaidAmount")-sum(A."RefundAmount") "BalanceAmount",A."AppointmentId",A."IsAppointmentReceipt"
from (
select R."ReceiptId",A."FullName",Rl."RoleName",R."CreatedDate" "CreatedDate",
coalesce(case when "ReceiptTypeId"=1 then R."Cost" end,0) as "PaidAmount" ,
coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount" ,Ad."FollowUpForAppointmentId",
Ad."AppointmentDate",Ad."AppointmentNo", Ad."AppointmentTime",Ad."LocationId",
pa."FullName" "PatientName",Pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",Ad."PaymentType",
pt."PayTypeName",R."PaymentDetails" , R."AppointmentId",R."IsAppointmentReceipt"
from "Receipt" R
join "Appointment" ad on Ad."AppointmentId"=R."AppointmentId" and ad."Status" <> 'C' and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
join "Patient" pa on Ad."PatientId"=pa."PatientId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" pt on pt."PayTypeId"=R."PayTypeId"
where R."Active" <> false and
case when "accountId" is null then 1=1 else R."CreatedBy" = any("accountId") end
and case when "providerId" is null then 1=1 else pr."ProviderId" = "providerId" end
and case when "locationId" is null then 1=1 else Ad."LocationId" = "locationId" end
and case when "roleId" is null then 1=1 else A."RoleId" = any("roleId") end and
case when "appointmentNo" is null then 1=1 else Ad."AppointmentNo" ilike '%' || "appointmentNo" ||'%' end and
case when "patientId" is null then 1=1 else pa."PatientId" = "patientId" end
and case when "uMRNo" is null then 1=1 else pa."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pa."Mobile" ilike'%'|| "patientMobile"||'%' end
and
case when "receiptId" is null then 1=1 else R."ReceiptId" = "receiptId" end
and
case when "createdBy" is null then 1=1 else R."CreatedBy" = "createdBy" end
and
case when "payTypeId" is null then 1=1 else pt."PayTypeId" = "payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=R."CreatedDate" and R."CreatedDate" <="toDate" and R."Active" is not false end
) A
GROUP BY GROUPING SETS((A."ReceiptId",A."RoleName",A."FullName",A."CreatedDate",A."PaymentType",A."PayTypeName",A."PaymentDetails"
,A."FollowUpForAppointmentId",A."AppointmentDate",A."AppointmentNo"
,A."AppointmentTime",A."PatientName",A."UMRNo",A."Mobile",A."ProviderName",A."AppointmentId",
A."IsAppointmentReceipt"), (A."FullName"), ())
order by A."FullName"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_Receipts_Appointments_Location"(integer[], integer, integer, integer[], character varying, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- OWNER TO postgres;
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, integer, integer)
--
DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, 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,
"referredBy" text DEFAULT NULL::text,
"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,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text,
"ProviderName" character varying, "FollowUpForAppointmentId" integer,
"AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer,
"ReferredBy" 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)
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."FollowUpForAppointmentId",
A."AppointmentNo",A."PatientId" "PatientId",Pa."ReferredBy",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"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
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 "referredBy" is null then 1=1 when "referredBy" ='' then 1=1 else Pa."ReferredBy" ilike'%'||"referredBy" ||'%' 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
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",Pa."ReferredBy"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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",
A."FollowUpForAppointmentId",A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else Pa."ReferredBy"::varchar end as "ReferredBy",
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"
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"
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, integer, integer)
-- OWNER TO postgres;
-- SEQUENCE: public.SessionType_SessionTypeId_seq
-- DROP SEQUENCE IF EXISTS public."SessionType_SessionTypeId_seq";
CREATE SEQUENCE IF NOT EXISTS public."SessionType_SessionTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."SessionType_SessionTypeId_seq"
OWNER TO postgres;
------------------------------------------------------------------------------------
-- Table: public.SessionType
-- DROP TABLE IF EXISTS public."SessionType";
CREATE TABLE IF NOT EXISTS public."SessionType"
(
"SessionTypeId" integer NOT NULL DEFAULT nextval('"SessionType_SessionTypeId_seq"'::regclass),
"Name" character varying(150) COLLATE pg_catalog."default",
"Active" boolean NOT NULL,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "SessionTypeId_pkey" PRIMARY KEY ("SessionTypeId")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."SessionType"
OWNER to postgres;
---------------------------------------------------------------------------------------------------------------------------
-- SEQUENCE: public.Session_SessionId_seq
-- DROP SEQUENCE IF EXISTS public."Session_SessionId_seq";
CREATE SEQUENCE IF NOT EXISTS public."Session_SessionId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."Session_SessionId_seq"
OWNER TO postgres;
----------------------------------------------------------------------------------------------------------------
-- Table: public.Session
-- DROP TABLE IF EXISTS public."Session";
CREATE TABLE IF NOT EXISTS public."Session"
(
"SessionId" integer NOT NULL DEFAULT nextval('"Session_SessionId_seq"'::regclass),
"ProviderId" integer,
"Date" date,
"StartTime" time without time zone,
"EndTime" time without time zone,
"AvailabilityCount" integer,
"Banner" character varying COLLATE pg_catalog."default",
"LocationId" integer,
"SessionTypeId" integer,
"Active" boolean NOT NULL,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "SessionId_pkey" PRIMARY KEY ("SessionId"),
CONSTRAINT "Session_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "Session_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "Session_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "Session_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "Session_SessionTypeId_fkey" FOREIGN KEY ("SessionTypeId")
REFERENCES public."SessionType" ("SessionTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Session"
OWNER to postgres;
--------------------------------------------------------------------------------------------------------------------------------
\ No newline at end of file
insert into "LogType"("LogTypeId","LogTypeName","Active")values(68,'SessionType',true),(69,'Session',true);
-- FUNCTION: public.udf_fetch_Admission_Location(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_fetch_Admission_Location"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_fetch_Admission_Location"(
"admissionNo" text DEFAULT NULL::text,
"providerId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"isDischarged" boolean DEFAULT NULL::boolean,
"patientMobileNo" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"dischargeDate" date DEFAULT NULL::date,
"uMRNo" text DEFAULT NULL::text,
active boolean DEFAULT NULL::boolean,
locationid integer DEFAULT NULL::integer,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("AdmissionId" integer, "AdmissionNo" text, "IsConvertedFromOPtoIp" boolean, "AdmissionDate" timestamp without time zone, "AdmissionTime" time without time zone, "PatientName" text, "UMRNo" character varying, "PatientAge" smallint, "PatientGender" character, "patientMobile" character varying, "ProviderAge" smallint, "ProviderGender" character, "ProviderName" text, "DepartmentName" text, "WardName" character varying, "RoomName" character varying, "BedNumber" character varying, "AttendantName" character varying, "AttendantRelationWithPatient" character varying, "AttendantContactNo" character varying, "IsDischarged" boolean, "DischargeDate" date, "DischargeTime" time without time zone, "DischargeStatus" character varying, "IsMaternity" boolean, "EncounterId" integer, "SurgeryName" character varying, "ProviderThumbnailUrl" text, "PatientThumbnailUrl" text, "BedId" integer, "RoomId" integer, "WardId" integer, "DepartmentId" integer, "PatientId" integer, "ProviderId" integer, "SurgeryTypeId" integer, "PatientType" character, "AdmissionNotes" text, "PaidAmount" numeric, "FinalAmount" numeric, "PaymentStatus" text, "IsFinalBill" boolean, "TotalItems" bigint, "Active" boolean, "ExpectedDischargeDate" timestamp without time zone, "DischargedBy" integer, "DischargedByRole" text, "DischargedByName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
With TotalItems as (
select count(distinct A."AdmissionId")::bigint "TotalItems"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
where
case when "admissionNo" is null then 1=1
when "admissionNo"='' 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 AND
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "providerId" is null then 1=1
else Pr."ProviderId" = "providerId" end and
-- case when "isDischarged" is null then 1=1
-- when "isDischarged" =true then A."AdmissionId"=A."AdmissionId"
-- when "isDischarged" =false then ds."AdmissionId" is null
-- end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate" and A."AdmissionDate" <="toDate" end
)
select A."AdmissionId",A."AdmissionNo",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName" "PatientName",Pa."UMRNo",Pa."Age" "PatientAge",Pa."Gender" as "PatientGender",pa."Mobile" "patientMobile",Pr."Age" "ProviderAge",Pr."Gender" as "ProviderGender",
Pr."FullName"::text "ProviderName",D."DepartmentName"::text "DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName" "AttendantName",A."AttendantRelationWithPatient" "AttendantRelationWithPatient",A."AttendantContactNo" "AttendantContactNumber",
case when ds."DischargeId" is not null then true else false end as "IsDischarged",ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus"
,A."IsMaternity",A."EncounterId",st."SurgeryName",
(CASE WHEN pr."ThumbnailUrl" IS NOT NULL THEN CONCAT(pr."Guid", '/', pr."ThumbnailUrl") ELSE NULL END) AS "ProviderThumbnailUrl",
(CASE WHEN pa."ThumbnailUrl" IS NOT NULL THEN CONCAT(pa."Guid", '/', pa."ThumbnailUrl") ELSE NULL END) AS "PatientThumbnailUrl"
,A."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,
sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0) "PaidAmount"
,
FB."FinalAmount" ,
case when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))=0 then 'Payment Cleared'
when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))>0 then 'Payment Due'
when FB."FinalAmount"-(sum(coalesce(Re."Cost",0))-coalesce((select sum(Rfd."Cost") from "Receipt" Rfd where Rfd."AdmissionId"=A."AdmissionId" and "ReceiptTypeId"=2 and Rfd."Active"=true and Rfd."IsRefunded" =true ),0))<0 then 'Pending Refund' end "PaymentStatus",
case when FB."FinalBillId" is null then false else true end "IsFinalBill",(select T."TotalItems" from TotalItems T) "TotalItems",
A."Active",
A."ExpectedDischargeDate",
A."DischargedBy" ,
case when RL."RoleId" = '3' then DP."DepartmentName"::TEXT else RL."RoleName"::TEXT end as "DischargedByRole",
case when RL."RoleId" = '3' then PRO."FullName" else AC."FullName" end as "DischargedByName"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
left join "Account" AC on AC."AccountId"=A."DischargedBy"
left join "Role" RL on RL."RoleId"= AC."RoleId"
left join "Provider" PRO on PRO."ProviderId"=AC."ReferenceId"
left join "Department" DP on DP."DepartmentId"=PRO."DepartmentId"
where
case when "admissionNo" is null then 1=1
when "admissionNo"='' 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 AND
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "providerId" is null then 1=1
else Pr."ProviderId" = "providerId" end and
case when "isDischarged" is null then 1=1
when "isDischarged" =true then ds."AdmissionId"=A."AdmissionId"
when "isDischarged" =false then ds."AdmissionId" is null
end AND
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate"::date and A."AdmissionDate"::date <="toDate" end
AND
case when "dischargeDate" is null then 1=1 else "dischargeDate" =ds."DischargeDate"::date end
and
case when "uMRNo" is null then 1=1
when "uMRNo"='' then 1=1
else Pa."UMRNo" ilike '%'||"uMRNo"||'%' end
group by A."AdmissionId",A."AdmissionNo",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName",Pa."UMRNo",Pa."Age" ,Pa."Gender" ,Pr."Age" ,Pr."Gender" ,
Pr."FullName",D."DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName",A."AttendantRelationWithPatient",A."AttendantContactNo" , ds."DischargeId"
,ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus",pa."Mobile"
,A."IsMaternity",A."EncounterId",st."SurgeryName",pr."ThumbnailUrl", pr."Guid",pr."ThumbnailUrl" ,pa."Guid", pa."ThumbnailUrl",
A."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,FB."FinalAmount" ,FB."FinalBillId",
RL."RoleId",DP."DepartmentName",PRO."FullName",AC."FullName"
order by A."AdmissionId" desc
limit "pageSize" offset ("pageSize"*"pageIndex");
END
$BODY$;
ALTER FUNCTION public."udf_fetch_Admission_Location"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer)
OWNER TO postgres;
\ No newline at end of file
ALTER TABLE "PatientLabDetail"
DROP COLUMN "LabHeaderId",
DROP COLUMN "LabPackageId";
---------------------------------------------------------------
ALTER TABLE "PatientLabDetail"
ADD COLUMN "LabMainDetailId" integer,
add CONSTRAINT "PatientLabDetail_LabMainDetailId_fkey" FOREIGN KEY ("LabMainDetailId")
REFERENCES public."LabMainDetail" ("LabMainDetailId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
--------------------------------------------------------------------
truncate table "PatientLabHeader" cascade
truncate table "PatientLabDetail" cascade
\ No newline at end of file
create sequence "NewLabCancelBookingHeader_NewLabCancelBookingHeaderId_seq"
-------------------------------------------------------------------------------
-- Table: public.NewLabCancelBookingHeader
-- DROP TABLE IF EXISTS public."NewLabCancelBookingHeader";
CREATE TABLE IF NOT EXISTS public."NewLabCancelBookingHeader"
(
"NewLabCancelBookingHeaderId" integer NOT NULL DEFAULT nextval('"NewLabCancelBookingHeader_NewLabCancelBookingHeaderId_seq"'::regclass),
"NewLabBookingHeaderId" integer,
"TotalReturnAmount" numeric(8,2),
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
CONSTRAINT "NewLabCancelBookingHeader_pkey" PRIMARY KEY ("NewLabCancelBookingHeaderId"),
CONSTRAINT "NewLabBookingHeader_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "NewLabCancelBookingHeader_NewLabBookingHeaderId_fkey" FOREIGN KEY ("NewLabBookingHeaderId")
REFERENCES public."NewLabBookingHeader" ("NewLabBookingHeaderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."NewLabCancelBookingHeader"
OWNER to postgres;
--------------------------------------------------------------------------------------------------------------------
create sequence "NewLabCancelBookingDetail_NewLabCancelBookingDetailId_seq"
------------------------------------------------------------------------------------------------------------------------
-- Table: public.NewLabCancelBookingDetail
-- DROP TABLE IF EXISTS public."NewLabCancelBookingDetail";
CREATE TABLE IF NOT EXISTS public."NewLabCancelBookingDetail"
(
"NewLabCancelBookingDetailId" integer NOT NULL DEFAULT nextval('"NewLabCancelBookingDetail_NewLabCancelBookingDetailId_seq"'::regclass),
"NewLabCancelBookingHeaderId" integer,
"NewLabBookingDetailId" integer,
"ReturnAmount" numeric(8,2),
CONSTRAINT "NewLabCancelBookingDetail_pkey" PRIMARY KEY ("NewLabCancelBookingDetailId"),
CONSTRAINT "NewLabCancelBookingDetail_NewLabBookingDetailId_fkey" FOREIGN KEY ("NewLabBookingDetailId")
REFERENCES public."NewLabBookingDetail" ("NewLabBookingDetailId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "NewLabCancelBookingDetail_NewLabCancelBookingHeaderId_fkey" FOREIGN KEY ("NewLabCancelBookingHeaderId")
REFERENCES public."NewLabCancelBookingHeader" ("NewLabCancelBookingHeaderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."NewLabCancelBookingDetail"
OWNER to postgres;
\ 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 regexp_split_to_table(A."AvailableDate",',') ::date "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" =A."SpecializationId" 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."AvailableDay", A."ProviderAvailabilityId",A."AvailableDate"
--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",unnest(string_to_array(A."AvailableDate", ',')) AS "AvailableDate", 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 "AvailableDate"::date is not null is not null then 'A' else '' end "Status"
from TotalDates A
left join Avail B on "AvailableDate"::date= A."Dates" ::date 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"
where
A."Dates"::Date between startdate::Date and enddate::Date
)
select DISTINCT A."Date",A."DateNo"::int,A."Day"::text::character varying(10),A."Status"::char
from FinalData A
where trim(A."Status") <> ''
--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 "Location"
add "NameLoc" character varying(10)
update "Location"
set "NameLoc"= 'BK'
where "LocationId"=1
update "Location"
set "NameLoc"= 'BH'
where "LocationId"=2
update "Location"
set "NameLoc"= 'HG'
where "LocationId"=3
update "Location"
set "NameLoc"= 'MP'
where "LocationId"=4
alter table "DoctorSpecializationChargeModuleDetails" add column "FollowUpDays" integer;
alter table "DoctorSpecializationChargeModuleDetails" add column "FollowUpDaysLimit" integer;
alter table "Appointment" add column "DoctorSpecializationChargeModuleDetailsId" integer;
alter table "Appointment" drop column "ProviderAvailabilityChargeTypeId";
-- FUNCTION: public.UDF_Provider_Charges_From_Charge_Module(integer, integer, integer, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."UDF_Provider_Charges_From_Charge_Module"(integer, integer, integer, text, integer, integer);
CREATE OR REPLACE FUNCTION public."UDF_Provider_Charges_From_Charge_Module"(
providerid integer,
specializationid integer,
locationid integer,
appointmentdate text,
chargetypesid integer,
consultationtypeid integer)
RETURNS TABLE("DoctorSpecializationChargeModuleDetailsId" bigint, "ChargeTypesId" integer, "ChargeName" character varying, "Charge" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
IF EXISTS (
Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."ProviderId" = providerid and DSD."SpecializationId" = specializationid and DSD."LocationId" = locationid
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid
--END IF; 1
) THEN return query
Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."ProviderId" = providerid and DSD."SpecializationId" = specializationid and DSD."LocationId" = locationid
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid;
ELSEIF EXISTS (
Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."SpecializationId" = specializationid and DSD."LocationId" = locationid and DSD."ProviderId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid
) THEN return query Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."SpecializationId" = specializationid and DSD."LocationId" = locationid and DSD."ProviderId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid;
--END IF; 2
ELSEIF EXISTS (Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSD."ProviderId" = providerid and DSD."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid
) THEN return query Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSD."ProviderId" = providerid and DSD."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid;
--END IF; 3
ELSEIF EXISTS (Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSD."ProviderId" is null and DSD."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid
) THEN return query Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSD."ProviderId" is null and DSD."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSD."ConsultationTypeId" = consultationtypeid;
END IF; -- 1
end
$BODY$;
ALTER FUNCTION public."UDF_Provider_Charges_From_Charge_Module"(integer, integer, integer, text, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.udf_FetchDoctor_With_Availability_Specialization(character varying, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_FetchDoctor_With_Availability_Specialization"(character varying, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_FetchDoctor_With_Availability_Specialization"(
"filter" character varying DEFAULT NULL::text,
"locationId" integer DEFAULT NULL::integer,
"consultationTypeId" integer DEFAULT NULL::integer,
"appointmentDate" character varying DEFAULT NULL::text)
RETURNS TABLE("ProviderAvailabilityId" integer, "FullName" character varying, "DepartmentName" character varying, "DepartmentId" integer, "ProviderId" integer, "SpecializationId" integer, "SpecializationName" character varying, "LocationId" integer, "ConsultationTypeId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
SELECT DISTINCT on (pr2."ProviderId", s."SpecializationId") prl."ProviderAvailabilityId" ,pr2."FullName"
, d."DepartmentName" , d."DepartmentId"
,pr2."ProviderId"
, s. "SpecializationId", s."SpecializationName"
, CMT."LocationId", prl."ConsultationTypeId"
FROM "ProviderAvailability" prl
Join "DoctorSpecializationMap" LSM on LSM."ProviderId" = prl."ProviderId" and LSM."SpecializationId" = prl."SpecializationId" and LSM."ConsultationTypeId" = prl."ConsultationTypeId"
join "DoctorSpecializationChargeModuleDetails" DSCD on DSCD."ReferenceId" = LSM."DoctorSpecializationMapId"
join "DoctorSpecializationChargeModuleCategory" DSCC on DSCC."DoctorSpecializationChargeModuleCategoryId" = DSCD."DoctorSpecializationChargeModuleCategoryId"
join "ChargeModuleTemplate" CMT on CMT."ChargeModuleTemplateId" = DSCC."ChargeModuleTemplateId"
JOIN "Provider" pr2 on pr2."ProviderId" = LSM."ProviderId" and pr2."Active" is true
join "Account" pa on pa."ReferenceId" = pr2."ProviderId" and pa."Active" is true and pa."RoleId" = 3
JOin "LocationAccountMap" LAM on LAM."AccountId" = pa."AccountId"
join "Specialization" s on s."SpecializationId" = ANY (pr2."Specializations")
JOIN "Location" pral on pral."LocationId" = CMT."LocationId" AND pral."Active" IS TRUE
JOIN "Practice" pra on pra."PracticeId" = pral."PracticeId" AND pra."Active" IS TRUE
JOIN "Department" d on d."DepartmentId" = pr2."DepartmentId"
where pr2."Active" is true and CMT."LocationId" = "locationId" and s."Active" = true and CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date and "IsInUse" is true
and case when "filter" is null then 1=1 else TRIM(UPPER(pr2."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(s."SpecializationName")) ilike'%'|| "filter"||'%' end
and case when "consultationTypeId" is null then 1=1 else prl."ConsultationTypeId" = "consultationTypeId" end
--and case when "locationId" is null then 1=1 else LAM."LocationId" = "LocationId" end
--order by "FullName" asc
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchDoctor_With_Availability_Specialization"(character varying, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.udf_PharmacyBills_Report(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text)
-- DROP FUNCTION IF EXISTS public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_Report"(
"billNumber" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "PaidVia" character varying, "PaymentNumber" character varying, "CreatedByName" text, "RoleName" character varying, "ProviderName" character varying, "TotalAmount" numeric, "RetailName" text, "OverallTaxes" numeric, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."CreatedDate" "SaleDate",PH."PatientName",PH."Mobile"
,Pa."UMRNo",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."ProviderName", PH."OverallNetAmount" ,RP."RetailName",PH."OverallTaxes",L."Name" as "LocationName"
from "PharmacySaleHeader" PH
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
--join "Provider" pr on pr."ProviderId"::text=PH."ProviderId"::text
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" ="providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" :: date >= "fromDate" :: date end and
case when "toDate" is null then 1=1 else PH."SaleDate" :: date<= "toDate" :: date end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."SaleDate", PH."OverallNetAmount",PH."PatientName",PH."Mobile",Pa."UMRNo",PT."PayTypeName", PH."PaymentNumber", A."FullName"
,R."RoleName" ,PH."ProviderName",RP."RetailName",PH."OverallTaxes",L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
ALTER FUNCTION public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text)
OWNER TO postgres;
--select * from udf_PharmacyBills_Report(text, integer,text, character varying, integer, integer, integer, '2023-02-28':: date, '2023-03-01':: date, text, integer, text)
\ No newline at end of file
-- FUNCTION: public.udf_DailySalesReportByMedication(text, text, text, text, text, integer, date, date, integer)
-- DROP FUNCTION IF EXISTS public."udf_DailySalesReportByMedication"(text, text, text, text, text, integer, date, date, integer);
CREATE OR REPLACE FUNCTION public."udf_DailySalesReportByMedication"(
"productName" text DEFAULT NULL::text,
"genericName" text DEFAULT NULL::text,
"categoryName" text DEFAULT NULL::text,
"companyName" text DEFAULT NULL::text,
"supplierName" text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("PharmacyProductId" integer, "ProductName" character varying, "BatchNumber" character varying, "GenericName" text, "CategoryName" character varying, "CompanyName" text, "SupplierName" text, "SaleQuantity" bigint, "Mrp" numeric, "Discount" numeric, "TotalAmount" numeric, "PaidVia" character varying, "PaymentNumber" character varying, "SaleDate" timestamp without time zone, "PurchaseValue" numeric, "PurchaseUnitQty" integer, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select A."PharmacyProductId",A."ProductName",A."BatchNumber",A."GenericName",A."CategoryName ",A."CompanyName"
,A."SupplierName"
,sum(A."Quantity") "SaleQuantity",A."Mrp",A."OverallDiscount" "Discount",sum(A."NetAmount") "TotalAmount"
,A."PaidVia",A."PaymentNumber",A."SaleDate" , TRUNC((A."PPD_NetAmount"/A."PPD_Quantity"),2) as "PurchaseValue"
,A."PurchaseUnitQty",A."LocationName"
from (
select PS."PharmacyProductId",PP."ProductName",PRS."BatchNumber",pp."GenericName",ci."Name" "CategoryName ",c."Name" "CompanyName",s."Name" "SupplierName"
,PH."SaleDate",PS."Quantity",PRS."Mrp",Ps."Discount" "OverallDiscount",PS."NetAmount" , PT."PayTypeName" as "PaidVia", PH."PaymentNumber",
ppd."NetAmount" as "PPD_NetAmount",ppd."Quantity" as "PPD_Quantity",L."Name" as "LocationName"
,pp."PurchaseUnitQty"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyPurchaseDetail" Ppd on ppd."PharmacyStockId"=prs."PharmacyStockId" and ppd."PharmacyProductId"=PRS."PharmacyProductId"
join "PharmacyPurchaseHeader" pph on pph."PharmacyPurchaseHeaderId"=Ppd."PharmacyPurchaseHeaderId"
join "Supplier" s on s."SupplierId"=pph."SupplierId"
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "productName" ='' then 1=1 when "productName" is null then 1=1 else PP."ProductName" ilike '%'||"productName"||'%' end and
case when "genericName" ='' then 1=1 when "genericName" is null then 1=1 else pp."GenericName" ilike '%'||"genericName"||'%' end and
case when "categoryName" ='' then 1=1 when "categoryName" is null then 1=1 else ci."Name" ilike '%'||"categoryName"||'%' end and
case when "companyName" ='' then 1=1 when "companyName" is null then 1=1 else c."Name" ilike '%'||"companyName"||'%' end and
case when "supplierName" ='' then 1=1 when "supplierName" is null then 1=1 else s."Name" ilike '%'||"supplierName"||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" ::date <=PH."SaleDate"::date and PH."SaleDate"::date <="toDate" ::date end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PS."PharmacyProductId",PP."ProductName",PRS."BatchNumber",PH."SaleDate"
,pp."GenericName",ci."Name",c."Name" ,s."Name" ,PS."Quantity",PS."NetAmount",PRS."Mrp",Ps."Discount" ,PT."PayTypeName" , PH."PaymentNumber",
ppd."NetAmount", ppd."Quantity",pp."PurchaseUnitQty",L."Name") A
group by A."PharmacyProductId",A."ProductName",A."BatchNumber",A."GenericName",A."CategoryName ",
A."CompanyName",A."SupplierName",A."Mrp",A."OverallDiscount",A."PaidVia",A."PaymentNumber",A."SaleDate", (A."PPD_NetAmount"/A."PPD_Quantity") , A."PurchaseUnitQty",
A."LocationName"
order by A."ProductName"
;
END
$BODY$;
ALTER FUNCTION public."udf_DailySalesReportByMedication"(text, text, text, text, text, integer, date, date, integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.udf_PatientMedicationReport(integer, text, text, text, integer, timestamp without time zone, timestamp without time zone, text)
-- DROP FUNCTION IF EXISTS public."udf_PatientMedicationReport"(integer, text, text, text, integer, timestamp without time zone, timestamp without time zone, text);
CREATE OR REPLACE FUNCTION public."udf_PatientMedicationReport"(
"patientId" integer DEFAULT NULL::integer,
"uMRNo" text DEFAULT NULL::text,
"patientMobile" text DEFAULT NULL::text,
"billNumber" text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PatientName" text, "UMRNo" character varying, "PatientMobile" character varying, "BillNumber" character varying, "BillType" character varying, "SaleDate" timestamp without time zone, "OverallNetAmount" numeric, "ProductName" character varying, "GenericName" text, "CategoryName" character varying, "CompanyName" text, "BatchNumber" character varying, "PaidVia" character varying, "PaymentNumber" character varying, "Quantity" integer, "NetAmount" numeric, "TotalAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select P."FullName" "PatientName",P."UMRNo",p."Mobile" "PatientMobile" ,Ph."BillNumber",PH."BillType",
PH."CreatedDate" "SaleDate",PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" "CategoryName ",c."Name" "CompanyName",PRS."BatchNumber", PT."PayTypeName" as "PaidVia",PH."PaymentNumber" ,sum(PS."Quantity")::int "Quantity",
PS."NetAmount" ,sum(PS."NetAmount") "TotalAmount"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Patient" P on P."PatientId"=ph."PatientId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
--where p."UMRNo" ='UMR21050206'
where case when "uMRNo" ='' then 1=1 when "uMRNo" is null then 1=1 else p."UMRNo" ilike '%'||"uMRNo"||'%' end and
--case when "patientName" ='' then 1=1 when "patientName" is null then 1=1 else P."FullName" ilike '%'||"patientName"||'%' end and
case when "patientId" is null then 1=1 else P."PatientId"="patientId" end and
case when "patientMobile" ='' then 1=1 when "patientMobile" is null then 1=1 else p."Mobile" ilike '%'||"patientMobile"||'%' end and
case when "billNumber" ='' then 1=1 when "billNumber" is null then 1=1 else Ph."BillNumber" ilike '%'||"billNumber"||'%' end
and case when "payTypeId" is null then 1=1 else PT."PayTypeId" ="payTypeId" end
and case when "fromDate" is null then 1=1 else "fromDate" <= PH."CreatedDate" and PH."CreatedDate" <= "toDate" end
and case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
GROUP BY GROUPING SETS(( P."FullName",P."UMRNo",p."Mobile" ,Ph."BillNumber",PH."CreatedDate",PH."BillType",
PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" ,c."Name" ,PRS."BatchNumber",PT."PayTypeName", PH."PaymentNumber" ,PS."Quantity",PS."NetAmount" ),
( P."FullName",Ph."BillNumber",PH."BillType"), ())
order by Ph."CreatedDate" desc
;
END
$BODY$;
ALTER FUNCTION public."udf_PatientMedicationReport"(integer, text, text, text, integer, timestamp without time zone, timestamp without time zone, text)
OWNER TO postgres;
create table "PatientMedicationHeader"(
"PatientMedicationHeaderId" serial primary key,"AppointmentId" int references "Appointment"("AppointmentId"),
"CreatedBy" int references "Account"("AccountId"),"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),"ModifiedDate" timestamp without time zone,
"Active" boolean default true);
create table "PatientMedicationDetail"(
"PatientMedicationDetailId" serial primary key,"PatientMedicationHeaderId" int references "PatientMedicationHeader"("PatientMedicationHeaderId"),
"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),"Duration" int not null,
"DurationType" varchar(10) not null,"IsMorning" boolean default false,"IsAfternoon" boolean default false,"IsNight" boolean default false,
"MorningDosage" text,"AfternoonDosage" text,"NightDosage" text
);
-----------------
alter table "PatientMedicationHeader" add column "EncounterType" text;
--------------
alter table "PatientMedicationDetail" add column "Dosage" int not null;
alter table "PatientMedicationDetail" add column "Instruction" text;
\ No newline at end of file
create table "OrderPrescriptionMaster"(
"OrderPrescriptionMasterId" serial not null ,
"Name" character varying not null,
"Active" BOOLEAN,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "OrderPrescriptionMasterId_pkey" PRIMARY KEY ("OrderPrescriptionMasterId"),
CONSTRAINT "FK_OrderPrescriptionMaster_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_OrderPrescriptionMaster_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Important Advice', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Maternal Plan', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Fatal Plan', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate")VALUES ('Investigation Template', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Referrals', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Procedures Templates', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Diagnosis Remarks', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('pregnancy Plan', true, 1029,'2022-07-27 17:26:41.188772');
INSERT INTO "OrderPrescriptionMaster" ("Name", "Active", "CreatedBy","CreatedDate") VALUES ('Pre pregnancy Councelling Details', true,1029,'2022-07-27 17:26:41.188772');
ALTER TABLE "OTRegister"
ADD COLUMN "OTRoomId" integer,
ADD CONSTRAINT "FK_OTRoom_Surgery_fkey" FOREIGN KEY ("OTRoomId")
REFERENCES public."OTRoom" ("OTRoomId")
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."OTRoomAvailability_OTRoomAvailabilityId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1;
-- Table: public.OTRoomAvailability
-- DROP TABLE IF EXISTS public."OTRoomAvailability";
CREATE TABLE IF NOT EXISTS public."OTRoomAvailability"
(
"OTRoomAvailabilityId" integer NOT NULL DEFAULT nextval('"OTRoomAvailability_OTRoomAvailabilityId_seq"'::regclass),
"OTRoomId" integer,
"Availability" text COLLATE pg_catalog."default",
"LocationId" integer,
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"FromDate" timestamp(6) without time zone,
"ToDate" timestamp(6) without time zone,
"AvailableDays" text COLLATE pg_catalog."default",
"FromTime" text COLLATE pg_catalog."default",
"ToTime" text COLLATE pg_catalog."default",
CONSTRAINT "OTRoomAvailability_pkey" PRIMARY KEY ("OTRoomAvailabilityId"),
CONSTRAINT "OTRoomAvailability_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRoomAvailability_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRoomAvailability_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "OTRoomAvailability_OTRoomId_fkey" FOREIGN KEY ("OTRoomId")
REFERENCES public."OTRoom" ("OTRoomId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."OTRoomAvailability"
OWNER to postgres;
\ 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);
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[],
"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)
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"
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
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."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"
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[], integer, integer)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.udf_fetchpatientsfilter_for_appointment(character varying, character varying, character varying, character varying)
DROP FUNCTION public.udf_fetchpatientsfilter_for_appointment(character varying, character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public.udf_fetchpatientsfilter_for_appointment(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"patientName" 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, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
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"
where a."Active"=true
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 "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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" ,
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT('https://hims-qa.s3.amazonaws.com/', 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"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
WHERE pat."Active" IS TRUE
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 "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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_fetchpatientsfilter_for_appointment(character varying, character varying, character varying, character varying)
OWNER TO postgres;
DROP FUNCTION IF EXISTS public."udf_FetchPatients_For_QuickScheduleFollowUp"(character varying, character varying, character varying, character varying);
-- 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, "PaymentStatus" boolean,"HowDidYouKnowId" integer,"EducationId" integer,"OccupationId" integer, "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" ,
pat."PaymentStatus",
pat."HowDidYouKnowId",
pat."EducationId",
pat."OccupationId",
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;
\ No newline at end of file
////////PatientFamily Alter query/////
ALTER TABLE "PatientFamily"
ADD COLUMN "Education" VARCHAR(255),
ADD COLUMN "Occupation" VARCHAR(255),
ADD COLUMN "DOB" DATE;
////////Patient Alter query/////
ALTER TABLE "Patient"
ADD COLUMN "Education" VARCHAR(255),
ADD COLUMN "Occupation" VARCHAR(255),
ADD COLUMN "Religion" VARCHAR(255),
ADD COLUMN "Nationality" VARCHAR(255);
-- Column: public."PayType"."SalucroPayType"
-- ALTER TABLE IF EXISTS public."PayType" DROP COLUMN IF EXISTS "SalucroPayType";
ALTER TABLE IF EXISTS public."PayType"
ADD COLUMN "SalucroPayType" boolean DEFAULT false;
\ No newline at end of file
delete from "PracticeLocation"
ALTER TABLE "PracticeLocation" ADD "LocationId" INT NOT NULL ;
DROP INDEX IF EXISTS public."IX_PracticeLocation";
DROP INDEX IF EXISTS public."IX_PracticeLocation_FullName";
\ No newline at end of file
alter table "ProviderAvailability" drop column "FreeFollowUpDays" ;
alter table "ProviderAvailability" drop column "FreeFollowUpDaysLimit";
alter table "ProviderAvailability" add column "NoOfOfflinePatient" integer;
\ No newline at end of file
CREATE OR REPLACE FUNCTION public."UDF_TEST"(
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"
) 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;
--END IF; 1
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName",PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
) 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."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"
) 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."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"
) 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."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_TEST"(integer, integer, integer, text, integer, integer)
OWNER TO postgres;
alter table "ProviderAvailabilityChargeType" add column "FollowUpDays" integer;
alter table "ProviderAvailabilityChargeType" add column "FollowUpDaysLimit" integer;
update "ProviderAvailabilityChargeType" set "FollowUpDays" = 0 , "FollowUpDaysLimit" = 0;
\ No newline at end of file
-- Table: public.ProviderAvailabilityChargeType
DROP TABLE IF EXISTS public."ProviderAvailabilityChargeType";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilityChargeType"
(
"ProviderAvailabilityChargeTypeId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId"'::regclass),
"ChargeTypesId" integer NOT NULL,
"Charge" integer,
"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,
"ProviderId" integer,
"LocationId" integer,
"StartDate" timestamp(6) without time zone,
"EndDate" timestamp(6) without time zone,
"SpecializationId" integer,
"ConsultationTypeId" integer,
"PartsOfDayId" integer,
CONSTRAINT "ProviderAvailabilityChargeType_pkey" PRIMARY KEY ("ProviderAvailabilityChargeTypeId"),
CONSTRAINT "ProviderAvailabilityChargeType_ChargeTypesId_fkey" FOREIGN KEY ("ChargeTypesId")
REFERENCES public."ChargeTypes" ("ChargeTypesId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_ConsultationTypeId_fkey" FOREIGN KEY ("ConsultationTypeId")
REFERENCES public."ConsultationType" ("ConsultationTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_PartsOfDayId_fkey" FOREIGN KEY ("PartsOfDayId")
REFERENCES public."PartsOfDay" ("PartsOfDayId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilityChargeType"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilityChargeType"."ProviderAvailabilityChargeTypeId"
IS ' ';
---------------------------------------------------------------------------------------------------------------------------------------
-- Table: public.ProviderAvailabilityVisitType
DROP TABLE IF EXISTS public."ProviderAvailabilityVisitType";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilityVisitType"
(
"ProviderAvailabilityVisitTypeId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_s"'::regclass),
"VisitTypeId" integer NOT NULL,
"Duration" integer,
"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,
"LocationId" integer,
"ProviderId" integer,
"SpecializationId" integer,
CONSTRAINT "ProviderAvailabilityVisitType_pkey" PRIMARY KEY ("ProviderAvailabilityVisitTypeId"),
CONSTRAINT "ProviderAvailabilityVisitType_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_VisitTypeId_fkey" FOREIGN KEY ("VisitTypeId")
REFERENCES public."VisitType" ("VisitTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilityVisitType"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilityVisitType"."ProviderAvailabilityVisitTypeId"
IS ' ';
\ No newline at end of file
-- Table: public.ProviderAvailabilityVisitType
-- DROP TABLE IF EXISTS public."ProviderAvailabilityVisitType";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilityVisitType"
(
"ProviderAvailabilityVisitTypeId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilityVisitType_ProviderAvailabilityVisitTypeId_s"'::regclass),
"VisitTypeId" integer NOT NULL,
"Duration" integer,
"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,
"LocationId" integer,
"ProviderId" integer,
"SpecializationId" integer,
"ProviderAvailabilityId" integer,
CONSTRAINT "ProviderAvailabilityVisitType_pkey" PRIMARY KEY ("ProviderAvailabilityVisitTypeId"),
CONSTRAINT "ProviderAvailabilityVisitType_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_ProviderAvailabilityId_fkey" FOREIGN KEY ("ProviderAvailabilityId")
REFERENCES public."ProviderAvailability" ("ProviderAvailabilityId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityVisitType_VisitTypeId_fkey" FOREIGN KEY ("VisitTypeId")
REFERENCES public."VisitType" ("VisitTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilityVisitType"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilityVisitType"."ProviderAvailabilityVisitTypeId"
IS ' ';
--------------------------------------------------------------------------------------------------------------------
-- Table: public.ProviderAvailabilityChargeType
-- DROP TABLE IF EXISTS public."ProviderAvailabilityChargeType";
CREATE TABLE IF NOT EXISTS public."ProviderAvailabilityChargeType"
(
"ProviderAvailabilityChargeTypeId" integer NOT NULL DEFAULT nextval('"ProviderAvailabilityChargeType_ProviderAvailabilityChargeTypeId"'::regclass),
"PartsOfDayId" integer,
"ChargeTypesId" integer NOT NULL,
"Charge" integer,
"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,
"ProviderId" integer,
"LocationId" integer,
"StartDate" timestamp(6) without time zone,
"EndDate" timestamp(6) without time zone,
"SpecializationId" integer,
CONSTRAINT "ProviderAvailabilityChargeType_pkey" PRIMARY KEY ("ProviderAvailabilityChargeTypeId"),
CONSTRAINT "ProviderAvailabilityChargeType_ChargeTypesId_fkey" FOREIGN KEY ("ChargeTypesId")
REFERENCES public."ChargeTypes" ("ChargeTypesId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_PartsOfDayId_fkey" FOREIGN KEY ("PartsOfDayId")
REFERENCES public."PartsOfDay" ("PartsOfDayId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "ProviderAvailabilityChargeType_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ProviderAvailabilityChargeType_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ProviderAvailabilityChargeType"
OWNER to postgres;
COMMENT ON COLUMN public."ProviderAvailabilityChargeType"."ProviderAvailabilityChargeTypeId"
IS ' ';
\ No newline at end of file
-- FUNCTION: public.udf_FetchPatientsFilter_For_Appointment(character varying,character varying, character varying, character varying)
-- DROP FUNCTION IF EXISTS public."udf_FetchPatientsFilter_For_Appointment"(character varying,character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatientsFilter_For_Appointment"(
"filter" character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"patientName" 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, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean)
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"
where a."Active"=true
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 "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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" ,
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT('https://hims-devv.s3.amazonaws.com/', 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"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
WHERE pat."Active" IS TRUE
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 "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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_FetchPatientsFilter_For_Appointment"(character varying,character varying, character varying, character varying)
OWNER TO postgres;
-- FUNCTION: public.UDF_Provider_Charges_From_Charge_Module(integer, integer, integer, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."UDF_Provider_Charges_From_Charge_Module"(integer, integer, integer, text, integer, integer);
CREATE OR REPLACE FUNCTION public."UDF_Provider_Charges_From_Charge_Module"(
providerid integer,
specializationid integer,
locationid integer,
appointmentdate text,
chargetypesid integer,
consultationtypeid integer)
RETURNS TABLE("DoctorSpecializationChargeModuleDetailsId" bigint, "ChargeTypesId" integer, "ChargeName" character varying, "Charge" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
IF EXISTS (
Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSM."ProviderId" = providerid and DSM."SpecializationId" = specializationid and DSD."LocationId" = locationid
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid
--END IF; 1
) THEN return query
Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSM."ProviderId" = providerid and DSM."SpecializationId" = specializationid and DSD."LocationId" = locationid
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid;
ELSEIF EXISTS (
Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSM."SpecializationId" = specializationid and DSD."LocationId" = locationid and DSM."ProviderId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid
) THEN return query Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSM."SpecializationId" = specializationid and DSD."LocationId" = locationid and DSM."ProviderId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid;
--END IF; 2
ELSEIF EXISTS (Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSM."ProviderId" = providerid and DSM."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid
) THEN return query Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSM."ProviderId" = providerid and DSM."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid;
--END IF; 3
ELSEIF EXISTS (Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSM."ProviderId" is null and DSM."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid
) THEN return query Select DSD."DoctorSpecializationChargeModuleDetailsId", DSC."ChargeTypesId", CT."ChargeName", DSD."Amount" as "Charge"
from "DoctorSpecializationChargeModuleDetails" DSD
Join "DoctorSpecializationMap" DSM on DSM."DoctorSpecializationMapId" = DSD."ReferenceId"
Join "DoctorSpecializationChargeModuleCategory" DSC on DSC."DoctorSpecializationChargeModuleCategoryId" = DSD."DoctorSpecializationChargeModuleCategoryId" and DSC."Active" is true
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = DSC."ChargeTypesId" and CT."Active" is true
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = DSC."ModulesMasterId"
JOIN "ChargeModuleTemplate" CMT ON CMT."ChargeModuleTemplateId" = DSC."ChargeModuleTemplateId" and CMT."IsInUse" is true
where DSD."LocationId" = locationid and DSM."ProviderId" is null and DSM."SpecializationId" is null
AND CMT."StartDate"::DATE <= appointmentdate::DATE and CMT."EndDate"::DATE >= appointmentdate::DATE
AND DSC."ChargeTypesId" = chargetypesid And DSM."ConsultationTypeId" = consultationtypeid;
END IF; -- 1
end
$BODY$;
ALTER FUNCTION public."UDF_Provider_Charges_From_Charge_Module"(integer, integer, integer, text, integer, integer)
OWNER TO postgres;
alter table "ChargeCategory"
ALTER COLUMN "Default" DROP NOT NULL
\ No newline at end of file
-- FUNCTION: public.udf_FetchDoctor_With_Availability_Specialization_Op(character varying, integer, integer, character varying)
-- DROP FUNCTION IF EXISTS public."udf_FetchDoctor_With_Availability_Specialization_Op"(character varying, integer, integer, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchDoctor_With_Availability_Specialization_Op"(
filter character varying DEFAULT NULL::text,
"locationId" integer DEFAULT NULL::integer,
"consultationTypeId" integer DEFAULT NULL::integer,
"appointmentDate" character varying DEFAULT NULL::text)
RETURNS TABLE("ProviderAvailabilityId" integer, "FullName" character varying, "DepartmentName" character varying, "DepartmentId" integer, "ProviderId" integer, "SpecializationId" integer, "SpecializationName" character varying, "LocationId" integer, "ConsultationTypeId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
SELECT DISTINCT on (pr2."ProviderId", s."SpecializationId") prl."ProviderAvailabilityId" ,pr2."FullName"
, d."DepartmentName" , d."DepartmentId"
,pr2."ProviderId"
, s. "SpecializationId", s."SpecializationName"
, CMT."LocationId", prl."ConsultationTypeId"
FROM "ProviderAvailability" prl
Join "DoctorSpecializationMap" LSM on LSM."ProviderId" = prl."ProviderId" and LSM."SpecializationId" = prl."SpecializationId" and LSM."ConsultationTypeId" = prl."ConsultationTypeId"
join "DoctorSpecializationChargeModuleDetails" DSCD on DSCD."ReferenceId" = LSM."DoctorSpecializationMapId"
join "DoctorSpecializationChargeModuleCategory" DSCC on DSCC."DoctorSpecializationChargeModuleCategoryId" = DSCD."DoctorSpecializationChargeModuleCategoryId"
join "ChargeModuleTemplate" CMT on CMT."ChargeModuleTemplateId" = DSCC."ChargeModuleTemplateId"
JOIN "Provider" pr2 on pr2."ProviderId" = LSM."ProviderId" and pr2."Active" is true
join "Account" pa on pa."ReferenceId" = pr2."ProviderId" and pa."Active" is true and pa."RoleId" = 3
JOin "LocationAccountMap" LAM on LAM."AccountId" = pa."AccountId"
join "Specialization" s on s."SpecializationId" = ANY (pr2."Specializations")
JOIN "Location" pral on pral."LocationId" = CMT."LocationId" AND pral."Active" IS TRUE
JOIN "Practice" pra on pra."PracticeId" = pral."PracticeId" AND pra."Active" IS TRUE
JOIN "Department" d on d."DepartmentId" = pr2."DepartmentId"
where pr2."Active" is true and CMT."LocationId" = "locationId" and s."Active" = true
--and CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date
and "IsInUse" is true
and case when "filter" is null then 1=1 else TRIM(UPPER(pr2."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(s."SpecializationName")) ilike'%'|| "filter"||'%' end
and case when "consultationTypeId" is null then 1=1 else prl."ConsultationTypeId" = "consultationTypeId" end
and case when "appointmentDate" is null then CMT."StartDate"::date <= current_date::date and CMT."EndDate"::date >= current_date::date else CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date end
--and case when "locationId" is null then 1=1 else LAM."LocationId" = "LocationId" end
--order by "FullName" asc
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchDoctor_With_Availability_Specialization_Op"(character varying, integer, integer, character varying)
OWNER TO postgres;
-- FUNCTION: public.udf_FetchPatients_For_QuickSchedule(character varying, character varying, character varying)
DROP FUNCTION if exists public."udf_FetchPatients_For_QuickSchedule"(character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_QuickSchedule"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"patientName" 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, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean)
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"
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" ,
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT('https://hims-devv.s3.amazonaws.com/', 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"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
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_QuickSchedule"(character varying, character varying, character varying)
OWNER TO postgres;
-- FUNCTION: public.udf_FetchDoctor_With_Availability_Specialization(character varying, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_FetchDoctor_With_Availability_Specialization"(character varying, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_FetchDoctor_With_Availability_Specialization"(
filter character varying DEFAULT NULL::text,
"locationId" integer DEFAULT NULL::integer,
"consultationTypeId" integer DEFAULT NULL::integer)
RETURNS TABLE("ProviderAvailabilityId" integer, "FullName" character varying, "DepartmentName" character varying, "DepartmentId" integer, "ProviderId" integer, "SpecializationId" integer, "SpecializationName" character varying, "LocationId" integer, "ConsultationTypeId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
SELECT DISTINCT on (pr2."ProviderId", s."SpecializationId") prl."ProviderAvailabilityId" ,pr2."FullName"
, d."DepartmentName" , d."DepartmentId"
,pr2."ProviderId"
, s. "SpecializationId", s."SpecializationName"
, prl."LocationId", prl."ConsultationTypeId"
FROM "ProviderAvailability" prl
JOIN "Provider" pr2 on pr2."ProviderId" = prl."ProviderId" and pr2."Active" is true
join "Account" pa on pa."ReferenceId" = pr2."ProviderId" and pa."Active" is true and pa."RoleId" = 3
JOin "LocationAccountMap" LAM on LAM."AccountId" = pa."AccountId"
join "Specialization" s on s."SpecializationId" = ANY (pr2."Specializations")
JOIN "Location" pral on pral."LocationId" = prl."LocationId" AND pral."Active" IS TRUE
JOIN "Practice" pra on pra."PracticeId" = pral."PracticeId" AND pra."Active" IS TRUE
JOIN "Department" d on d."DepartmentId" = pr2."DepartmentId"
where pr2."Active" is true and prl."LocationId" = "locationId" and s."Active" = true
and case when "filter" is null then 1=1 else TRIM(UPPER(pr2."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(s."SpecializationName")) ilike'%'|| "filter"||'%' end
and case when "consultationTypeId" is null then 1=1 else prl."ConsultationTypeId" = "consultationTypeId" end
--and case when "locationId" is null then 1=1 else LAM."LocationId" = "LocationId" end
--order by "FullName" asc
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchDoctor_With_Availability_Specialization"(character varying, integer, integer)
OWNER TO postgres;
alter table "Receipt"
add "PatientRegistrationDetailId" INTEGER;
alter table "Receipt"
ADD CONSTRAINT "FK_Receipt_PatientRegistrationDetailId" FOREIGN KEY ("PatientRegistrationDetailId")
REFERENCES public."PatientRegistrationDetail" ("PatientRegistrationDetailId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
\ No newline at end of file
alter table "RoomCharge"
add column "ModifiedBy" integer,
add column "ModifiedDate" timestamp without time zone,
add CONSTRAINT "RoomChargeId_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
===================================
alter table "RoomCharge"
add column "Active" bool default false
\ No newline at end of file
alter table "ScanMachineAvailability" add column "FromTime" text
alter table "ScanMachineAvailability" add column "ToTime" text
\ No newline at end of file
INSERT INTO "Lookup" ("LookupId", "Name", "Description")VALUES (18, 'ScanCategory', 'Scan category types.');
INSERT INTO "Lookup" ("LookupId", "Name", "Description")VALUES (19, 'ScanSubCategory', 'Scan Sub category types.');
-- Table: public."ScanMachineAvailability"
-- DROP TABLE public."ScanMachineAvailability";
CREATE TABLE public."ScanMachineAvailability"
(
"ScanMachineAvailabilityId" serial integer NOT NULL ,
"ScanMachineMasterId" integer,
"RoomName" character varying(250) COLLATE pg_catalog."default",
"AvailableDays" character varying(14) COLLATE pg_catalog."default",
"Availability" text COLLATE pg_catalog."default",
"LocationId" integer,
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"FromDate" timestamp(6) without time zone,
"ToDate" timestamp(6) without time zone,
CONSTRAINT "ScanMachineAvailability_pkey" PRIMARY KEY ("ScanMachineAvailabilityId"),
CONSTRAINT "ScanMachineAvailability_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanMachineAvailability_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanMachineAvailability_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "ScanMachineAvailability_ScanMachineMasterId_fkey" FOREIGN KEY ("ScanMachineMasterId")
REFERENCES public."ScanMachineMaster" ("ScanMachineMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."ScanMachineAvailability"
OWNER to postgres;
----------------------------------------------------------------------------------------------------------------------------
-- Table: public."BookScanAppointment"
-- DROP TABLE public."BookScanAppointment";
CREATE TABLE public."BookScanAppointment"
(
"BookScanAppointmentId" serial integer NOT NULL ,
"PatientId" integer,
"PaymentStatus" boolean,
"PayTypeId" integer,
"LocationId" integer,
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"ScanMachineMasterId" integer,
"AppointmentDate" date,
"AppointmentTime" time(6) without time zone,
"PaymentNumber" character varying COLLATE pg_catalog."default",
"ScanTestMasterId" integer,
CONSTRAINT "BookScanAppointment_pkey" PRIMARY KEY ("BookScanAppointmentId"),
CONSTRAINT "BookScanAppointment_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "BookScanAppointment_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "BookScanAppointment_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "BookScanAppointment_PatientId_fkey" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "BookScanAppointment_PayTypeId_fkey" FOREIGN KEY ("PayTypeId")
REFERENCES public."PayType" ("PayTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "BookScanAppointment_ScanMachineMasterId_fkey" FOREIGN KEY ("ScanMachineMasterId")
REFERENCES public."ScanMachineMaster" ("ScanMachineMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public."BookScanAppointment"
OWNER to postgres;
---------------------------------------------------------------
\ No newline at end of file
insert into "Settings" ("Name") values('Email')
\ No newline at end of file
-- FUNCTION: public.udf_Employee_Revenue_Location(integer, integer, integer, timestamp without time zone, timestamp without time zone)
-- DROP FUNCTION IF EXISTS public."udf_Employee_Revenue_Location"(integer, integer, integer, timestamp without time zone, timestamp without time zone);
CREATE OR REPLACE FUNCTION public."udf_Employee_Revenue_Location"(
accountid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer,
roleid integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone)
RETURNS TABLE("AccountId" integer, "EmployeeName" text, "RoleName" character varying, "AppointmentCashTotal" numeric, "AppointmentCardTotal" numeric, "AppointmentAmount" numeric, "AdmissionCashTotal" numeric, "AdmissionCardTotal" numeric, "AdmissionAmount" numeric, "LabCash" numeric, "LabCard" numeric, "LabAmount" numeric, "PharmacySaleCash" numeric, "PharmacySaleCard" numeric, "PharmacyAmount" numeric, "TotalCash" numeric, "TotalCard" numeric, "Total" 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 "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" and rol."RoleName"<>'Patient'
where rol."RoleId"<>4 and case when accountid is null then 1=1 else a."AccountId"=accountid end
and case when roleid is null then 1=1 else a."RoleId"=roleid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
)
,actappointmentamount as (
select a."AccountId",sum(A."CashTotal") "AppointmentCashTotal",sum(A."CardTotal") "AppointmentCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") appointmentamount from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end and A."ReceiptTypeId"=1
and A."Active"<>false and A."AppointmentId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) <>true and ap."Status" <> 'C' and
case when "fromDate" is null then 1=1
else (A."CreatedDate" >= "fromDate" and A."CreatedDate" <= "toDate") end )a
group by a."AccountId"
)
,refundappointmentamount as (
select a."AccountId" ,sum(A."CashTotal") "AppointmentRefCashTotal",sum(A."CardTotal") "AppointmentRefCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") refappointmentamount from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Status" <> 'C' and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end
and A."Active"<>false and A."AppointmentId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) = true and
case when "fromDate" is null then 1=1
else (A."CreatedDate" >= "fromDate" and A."CreatedDate" <= "toDate") end ) a
group by a."AccountId"
)
,appointmentamount as (
select A."AccountId",
coalesce(A."AppointmentCashTotal",0) - coalesce(B."AppointmentRefCashTotal",0) as "AppointmentCashTotal" ,
coalesce(A."AppointmentCardTotal",0) - coalesce(B."AppointmentRefCardTotal",0) as "AppointmentCardTotal" ,
coalesce(A.appointmentamount,0) - coalesce(B.refappointmentamount,0) as "AppointmentAmount" from actappointmentamount A
left join refundappointmentamount B on A."AccountId"=B."AccountId"
)
,actadmissionamount as (
select a."AccountId" , sum(A."CashTotal") "AdmissionCashTotal",sum(A."CardTotal") "AdmissionCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") "AdmissionAmount" from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate" >= "fromDate" and adr."CreatedDate" <= "toDate") end )a
group by a."AccountId"
)
,refadmissionamount as (
select a."AccountId" , sum(A."CashTotal") "AdmissionRefCashTotal",sum(A."CardTotal") "AdmissionRefCardTotal",sum(A."CashTotal")+ sum(A."CardTotal") "AdmissionRefAmount" from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate" >= "fromDate" and adr."CreatedDate" <= "toDate") end )a
group by a."AccountId"
)
,admissionamount as (
select A."AccountId" ,
coalesce(A."AdmissionCashTotal",0) - coalesce(B."AdmissionRefCashTotal",0) "AdmissionCashTotal",
coalesce(A."AdmissionCardTotal",0) - coalesce(B."AdmissionRefCardTotal",0) "AdmissionCardTotal",
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A
left join refadmissionamount B on A."AccountId"=B."AccountId"
)
,LabAmount as (
select a."AccountId",sum(a."Cash") "LabCash",sum(a."Card") "LabCard" ,sum(a."Cash")+sum(a."Card")"LabAmount" from(
select a."AccountId",
case when "PaidVia"='Cash' then coalesce(ar."NetAmount",0) else 0 end "Cash"
,case when "PaidVia"<>'Cash' then coalesce(ar."NetAmount",0) else 0 end "Card"
from "Account" a
join "LabBookingHeader" ar on ar."CreatedBy" = a."AccountId" and ar."Active" <> false
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."CreatedDate" >= "fromDate" and ar."CreatedDate" <= "toDate") end)a
group by a."AccountId" )
,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 "PaidVia"='Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when "PaidVia"<>'Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."SaleDate" >= "fromDate" and ar."SaleDate" <= "toDate") 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."PaidVia"='Cash' then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PaidVia"='Card' then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when accountid is null then 1=1 else ar."CreatedBy"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."ReturnDate" >= "fromDate" and ar."ReturnDate" <= "toDate") 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 a."AccountId",a."EmployeeName",a."RoleName",
ap."AppointmentCashTotal",ap."AppointmentCardTotal",ap."AppointmentAmount",
ad."AdmissionCashTotal",ad."AdmissionCardTotal",ad."AdmissionAmount",
lb."LabCash", lb."LabCard",lb."LabAmount",
sum(pa."PharmaSaleCash") over(partition by a."AccountId") "PharmacySaleCash",
sum(pa."PharmaSaleCard") over(partition by a."AccountId") "PharmacySaleCard",
sum(pa."PharmaAmount") over(partition by a."AccountId") "PharmacyAmount",
coalesce(ap."AppointmentCashTotal",0)+ coalesce(ad."AdmissionCashTotal",0)+coalesce(lb."LabCash",0)+coalesce(sum(pa."PharmaSaleCash") over(partition by a."AccountId") ,0) "TotalCash",
coalesce(ap."AppointmentCardTotal",0)+ coalesce(ad."AdmissionCardTotal",0)+coalesce(lb."LabCard",0)+coalesce(sum(pa."PharmaSaleCard") over(partition by a."AccountId"),0) "TotalCard",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(partition by a."AccountId"),0) "Total"
from accountdata a
left join appointmentamount ap on ap."AccountId"=a."AccountId"
left join admissionamount ad on ad."AccountId"=a."AccountId"
left join LabAmount lb on lb."AccountId"=a."AccountId"
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public."udf_Employee_Revenue_Location"(integer, integer, integer, timestamp without time zone, timestamp without time zone)
OWNER TO postgres;
\ No newline at end of file
INSERT INTO public."LogType"(
"LogTypeId", "LogTypeName", "Active")
VALUES (73, 'Surgery', true);
\ No newline at end of file
alter table "Ticket" add column "LocationId" int references "Location"("LocationId");
CREATE OR REPLACE FUNCTION public."udf_FetchPatientsFilter_For_Appointment1"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"patientName" character varying DEFAULT NULL::text,
"billNumber" text 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, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean, "BillNumber" 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"
where a."Active"=true
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 "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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" ,
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT('https://hims-devv.s3.amazonaws.com/', 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"
,LBH."BillNumber"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
left join "LabBookingHeader" LBH on LBH."PatientId"=pat."PatientId"
WHERE pat."Active" IS TRUE
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 "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' 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
and case when "billNumber" is null then 1=1 else LBH."BillNumber" ilike'%'|| "billNumber"||'%' end
;
END
$BODY$;
-- FUNCTION: public.udf_PharmacyBills_Report(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text)
-- DROP FUNCTION IF EXISTS public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_Report"(
"billNumber" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "PaidVia" character varying, "PaymentNumber" character varying, "CreatedByName" text, "RoleName" character varying, "ProviderName" character varying, "TotalAmount" numeric, "RetailName" text, "OverallTaxes" numeric, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."CreatedDate" "SaleDate",PH."PatientName",PH."Mobile"
,Pa."UMRNo",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."ProviderName", PH."OverallNetAmount" ,RP."RetailName",PH."OverallTaxes",L."Name" as "LocationName"
from "PharmacySaleHeader" PH
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
--join "Provider" pr on pr."ProviderId"::text=PH."ProviderId"::text
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" ="providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."SaleDate", PH."OverallNetAmount",PH."PatientName",PH."Mobile",Pa."UMRNo",PT."PayTypeName", PH."PaymentNumber", A."FullName"
,R."RoleName" ,PH."ProviderName",RP."RetailName",PH."OverallTaxes",L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
ALTER FUNCTION public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text)
OWNER TO postgres;
-- FUNCTION: public.udf_ProductPurchaseReport(text, text, integer, text, text, date, date, boolean, text)
DROP FUNCTION IF EXISTS public."udf_ProductPurchaseReport"(text, text, integer, text, text, date, date, boolean, text);
CREATE OR REPLACE FUNCTION public."udf_ProductPurchaseReport"(
"billNumber" text DEFAULT NULL::text,
"billType" text DEFAULT NULL::text,
"createdBy" integer DEFAULT NULL::integer,
"supplierName" text DEFAULT NULL::text,
"productName" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"pharmacyBillType" boolean DEFAULT NULL::boolean,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("ProductName" character varying, "GenericName" text, "CategoryName" character varying, "PurchaseRate" numeric, "Quantity" numeric, "Mrp" numeric, "TaxAmount" numeric, "PharmacyPurchaseHeaderId" integer, "BillNumber" character varying, "BillType" character varying, "BillDate" timestamp without time zone, "CreatedByName" text, "RoleName" character varying, "SupplierName" text, "NetAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."ProductName",PH."GenericName",PH."CategoryName",PH."PurchaseRate",PH."Quantity",PH."Mrp",PH."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."BillDate",ph."CreatedByName",
ph."Role",ph."SupplierName", PH."NetAmount" from
(
select PP."ProductName",PP."GenericName",ci."Name" "CategoryName",PPD."PurchaseRate",PPD."Quantity",PPD."Mrp",PPD."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName", ppd."NetAmount" "NetAmount",true "PharmacyBillType"
from "PharmacyPurchaseHeader" PH
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyPurchaseDetail" ppd on ppd."PharmacyPurchaseHeaderId" = ph."PharmacyPurchaseHeaderId"
join "PharmacyProduct" pp on pp."PharmacyProductId" = ppd."PharmacyProductId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Account" A on A."AccountId"=ph."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacyWareHouse" PWH on PWH."PharmacyWareHouseId" = PH."PharmacyWareHouseId"
left join "PharmacyPurchaseReturnHeader" pr on pr."PharmacyPurchaseHeaderId" = PH."PharmacyPurchaseHeaderId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end and
case when "productName" is null then 1=1 else pp."ProductName" ilike '%' || "productName" ||'%' end
and case when "fromDate" is null then 1=1 else PH."BillDate"::date >= "fromDate" end
and case when "toDate" is null then 1=1 else PH."BillDate"::date <= "toDate" end and
case when "locationId" is null then 1=1 else coalesce(PWH."LocationId",PWH."CentralWarehouseLocationId") = "locationId"::int end
group by PP."ProductName",PP."GenericName",ci."Name",PPD."PurchaseRate",PPD."Quantity",PPD."Mrp",PPD."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",PH."CreatedDate", ppd."NetAmount",S."Name",
A."FullName" ,R."RoleName"
union
select PP."ProductName",PP."GenericName",ci."Name" "CategoryName",PPD."PurchaseRate",
PrD."ReturnQuantity" "Quantity",PPD."Mrp",PrD."TaxAmount", PH."PharmacyPurchaseHeaderId" ,PH."BillNumber",PH."BillType",prh."CreatedDate" "BillDate",A."FullName"
"CreatedByName",R."RoleName" "Role",S."Name" "SupplierName", -prd."NetAmount" "Netamount",false "PharmacyBillType"
from "PharmacyPurchaseReturnHeader" prh
join "Account" A on A."AccountId"=prh."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
Join "PharmacyPurchaseHeader" ph on ph."PharmacyPurchaseHeaderId"= prh."PharmacyPurchaseHeaderId"
join "PharmacyWareHouse" PWH on PWH."PharmacyWareHouseId" = ph."PharmacyWareHouseId"
join "PharmacyPurchaseDetail" ppd on ppd."PharmacyPurchaseHeaderId" = ph."PharmacyPurchaseHeaderId"
join "PharmacyProduct" pp on pp."PharmacyProductId" = ppd."PharmacyProductId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Supplier" s on s."SupplierId"=ph."SupplierId"
join "PharmacyPurchaseReturnDetail" prd on prh."PharmacyPurchaseReturnHeaderId"= prd."PharmacyPurchaseReturnHeaderId"
and ppd."PharmacyProductId"=prd."PharmacyProductId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "supplierName" is null then 1=1 else S."Name" ilike '%' || "supplierName" ||'%' end and
case when "productName" is null then 1=1 else pp."ProductName" ilike '%' || "productName" ||'%' end
and case when "fromDate" is null then 1=1 else PH."BillDate"::date >= "fromDate" end
and case when "toDate" is null then 1=1 else PH."BillDate"::date <= "toDate" end and
case when "locationId" is null then 1=1 else coalesce(PWH."LocationId",PWH."CentralWarehouseLocationId") = "locationId"::int end
group by PP."ProductName",PP."GenericName",ci."Name",PPD."PurchaseRate",PrD."ReturnQuantity",PPD."Mrp",PrD."TaxAmount",PH."PharmacyPurchaseHeaderId" ,
PH."BillNumber",PH."BillType",prh."CreatedDate",A."FullName"
,R."RoleName" ,S."Name" , prd."NetAmount"
) Ph
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end
order by PH."BillDate" desc, PH."PharmacyPurchaseHeaderId";
END
$BODY$;
ALTER FUNCTION public."udf_ProductPurchaseReport"(text, text, integer, text, text, date, date, boolean, text)
OWNER TO postgres;
\ No newline at end of file
-- FUNCTION: public.udf_emloyee_new_revenue(integer, integer, integer, date, date)
-- DROP FUNCTION public.udf_emloyee_new_revenue(integer, integer, integer, date, date);
CREATE OR REPLACE FUNCTION public.udf_emloyee_new_revenue(
accountid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer,
roleid integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date)
RETURNS TABLE("AccountId" integer, "EmployeeName" text, "RoleName" character varying, "AppointmentCashTotal" numeric, "AppointmentCardTotal" numeric, "AppointmentUPITotal" numeric, "AppointmentOnlineTotal" numeric, "AppointmentChequeTotal" numeric, "AppointmentPaytmTotal" numeric, "AppointmentAmount" numeric, "AdmissionCashTotal" numeric, "AdmissionCardTotal" numeric, "AdmissionUPITotal" numeric, "AdmissionOnlineTotal" numeric, "AdmissionChequeTotal" numeric, "AdmissionPaytmTotal" numeric, "AdmissionAmount" numeric, "LabCash" numeric, "LabCard" numeric, "LabUPI" numeric, "LabOnline" numeric, "LabCheque" numeric, "LabPaytm" numeric, "LabAmount" numeric, "PharmacySaleCash" numeric, "PharmacySaleCard" numeric, "PharmacySaleUPI" numeric, "PharmacySaleOnline" numeric, "PharmacySaleCheque" numeric, "PharmacySalePaytm" numeric, "PharmacyAmount" numeric, "TotalCash" numeric, "TotalCard" numeric, "TotalUPI" numeric, "TotalOnline" numeric, "TotalCheque" numeric, "TotalPaytm" numeric, "Total" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" and rol."RoleName"<>'Patient'
where case when accountid is null then 1=1 else a."AccountId"=accountid end
and case when roleid is null then 1=1 else a."RoleId"=roleid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
)
,actappointmentamount as (
select a."AccountId",sum(A."CashTotal") "AppointmentCashTotal",sum(A."CardTotal") "AppointmentCardTotal",
sum(A."UPITotal") "AppointmentUPITotal",sum(A."OnlineTotal") "AppointmentOnlineTotal",
sum(A."ChequeTotal") "AppointmentChequeTotal",sum(A."PaytmTotal") "AppointmentPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") appointmentamount
from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal",
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end and A."ReceiptTypeId"=1
and A."Active"<>false and A."AppointmentId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) <>true and ap."Status" <> 'C' and
case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
)a
group by a."AccountId"
)
,refundappointmentamount as (
select a."AccountId" ,sum(A."CashTotal") "AppointmentRefCashTotal",sum(A."CardTotal") "AppointmentRefCardTotal",
sum(A."UPITotal") "AppointmentRefUPITotal",sum(A."OnlineTotal") "AppointmentRefOnlineTotal",
sum(A."ChequeTotal") "AppointmentRefChequeTotal",sum(A."PaytmTotal") "AppointmentRefPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") refappointmentamount
from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal" ,
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."AppointmentId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Status" <> 'C' and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end
and A."Active"<>false and A."AppointmentId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) = true and
case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
) a
group by a."AccountId"
)
,appointmentamount as (
select A."AccountId",
coalesce(A."AppointmentCashTotal",0) - coalesce(B."AppointmentRefCashTotal",0) as "AppointmentCashTotal" ,
coalesce(A."AppointmentCardTotal",0) - coalesce(B."AppointmentRefCardTotal",0) as "AppointmentCardTotal" ,
coalesce(A."AppointmentUPITotal",0) - coalesce(B."AppointmentRefUPITotal",0) as "AppointmentUPITotal" ,
coalesce(A."AppointmentOnlineTotal",0) - coalesce(B."AppointmentRefOnlineTotal",0) as "AppointmentOnlineTotal" ,
coalesce(A."AppointmentChequeTotal",0) - coalesce(B."AppointmentRefChequeTotal",0) as "AppointmentChequeTotal" ,
coalesce(A."AppointmentPaytmTotal",0) - coalesce(B."AppointmentRefPaytmTotal",0) as "AppointmentPaytmTotal" ,
coalesce(A.appointmentamount,0) - coalesce(B.refappointmentamount,0) as "AppointmentAmount" from actappointmentamount A
left join refundappointmentamount B on A."AccountId"=B."AccountId"
)
,actadmissionamount as (
select a."AccountId" , sum(A."CashTotal") "AdmissionCashTotal",sum(A."CardTotal") "AdmissionCardTotal",
sum(A."UPITotal") "AdmissionUPITotal",sum(A."OnlineTotal") "AdmissionOnlineTotal",
sum(A."ChequeTotal") "AdmissionChequeTotal",sum(A."PaytmTotal") "AdmissionPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") "AdmissionAmount"
from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal" ,
case when adr."PayTypeId"=3 then coalesce(adr."Cost",0) else 0 end "UPITotal" ,
case when adr."PayTypeId"=4 then coalesce(adr."Cost",0) else 0 end "OnlineTotal" ,
case when adr."PayTypeId"=5 then coalesce(adr."Cost",0) else 0 end "ChequeTotal" ,
case when adr."PayTypeId"=6 then coalesce(adr."Cost",0) else 0 end "PaytmTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate"::date >= "fromDate" and adr."CreatedDate"::date <= "toDate") end )a
group by a."AccountId"
)
,refadmissionamount as (
select a."AccountId" , sum(A."CashTotal") "AdmissionRefCashTotal",sum(A."CardTotal") "AdmissionRefCardTotal",
sum(A."UPITotal") "AdmissionRefUPITotal",sum(A."OnlineTotal") "AdmissionRefOnlineTotal",
sum(A."ChequeTotal") "AdmissionRefChequeTotal",sum(A."PaytmTotal") "AdmissionRefPaytmTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal") "AdmissionRefAmount"
from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal" ,
case when adr."PayTypeId"=3 then coalesce(adr."Cost",0) else 0 end "UPITotal" ,
case when adr."PayTypeId"=4 then coalesce(adr."Cost",0) else 0 end "OnlineTotal" ,
case when adr."PayTypeId"=5 then coalesce(adr."Cost",0) else 0 end "ChequeTotal" ,
case when adr."PayTypeId"=6 then coalesce(adr."Cost",0) else 0 end "PaytmTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate"::date >= "fromDate" and adr."CreatedDate"::date <= "toDate") end )a
group by a."AccountId"
)
,admissionamount as (
select A."AccountId" ,
coalesce(A."AdmissionCashTotal",0) - coalesce(B."AdmissionRefCashTotal",0) "AdmissionCashTotal",
coalesce(A."AdmissionCardTotal",0) - coalesce(B."AdmissionRefCardTotal",0) "AdmissionCardTotal",
coalesce(A."AdmissionUPITotal",0) - coalesce(B."AdmissionRefUPITotal",0) "AdmissionUPITotal",
coalesce(A."AdmissionOnlineTotal",0) - coalesce(B."AdmissionRefOnlineTotal",0) "AdmissionOnlineTotal",
coalesce(A."AdmissionChequeTotal",0) - coalesce(B."AdmissionRefChequeTotal",0) "AdmissionChequeTotal",
coalesce(A."AdmissionPaytmTotal",0) - coalesce(B."AdmissionRefPaytmTotal",0) "AdmissionPaytmTotal",
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A
left join refadmissionamount B on A."AccountId"=B."AccountId"
)
,LabAmount as (
select a."AccountId",sum(a."Cash") "LabCash",sum(a."Card") "LabCard" ,
sum(a."UPI") "LabUPI",sum(a."Online") "LabOnline" ,
sum(a."Cheque") "LabCheque",sum(a."Paytm") "LabPaytm" ,
sum(a."Cash")+sum(a."Card")+sum(a."UPI")+sum(a."Online")+sum(a."Cheque")+sum(a."Paytm")"LabAmount"
from(
select a."AccountId",
case when ar."PayTypeId"=1 then coalesce(ar."NetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(ar."NetAmount",0) else 0 end "Card"
,case when ar."PayTypeId"=3 then coalesce(ar."NetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(ar."NetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(ar."NetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(ar."NetAmount",0) else 0 end "Paytm"
from "Account" a
join "LabBookingHeader" ar on ar."CreatedBy" = a."AccountId" and ar."Active" <> false
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."CreatedDate"::date >= "fromDate" and ar."CreatedDate"::date <= "toDate") end)a
group by a."AccountId" )
,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 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"
,case when ar."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm"
from "Account" a
join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."SaleDate"::date >= "fromDate" and ar."SaleDate"::date <= "toDate") 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
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when accountid is null then 1=1 else ar."CreatedBy"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."ReturnDate"::date >= "fromDate" and ar."ReturnDate"::date <= "toDate") 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."PharmaSaleUPI",0) - coalesce(b."PharmaReturnUPI",0) as "PharmaSaleUPI" ,
coalesce(a."PharmaSaleOnline",0) - coalesce(b."PharmaReturnOnline",0) as "PharmaSaleOnline" ,
coalesce(a."PharmaSaleCheque",0) - coalesce(b."PharmaReturnCheque",0) as "PharmaSaleCheque" ,
coalesce(a."PharmaSalePaytm",0) - coalesce(b."PharmaReturnPaytm",0) as "PharmaSalePaytm" ,
coalesce(a."PharmaSaleAmount",0) - coalesce(b."PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct a."AccountId",a."EmployeeName",a."RoleName",
ap."AppointmentCashTotal",ap."AppointmentCardTotal",ap."AppointmentUPITotal",ap."AppointmentOnlineTotal",ap."AppointmentChequeTotal",ap."AppointmentPaytmTotal"
,ap."AppointmentAmount",
ad."AdmissionCashTotal",ad."AdmissionCardTotal",ad."AdmissionUPITotal",ad."AdmissionOnlineTotal",ad."AdmissionChequeTotal",ad."AdmissionPaytmTotal"
,ad."AdmissionAmount",
lb."LabCash", lb."LabCard",lb."LabUPI", lb."LabOnline",lb."LabCheque", lb."LabPaytm"
,lb."LabAmount",
sum(pa."PharmaSaleCash") over(partition by a."AccountId") "PharmacySaleCash",
sum(pa."PharmaSaleCard") over(partition by a."AccountId") "PharmacySaleCard",
sum(pa."PharmaSaleUPI") over(partition by a."AccountId") "PharmacySaleUPI",
sum(pa."PharmaSaleOnline") over(partition by a."AccountId") "PharmacySaleOnline",
sum(pa."PharmaSaleCheque") over(partition by a."AccountId") "PharmacySaleCheque",
sum(pa."PharmaSalePaytm") over(partition by a."AccountId") "PharmacySalePaytm",
sum(pa."PharmaAmount") over(partition by a."AccountId") "PharmacyAmount",
coalesce(ap."AppointmentCashTotal",0)+ coalesce(ad."AdmissionCashTotal",0)+coalesce(lb."LabCash",0)+coalesce(sum(pa."PharmaSaleCash") over(partition by a."AccountId") ,0) "TotalCash",
coalesce(ap."AppointmentCardTotal",0)+ coalesce(ad."AdmissionCardTotal",0)+coalesce(lb."LabCard",0)+coalesce(sum(pa."PharmaSaleCard") over(partition by a."AccountId"),0) "TotalCard",
coalesce(ap."AppointmentUPITotal",0)+ coalesce(ad."AdmissionUPITotal",0)+coalesce(lb."LabUPI",0)+coalesce(sum(pa."PharmaSaleUPI") over(partition by a."AccountId") ,0) "TotalUPI",
coalesce(ap."AppointmentOnlineTotal",0)+ coalesce(ad."AdmissionOnlineTotal",0)+coalesce(lb."LabOnline",0)+coalesce(sum(pa."PharmaSaleOnline") over(partition by a."AccountId"),0) "TotalOnline",
coalesce(ap."AppointmentChequeTotal",0)+ coalesce(ad."AdmissionChequeTotal",0)+coalesce(lb."LabCheque",0)+coalesce(sum(pa."PharmaSaleCheque") over(partition by a."AccountId") ,0) "TotalCheque",
coalesce(ap."AppointmentPaytmTotal",0)+ coalesce(ad."AdmissionPaytmTotal",0)+coalesce(lb."LabPaytm",0)+coalesce(sum(pa."PharmaSalePaytm") over(partition by a."AccountId"),0) "TotalPaytm",
coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(partition by a."AccountId"),0) "Total"
from accountdata a
left join appointmentamount ap on ap."AccountId"=a."AccountId"
left join admissionamount ad on ad."AccountId"=a."AccountId"
left join LabAmount lb on lb."AccountId"=a."AccountId"
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
--ALTER FUNCTION public.udf_emloyee_new_revenue(integer, integer, integer, date, date)
-- OWNER TO postgres;
--
\ No newline at end of file
-----------------------------------------
--delete/drop all the function named -> "udf_uiReport_fetch_Appointments_Location"
-----------create ----------
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[],
"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)
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"
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
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."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
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"
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."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], integer, integer)
OWNER TO postgres;
CREATE SEQUENCE IF NOT EXISTS public."UserExcelHistory_UserExcelHistoryId_seq";
-- Table: public.UserExcelHistory
-- DROP TABLE IF EXISTS public."UserExcelHistory";
CREATE TABLE IF NOT EXISTS public."UserExcelHistory"
(
"UserExcelHistoryId" integer NOT NULL DEFAULT nextval('"UserExcelHistory_UserExcelHistoryId_seq"'::regclass),
"SheetName" text COLLATE pg_catalog."default",
"UploadedBy" integer,
"CreatedDate" timestamp without time zone,
"LocationId" integer,
"AddedUsers" text COLLATE pg_catalog."default",
CONSTRAINT "UserExcelHistory_pkey" PRIMARY KEY ("UserExcelHistoryId"),
CONSTRAINT "UserExcelHistory_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "UserExcelHistory_UploadedBy_fkey" FOREIGN KEY ("UploadedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."UserExcelHistory"
OWNER to postgres;
\ No newline at end of file
-- FUNCTION: public.udf_provider_availability_visitType1(integer, integer, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_provider_availability_visitType1"(integer, integer, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_provider_availability_visitType1"(
providerid integer,
specializationid integer,
locationid integer,
visittypeid integer)
RETURNS TABLE("ProviderAvailabilityVisitTypeId" integer, "VisitTypeId" integer, "VisitorName" character varying, "Duration" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
IF EXISTS (select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."ProviderId" = providerid and PA."SpecializationId" = specializationid and PA."LocationId" = locationid
AND PA."VisitTypeId" = visittypeid
) THEN return query select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."ProviderId" = providerid and PA."SpecializationId" = specializationid and PA."LocationId" = locationid
AND PA."VisitTypeId" = visittypeid;
--END IF; 1
ELSEIF EXISTS (select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."SpecializationId" = specializationid and PA."LocationId" = locationid and PA."ProviderId" is null
AND PA."VisitTypeId" = visittypeid
) THEN return query select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."SpecializationId" = specializationid and PA."LocationId" = locationid and PA."ProviderId" is null
AND PA."VisitTypeId" = visittypeid;
--END IF; 2
ELSEIF EXISTS (select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."ProviderId" = providerid and PA."LocationId" = locationid and PA."SpecializationId" is null
AND PA."VisitTypeId" = visittypeid
) THEN return query select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."ProviderId" = providerid and PA."LocationId" = locationid and PA."SpecializationId" is null
AND PA."VisitTypeId" = visittypeid;
--END IF; 3
ELSEIF EXISTS (select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."LocationId" = locationid and PA."SpecializationId" is null and PA."ProviderId" is null
AND PA."VisitTypeId" = visittypeid
) THEN return query select PA."ProviderAvailabilityVisitTypeId", PA."VisitTypeId", CT."VisitorName",PA."Duration"
FROM "ProviderAvailabilityVisitType" PA
JOIN "VisitType" CT ON CT."VisitTypeId" = PA."VisitTypeId"
where PA."LocationId" = locationid and PA."SpecializationId" is null and PA."ProviderId" is null
AND PA."VisitTypeId" = visittypeid;
END IF; -- 1
end
$BODY$;
ALTER FUNCTION public."udf_provider_availability_visitType1"(integer, integer, integer, integer)
OWNER TO postgres;
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