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 "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$
;
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