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

initial commit

parent 3a1ccff9
ALTER TABLE public."Admission"
ADD COLUMN "CounsellingId" integer;
ALTER TABLE public."Admission"
ADD CONSTRAINT "FK_Admission_CounsellingId" FOREIGN KEY ("CounsellingId")
REFERENCES public."Counselling" ("CounsellingId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
create table "CallHistory" (
"Id" SERIAL PRIMARY KEY,
"MobileNumber" VARCHAR,
"FirstName" VARCHAR,
"LastName" VARCHAR,
"Comments" VARCHAR,
"CallStart" text,
"CallEnd" text,
"CallDuration" text,
"Status" boolean,
"Type" integer,
"CreatedDate" timestamp without time zone,
"CreatedBy" integer,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"IsActive" boolean NOT NULL
);
\ No newline at end of file
create table "ContactDetails" (
"Id" SERIAL PRIMARY KEY,
"Details" text,
"PatientId" integer,
"Type" integer,
"CreatedDate" timestamp without time zone,
"CreatedBy" integer,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"IsActive" boolean NOT NULL
);
\ No newline at end of file
create table "FeedbackDetails" (
"Id" SERIAL PRIMARY KEY,
"MobileNumber" VARCHAR,
"PatientName" VARCHAR,
"Rating" integer,
"Comments" VARCHAR,
"Type" integer,
"CreatedDate" timestamp without time zone,
"CreatedBy" integer,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"IsActive" boolean NOT NULL
);
\ No newline at end of file
INSERT INTO "HowDidYouKnow"("Name", "Active", "CreatedBy","CreatedDate")
VALUES ('CALL CENTER', 'true', '6776', '2022-11-28 00:00:00' );
\ No newline at end of file
Alter table "FinalBillServiceOrder" add column "PackageModuleId" integer;
ALTER TABLE public."FinalBillServiceOrder"
ADD CONSTRAINT "FK_FinalBillServiceOrder_PackageModuleId" FOREIGN KEY ("PackageModuleId")
REFERENCES public."PackageModule" ("PackageModuleId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
\ No newline at end of file
-- ----------------------------
-- Table structure for MenuButton
-- ----------------------------
DROP TABLE IF EXISTS "public"."MenuButton";
CREATE SEQUENCE "MenuButton_MenuButtonId_seq";
CREATE TABLE "public"."MenuButton" (
"MenuButtonId" int4 NOT NULL DEFAULT nextval('"MenuButton_MenuButtonId_seq"'::regclass),
"Code" varchar(6) COLLATE "pg_catalog"."default" NOT NULL,
"Name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
"MenuId" int4 NOT NULL
)
;
ALTER TABLE "public"."MenuButton" OWNER TO "postgres";
-- ----------------------------
-- Primary Key structure for table MenuButton
-- ----------------------------
ALTER TABLE "public"."MenuButton" ADD CONSTRAINT "MenuButton_pkey" PRIMARY KEY ("MenuButtonId");
-- ----------------------------
-- Foreign Keys structure for table MenuButton
-- ----------------------------
ALTER TABLE "public"."MenuButton" ADD CONSTRAINT "FK_MenuButton_MenuId" FOREIGN KEY ("MenuId") REFERENCES "public"."Menu" ("MenuId") ON DELETE NO ACTION ON UPDATE NO ACTION;
-- ----------------------------
-- Table structure for MenuButtonRelationship
-- ----------------------------
DROP TABLE IF EXISTS "public"."MenuButtonRelationship";
CREATE SEQUENCE "MenuButtonRelationship_MenuButtonRelationshipId_seq";
CREATE TABLE "public"."MenuButtonRelationship" (
"MenuButtonRelationshipId" int4 NOT NULL DEFAULT nextval('"MenuButtonRelationship_MenuButtonRelationshipId_seq"'::regclass),
"RoleId" int4 NOT NULL,
"MenuButtonId" int4 NOT NULL
)
;
ALTER TABLE "public"."MenuButtonRelationship" OWNER TO "postgres";
-- ----------------------------
-- Primary Key structure for table MenuButtonRelationship
-- ----------------------------
ALTER TABLE "public"."MenuButtonRelationship" ADD CONSTRAINT "MenuButtonRelationship_pkey" PRIMARY KEY ("MenuButtonRelationshipId");
-- ----------------------------
-- Foreign Keys structure for table MenuButtonRelationship
-- ----------------------------
ALTER TABLE "public"."MenuButtonRelationship" ADD CONSTRAINT "FK_MenuButton_MenuButtonId" FOREIGN KEY ("MenuButtonId") REFERENCES "public"."MenuButton" ("MenuButtonId") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."MenuButtonRelationship" ADD CONSTRAINT "FK_MenuButton_RoleId" FOREIGN KEY ("RoleId") REFERENCES "public"."Role" ("RoleId") ON DELETE NO ACTION ON UPDATE NO ACTION;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "AdmissionPackageId";
ALTER TABLE IF EXISTS public."ServiceOrder"
ADD COLUMN "AdmissionPackageId" integer;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "PackageModuleDetailId";
ALTER TABLE IF EXISTS public."ServiceOrder"
ADD COLUMN "PackageModuleDetailId" integer;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "UsedQuantity";
ALTER TABLE IF EXISTS public."ServiceOrder"
ADD COLUMN "UsedQuantity" integer;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "UsedCost";
ALTER TABLE IF EXISTS public."ServiceOrder"
ADD COLUMN "UsedCost" numeric(10,2);
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP CONSTRAINT IF EXISTS "FK_ServiceOrder_AdmissionPackageId";
ALTER TABLE IF EXISTS public."ServiceOrder"
ADD CONSTRAINT "FK_ServiceOrder_AdmissionPackageId" FOREIGN KEY ("AdmissionPackageId")
REFERENCES public."AdmissionPackage" ("AdmissionPackageId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP CONSTRAINT IF EXISTS "FK_ServiceOrder_PackageModuleDetailId";
ALTER TABLE IF EXISTS public."ServiceOrder"
ADD CONSTRAINT "FK_ServiceOrder_PackageModuleDetailId" FOREIGN KEY ("PackageModuleDetailId")
REFERENCES public."PackageModuleDetail" ("PackageModuleDetailId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
\ No newline at end of file
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "AdmissionPackageId";
ALTER TABLE IF EXISTS public."LabServices"
ADD COLUMN "AdmissionPackageId" integer;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "PackageModuleDetailId";
ALTER TABLE IF EXISTS public."LabServices"
ADD COLUMN "PackageModuleDetailId" integer;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "UsedQuantity";
ALTER TABLE IF EXISTS public."LabServices"
ADD COLUMN "UsedQuantity" integer;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP COLUMN IF EXISTS "UsedCost";
ALTER TABLE IF EXISTS public."LabServices"
ADD COLUMN "UsedCost" numeric(10,2);
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP CONSTRAINT IF EXISTS "FK_ServiceOrder_AdmissionPackageId";
ALTER TABLE IF EXISTS public."LabServices"
ADD CONSTRAINT "FK_LabServices_AdmissionPackageId" FOREIGN KEY ("AdmissionPackageId")
REFERENCES public."AdmissionPackage" ("AdmissionPackageId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
-- ALTER TABLE IF EXISTS public."ServiceOrder" DROP CONSTRAINT IF EXISTS "FK_ServiceOrder_PackageModuleDetailId";
ALTER TABLE IF EXISTS public."LabServices"
ADD CONSTRAINT "FK_LabServices_PackageModuleDetailId" FOREIGN KEY ("PackageModuleDetailId")
REFERENCES public."PackageModuleDetail" ("PackageModuleDetailId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
\ No newline at end of file
----ran this query in QA, UAT, IVF------
INSERT INTO public."Settings"(
"Name", "Active", "Type", "Value", "ImageUrl", "Description", "Numeral")
VALUES ( 'AppointmentReschedule', true, 'Appointment', null, null, 'Choose to Enable/Disable the reschedule button in mobile applications and patient web application.', null);
INSERT INTO public."Settings"(
"Name", "Active", "Type", "Value", "ImageUrl", "Description", "Numeral")
VALUES ( 'AppointmentCancel', true, 'Appointment', null, null, 'Choose to enable/disable Appointment Cancel Buttion for mobile applications and patient web application', null);
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
CREATE SEQUENCE IF NOT EXISTS public."GatePassType_Seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-------------------------
CREATE TABLE IF NOT EXISTS public."GatePassType"
(
"GatePassTypeId" integer NOT NULL DEFAULT nextval('"GatePassType_Seq"'::regclass),
"Name" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "GatePassType_pkey" PRIMARY KEY ("GatePassTypeId")
)
TABLESPACE pg_default;
----------------------------------
insert into "GatePassType"("Name","Active") values('Provisional',true);
insert into "GatePassType"("Name","Active") values('Final',true);
---------------------------------
ALTER TABLE "GatePass"
ADD COLUMN "TypeId" integer not null DEFAULT 2;
ALTER TABLE "GatePass"
ADD CONSTRAINT "FK_GatePass_TypeId" FOREIGN KEY ("TypeId")
REFERENCES public."GatePassType" ("GatePassTypeId") ;
--------------------------------------------
alter table "BookScanAppointment"
add column "ProviderId" integer Null,
ADD CONSTRAINT "FK_BookScanAppointment_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") ;
\ No newline at end of file
alter table public."PharmacyProduct" drop column if exists "MaxQuantity",
drop column if exists "MinQuantity",drop column if exists "RolQuantity",
drop column if exists "RackId",drop column if exists "Pharmacy_Source";
alter table public."PharmacyProduct" add column if not exists "Potency" text,
add column if not exists "DrugRiskId" int references "LookupValue"("LookupValueId"),
add column if not exists "Dosage" text,add column if not exists "Formula" text,
add column if not exists "NABHCategoryId" int references "LookupValue"("LookupValueId"),
add column if not exists "DosageTypeId" int references "LookupValue"("LookupValueId"),
add column if not exists "Strength" text,add column if not exists "FixedDose" numeric,
add column if not exists "MedFrequencyMasterId" int references public."MedFrequencyMaster"("MedFrequencyMasterId"),
add column if not exists "NoOfTimes" int,add column if not exists "SaleLoose" boolean,
add column if not exists "InventoryExpiry" int,add column if not exists "FormulationId" int references "LookupValue"("LookupValueId"),
add column if not exists "MedRouteId" int references "LookupValue"("LookupValueId");
insert into "Lookup" ("Name","Description")
values
('PharmacyDrugRisk', 'For pharmacy drug risks');
insert into "LookupValue" ("LookupId","Name","CreatedBy", "CreatedDate")
values
((select "LookupId" from "Lookup" where "Name"= 'PharmacyDrugRisk'),'Low Risk',1029, now()),
((select "LookupId" from "Lookup" where "Name"= 'PharmacyDrugRisk'),'Medium Risk',1029, now()),
((select "LookupId" from "Lookup" where "Name"= 'PharmacyDrugRisk'),'High Risk',1029, now());
insert into "Lookup" ("Name","Description")
values
('NABHCategory', 'For NABH Authority');
insert into "LookupValue" ("LookupId","Name","CreatedBy", "CreatedDate")
values
((select "LookupId" from "Lookup" where "Name"= 'NABHCategory'),'Vital',1029, now()),
((select "LookupId" from "Lookup" where "Name"= 'NABHCategory'),'Essential',1029, now()),
((select "LookupId" from "Lookup" where "Name"= 'NABHCategory'),'Desirable',1029, now());
insert into "Lookup" ("Name","Description")
values
('PharmacyDosageType', 'To set dose for pharmacy product');
insert into "LookupValue" ("LookupId","Name","CreatedBy", "CreatedDate")
values
((select "LookupId" from "Lookup" where "Name"= 'PharmacyDosageType'),'Regular Items',1029, now()),
((select "LookupId" from "Lookup" where "Name"= 'PharmacyDosageType'),'Weight Wise',1029, now()),
((select "LookupId" from "Lookup" where "Name"= 'PharmacyDosageType'),'Age Wise',1029, now());
insert into "Lookup" ("Name","Description")
values
('PharmacyFormulation', 'To set formulation for pharmacy product');
alter table public."PharmacyProduct" add column if not exists "AlchoholInteraction" text,
add column if not exists "PregnancyInteraction" text,
add column if not exists "ExpertAdvice" text,
add column if not exists "CommonSideEffects" text,
add column if not exists "MedicineFaq" text,
add column if not exists "MedicineInteraction" text,
add column if not exists "Usage" text;
create table public."VaccineAgeGroup"(
"VaccineAgeGroupId" serial primary key,
"AgeGroupName" text
);
insert into public."VaccineAgeGroup"( "AgeGroupName")
values
('At Birth'),
('1 to 6 Weeks'),
('7 to 10 Weeks'),
('3 to 4 Months'),
('5 to 6 Months'),
('7 to 8 Months'),
('8 to 9 Months'),
('10 to 11 Months'),
('12 to 13 Months'),
('13 to 15 Months'),
('16 to 17 Months'),
('17 to 18 Months'),
('2 to 4 Years'),
('4 to 6 Years'),
('6 to 9 Years'),
('10 to 12 Years'),
('12 to 18 Years'),
('18 to 100 Years');
alter table public."VaccineMaster" add column if not exists "VaccineAgeGroupId" int references "VaccineAgeGroup"("VaccineAgeGroupId");
drop table "VaccineMasterPharmacyLink" ;
create table public."VaccinePharmacyLinkHeader"(
"VaccinePharmacyLinkHeaderId" serial primary key,
"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
create table public."VaccinePharmacyLinkDetail"(
"VaccinePharmacyLinkDetailId" serial primary key,
"VaccinePharmacyLinkHeaderId" int references "VaccinePharmacyLinkHeader"("VaccinePharmacyLinkHeaderId"),
"VaccineMasterId" int references "VaccineMaster"("VaccineMasterId")
);
create table public."ImmunizationHistory"(
"ImmunizationHistoryId" serial primary key,
"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"VaccineMasterId" int references "VaccineMaster"("VaccineMasterId"),
"ProductName" text,
"BillNumber" varchar(300),
"BatchNumber" varchar(300),
"ExpiryDate" date,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone
);
alter table public."ImmunizationHistory" add column if not exists
"Status" varchar(50);
alter table public."ImmunizationHistory" add column if not exists
"PatientId" int references "Patient"("PatientId");
alter table "ImmunizationHistory"
add column if not exists "VaccineGivenBy" int references "Account"("AccountId"),
add column if not exists "VaccineGivenDate" timestamp without time zone;
alter table "PediatricEncounter" add column if not exists "VaccineDetail" text;
UPDATE public."Menu"
SET "EncounterKey"='vaccineDetail'
where "Url"='/app/pediatric-encounter/:id/:type/immunization';
alter table "PediatricAgeWiseData"
add column if not exists "M" numeric,
add column if not exists "L" numeric,
add column if not exists "P999" numeric,
add column if not exists "P01" numeric,
add column if not exists "P10" numeric,
add column if not exists "P90" numeric,
add column if not exists "S" numeric,
add column if not exists "Minus3SD" numeric,
add column if not exists "Minus2SD" numeric,
add column if not exists "Minus1SD" numeric,
add column if not exists "Median" numeric,
add column if not exists "1SD" numeric,
add column if not exists "2SD" numeric,
add column if not exists "3SD" numeric;
create table vendors."SupplierProductHeader"(
"SupplierProductHeaderId" serial primary key,
"SupplierId" int references "Supplier"("SupplierId"),
"StartDate" timestamp without time zone,
"EndDate" timestamp without time zone,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
create table vendors."SupplierProductFormulation"(
"SupplierProductFormulationId" serial primary key,
"SupplierProductHeaderId" int references vendors."SupplierProductHeader"("SupplierProductHeaderId"),
"Operator" varchar(50),
"Condition" varchar(50),
"FOCQuantity" int
);
CREATE TABLE if not exists vendors."SupplierProductDetail" (
"SupplierProductDetailId" serial primary key,
"SupplierProductHeaderId" int ,
"PharmacyProductId" int ,
"PurchaseRate" numeric ,
"Mrp" numeric
);
ALTER TABLE vendors."SupplierProductDetail" ADD CONSTRAINT if not exists "SupplierProductDetail_PharmacyProductId_fkey" FOREIGN KEY ("PharmacyProductId") REFERENCES public."PharmacyProduct"("PharmacyProductId");
ALTER TABLE vendors."SupplierProductDetail" ADD CONSTRAINT if not exists "SupplierProductDetail_SupplierProductHeaderId_fkey" FOREIGN KEY ("SupplierProductHeaderId") REFERENCES vendors."SupplierProductHeader"("SupplierProductHeaderId");
alter table vendors."PharmacyProductApproval" add column if not exists "Free" int;
alter table vendors."PurchaseOrderDetail" add column if not exists "Free" int;
alter table public."PharmacyProduct" add column "InventoryItem" boolean default false;
create table public."PharmacyInPatientReturn"(
"PharmacyInPatientReturnId" bigserial primary key,
"PharmacyIssueDetailId" int references "PharmacyIssueDetail"("PharmacyIssueDetailId"),
"ReturnQuantity" int,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"AcceptedBy" int references "Account"("AccountId"),
"AcceptedDate" timestamp without time zone
);
alter table "PharmacyIssueDetail" add column "PharmacyIndentDetailId" int references "PharmacyIndentDetail"("PharmacyIndentDetailId");
\ No newline at end of file
1. Keep all your development Queries into "1. QA" folder
2. Person who moved to QA run all the scripts from "1. QA" once done move those scripts to "2. Prod"
3. person who moved to prod run all the scripts from "2. Prod" once done move those scripts to "3. Complete"
ALTER TABLE "FinalBillServiceOrder" ADD COLUMN "Discount" numeric(10,2) DEFAULT 0;
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
DROP TABLE IF EXISTS vendors."PharmacyProductApproval";
CREATE TABLE vendors."PharmacyProductApproval" (
"PharmacyProductApprovalId" bigserial NOT NULL,
"PharmacyProductId" int4 NULL,
"PharmacyStockId" int4 NULL,
"PurchaseRate" numeric NULL,
"Mrp" numeric NULL,
"SupplierId" int4 NULL,
"TenderStatusId" int4 NULL,
"PharmacyProductRequestId" int4 NULL,
"CreatedBy" int4 NULL,
"CreatedDate" timestamp NULL,
CONSTRAINT "PharmacyProductApproval_pkey" PRIMARY KEY ("PharmacyProductApprovalId"),
CONSTRAINT "PharmacyProductApproval_CreatedBy_fkey" FOREIGN KEY ("CreatedBy") REFERENCES public."Account"("AccountId"),
CONSTRAINT "PharmacyProductApproval_PharmacyProductId_fkey" FOREIGN KEY ("PharmacyProductId") REFERENCES public."PharmacyProduct"("PharmacyProductId"),
CONSTRAINT "PharmacyProductApproval_PharmacyProductRequestId_fkey" FOREIGN KEY ("PharmacyProductRequestId") REFERENCES vendors."PharmacyProductRequest"("PharmacyProductRequestId"),
CONSTRAINT "PharmacyProductApproval_PharmacyStockId_fkey" FOREIGN KEY ("PharmacyStockId") REFERENCES public."PharmacyStock"("PharmacyStockId"),
CONSTRAINT "PharmacyProductApproval_SupplierId_fkey" FOREIGN KEY ("SupplierId") REFERENCES public."Supplier"("SupplierId"),
CONSTRAINT "PharmacyProductApproval_TenderStatusId_fkey" FOREIGN KEY ("TenderStatusId") REFERENCES vendors."TendorStatus"("TenderStatusId")
);
insert into vendors."TendorStatus" ("Status")
values ('Moved To Tender');
-------------
create table vendors."TenderRequestSupplierHeader"(
"TenderRequestSupplierHeaderId" bigserial primary key,
"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
"TenderRaisedBy" int references "Account"("AccountId"),
"SupplierId" int references "Supplier"("SupplierId"),
"TenderRaisedDate" timestamp without time zone,
"IsCompleteAccepted" boolean default false,
"AcceptedDate" timestamp without time zone,
"IsCompleteRejected" boolean default false,
"CompleteRejectedDate" timestamp without time zone ,
"CompleteRejectionComment" text
);
create table vendors."TenderRequestSupplierDetail"(
"TenderRequestSupplierDetailId" bigserial primary key,
"TenderRequestSupplierHeaderId" bigint references vendors."TenderRequestSupplierHeader"("TenderRequestSupplierHeaderId"),
"PharmacyProductApprovalId" bigint references vendors."PharmacyProductApproval"("PharmacyProductApprovalId"),
"VendorMrp" numeric,
"VendorPurchaseRate" numeric,
"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
"VendorRejected" boolean default false,
"VendorRejectedDate" timestamp without time zone,
"RejectionComment" text
);
-------
insert into vendors."TendorStatus" ("Status")
values ('Pending Vendor Acceptance');
insert into vendors."TendorStatus" ("Status")
values ('PO Sent');
-----------
\ No newline at end of file
insert into vendors."TendorStatus" ("Status") values
('VendorAccepted'),
('VendorRejected'),
('PartialAccepted');
create table "PharmacyProductType"(
"PharmacyProductTypeId" serial primary key,
"TypeName" text,
"Active" boolean,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
alter table "PharmacyProductType" add column "IsGeneralItem" boolean default false;
create table "PharmacyProductSubType"(
"PharmacyProductSubTypeId" serial primary key,
"PharmacyProductTypeId" int references "PharmacyProductType"("PharmacyProductTypeId"),
"SubTypeName" text,
"Active" boolean,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
alter table "PharmacyProduct" add column "StorageTypeId" int references "LookupValue"("LookupValueId"),
add column "PharmacyProductTypeId" int references "PharmacyProductType"("PharmacyProductTypeId"),
add column "PharmacyProductSubTypeId" int references "PharmacyProductSubType"("PharmacyProductSubTypeId");
alter table "PharmacyProduct"
add column "OnlyConsumable" boolean default false;
alter table vendors."TenderRequestSupplierDetail" add column if not exists "VendorQuantity" int;
create table if not exists vendors."IncomingQuotationHeader"(
"IncomingQuotationHeaderId" bigserial primary key,
"TenderRequestSupplierHeaderId" bigint references vendors."TenderRequestSupplierHeader"("TenderRequestSupplierHeaderId"),
"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
"DeliveryDate" date,
"RaisedBy" int references "Account"("AccountId"),
"RaisedDate" timestamp without time zone,
"ApprovedBy" int references "Account"("AccountId"),
"ApprovedDate" timestamp without time zone
);
create table if not exists vendors."IncomingQuotationDetail"(
"IncomingQuotationDetailId" bigserial primary key,
"IncomingQuotationHeaderId" bigint references vendors."IncomingQuotationHeader"("IncomingQuotationHeaderId"),
"TenderRequestSupplierDetailId" bigint references vendors."TenderRequestSupplierDetail"("TenderRequestSupplierDetailId")
);
alter table vendors."PharmacyProductRequest" drop column if exists "PharmacyStockId", drop column if exists "RolStocksId";
alter table vendors."PharmacyProductRequest" add column if not exists "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");
alter table vendors."PharmacyProductApproval" drop column if exists "PharmacyStockId";
alter table vendors."PharmacyProductApproval" add column if not exists "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");
alter table "Supplier" add column if not exists "DeliverDays" int ;
alter table vendors."PharmacyProductApproval" add column if not exists "Quantity" int;
create table vendors."PurchaseOrderHeader"(
"PurchaseOrderHeaderId" bigserial primary key,
"PONumber" varchar(250),
"PORaiseDate" timestamp without time zone,
"EstimatedDeliveryDate" date,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
"TotalAmount" numeric,
"TotalTax" numeric,
"TotalNetAmount" numeric,
"SupplierId" int references "Supplier"("SupplierId"),
"PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId")
);
create table vendors."PurchaseOrderDetail"(
"PurchaseOrderDetailId" bigserial primary key,
"PurchaseOrderHeaderId" bigint references vendors."PurchaseOrderHeader"("PurchaseOrderHeaderId"),
"PharmacyProductApprovalId" bigint references vendors."PharmacyProductApproval"("PharmacyProductApprovalId"),
"Quantity" int ,
"Amount" numeric,
"TaxAmount" numeric,
"NetAmount" numeric
);
alter table "PharmacyPurchaseHeader" add column "PurchaseOrderHeaderId" bigint references vendors."PurchaseOrderHeader"("PurchaseOrderHeaderId");
alter table "PharmacyPurchaseDetail" add column "PurchaseOrderDetailId" bigint references vendors."PurchaseOrderDetail"("PurchaseOrderDetailId");
insert into vendors."TendorStatus"("Status") values
('Partial PO'),
('Completed') ;
alter table vendors."PurchaseOrderDetail" add column if not exists "IsAddedByGrn" bool default false;
------------latest--------
insert into vendors."TendorStatus" ("Status") values ('Awaits Approval');
alter table vendors."PharmacyProductRequest"
add column if not exists "ApprovalGivenBy" int references "Account"("AccountId"),
add column if not exists "ApprovalGivenDate" timestamp without time zone;
--- 20 07 23
drop table if exists vendors."TenderRequestSupplierDetail" ;
drop table if exists vendors."TenderRequestSupplierHeader" ;
drop table if exists vendors."IncomingQuotationDetail" ;
drop table if exists vendors."IncomingQuotationHeader" ;
\ No newline at end of file
create table if not exists vendors."ProductForQuotationHeader"(
"ProductForQuotationHeaderId" bigserial primary key,
"QuotationNumber" text,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId")
);
create table if not exists vendors."ProductForQuotationDetail"(
"ProductForQuotationDetailId" bigserial primary key,
"PharmacyProductApprovalId" bigint references vendors."PharmacyProductApproval"("PharmacyProductApprovalId"),
"ProductForQuotationHeaderId" bigint references vendors."ProductForQuotationHeader"("ProductForQuotationHeaderId"),
"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId")
);
insert into vendors."TendorStatus" ("Status") values ('Waiting For Quotation');
\ No newline at end of file
drop table if exists vendors."IncomingQuotationDetail";
drop table if exists vendors."IncomingQuotationHeader";
------------
drop table if exists vendors."TenderRequestSupplierDetail";
drop table if exists vendors."TenderRequestSupplierHeader";
---------------------
create table if not exists vendors."IncomingQuotationHeader"(
"IncomingQuotationHeaderId" bigserial primary key,
"ProductForQuotationHeaderId" bigint references vendors."ProductForQuotationHeader",
"SupplierId" int references public."Supplier"("SupplierId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone,
"IsFinalized" boolean default false,
"FinalizedBy" int references "Account"("AccountId"),
"FinalizedDate" timestamp without time zone,
"DeliveryDate" date,
"TotalAmount" numeric,
"TotalTax" numeric,
"TotalNetAmount" numeric,
"TotalDiscount" numeric
);
create table if not exists vendors."IncomingQuotationDetail"(
"IncomingQuotationDetailId" bigserial primary key,
"PharmacyProductApprovalId" bigint references vendors."PharmacyProductApproval"("PharmacyProductApprovalId"),
"IncomingQuotationHeaderId" bigint references vendors."IncomingQuotationHeader"("IncomingQuotationHeaderId"),
"ProductForQuotationDetailId" bigint references vendors."ProductForQuotationDetail"("ProductForQuotationDetailId"),
"PharmacyProductId" int references public."PharmacyProduct"("PharmacyProductId"),
"Tax" int,
"PurchaseRate" numeric,
"MRP" numeric,
"Amount" numeric,
"TaxAmount" numeric,
"DiscountPercentage" numeric,
"DiscountAmount" numeric,
"NetAmount" numeric,
"Quantity" int,
"Free" int
);
----------
insert into vendors."TendorStatus" ("Status") values ('Quoatation Received');
alter table vendors."SupplierProductFormulation" drop column if exists "SupplierProductHeaderId";
alter table vendors."SupplierProductFormulation" add column if not exists "SupplierProductDetailId" int references vendors."SupplierProductDetail"("SupplierProductDetailId");
-----
alter table vendors."SupplierProductHeader" add column if not exists "RateCardUrl" text;
------
drop TABLE if exists public."InventoryRequest";
drop TABLE if exists public."CpxRelatedToDepartment";
drop TABLE if exists public."RequestDepartment";
drop TABLE if exists public."TicketType";
----------
create table vendors."InventoryProductRequest"(
"InventoryProductRequestId" serial primary key,
"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"RequestProductName" text,
"ReasonForRequest" text,
"RequestedQuantity" int,
"RequestType" varchar(50),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"PharmacyProductRequestId" bigint references vendors."PharmacyProductRequest"("PharmacyProductRequestId"),
"RejectedBy" int references "Account"("AccountId"),
"RejectedDate" timestamp without time zone,
"RejectReason" text
);
alter table vendors."InventoryProductRequest" add column if not exists "ModifiedBy" int references "Account"("AccountId"),
add column if not exists "ModifiedDate" timestamp without time zone,add column if not exists "DocumentUrl" text,
add column if not exists "LocationId" int references "Location"("LocationId");
alter table vendors."PharmacyProductRequest" add column if not exists "RequestedQuantity" int default null;
----
INSERT INTO vendors."TendorStatus" ("Status")
SELECT 'Quotation Selected' as "Status"
WHERE
NOT EXISTS (
SELECT "Status" FROM vendors."TendorStatus" WHERE "Status" = 'Quotation Selected'
);
-----
alter table vendors."PharmacyProductApproval" add column if not exists "ProductForQuotationHeaderId" bigint references vendors."ProductForQuotationHeader"("ProductForQuotationHeaderId");
alter table "MasterBill"
drop constraint "FK_Receipt_ModulesMasterId";
alter table "MasterBill"
add column if not exists "LocationId" integer null;
alter table "MasterBill"
add column if not exists "ReceiptAreaTypeId" integer null;
update "MasterBill"
set "ReceiptAreaTypeId"=1 where "ModulesMasterId"=6;
update "MasterBill"
set "ReceiptAreaTypeId"=3 where "ModulesMasterId"=17;
update "MasterBill"
set "ReceiptAreaTypeId"=4 where "ModulesMasterId"=16;
update "MasterBill"
set "ReceiptAreaTypeId"=10 where "ModulesMasterId"=2;
update "MasterBill"
set "ReceiptAreaTypeId"=8 where "ModulesMasterId"=1;
-----------------------------------------------------------------------------------------
DROP FUNCTION IF EXISTS public."Masterbills_AppointmentReports"(date, date, integer, integer);
CREATE OR REPLACE FUNCTION public."Masterbills_AppointmentReports"(
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
locationid integer DEFAULT NULL::integer,
moduleid integer DEFAULT NULL::integer)
RETURNS TABLE("BillNumber" character varying, "BillDate" timestamp without time zone, "BillStatusTypeId" integer, "BillStatus" character varying, "Total" numeric, "Discount" numeric, "NetTotal" numeric,"Rounding" numeric, "Receipts" text, "Receipts_Cost" text, "ReceiptSum" numeric, "ReceiptAreaTypeId" integer, "PatientName" text, "Mobile" character varying, "UMRNo" character varying, "ProviderName" character varying, "LocationId" integer, "ModuleName" character varying, "LocationName" character varying, "AppointmentNo" character varying, "AppointmentDate" timestamp without time zone,"OPConsultation" numeric,"ScanConsultation" numeric,"Lab" numeric,"Pharmacy" numeric,"RegistrationCharges" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with getreceipts as (
select MB."MasterBillId",MB."BillNumber",string_agg(R."ReceiptId"::text,',') AS "Receipts",
string_agg(R."Cost"::text,',') AS "Receipts_Cost",MB."ReceiptAreaTypeId",--MB."ModulesMasterId",
sum(R."Cost") as "ReceiptSum"
from "MasterBill" MB
join "Receipt" R on R."MasterBillId"=MB."MasterBillId"
group by (MB."MasterBillId")
--order by MB."BillNumber" asc
)
,appointment as(
select
distinct on (MB."MasterBillId")
MB."BillNumber",MB."MasterBillId",MB."BillDate",MB."BillStatusTypeId",BST."Name" as "BillStatus",
MB."Total",MB."Discount",MB."NetTotal",MB."Rounding",--GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",
P."FullName" as "PatientName",P."Mobile",P."UMRNo",pr."FullName" as "ProviderName",
AT."LocationId",MM."Name" as "ModuleName",L."Name" as "LocationName",
AP."AppointmentNo",AP."AppointmentDate"
FROM "MasterBill" MB
Join "Appointment" AP on AP."AppointmentId"=MB."ModuleId"
join "Provider" pr on pr."ProviderId"= AP."ProviderId"
join "BillStatusType" BST on BST."BillStatusTypeId"=MB."BillStatusTypeId"
join "Patient" P on P."PatientId"=MB."PatientId"
--join "ModulesMaster" MM on MM."ModulesMasterId"=MB."ModulesMasterId"
join "ReceiptAreaType" MM on MM."ReceiptAreaTypeId"=MB."ReceiptAreaTypeId"
join "AppointmentTransaction" AT on AT."AppointmentId"=AP."AppointmentId"-- and MB."ReceiptAreaTypeId"=4
join "Location" L on L."LocationId"=AT."LocationId"
where
case when "fromDate" is null then 1=1 else "fromDate"<= AP."AppointmentDate"::date end
and case when "toDate" is null then 1=1 else AP."AppointmentDate"::date<= "toDate" end
and case when "locationid" is null then 1=1 else AT."LocationId" = "locationid" end
)
,lab as (
SELECT distinct on (MB."MasterBillId")
MB."BillNumber",MB."MasterBillId",MB."BillDate",MB."BillStatusTypeId",BST."Name" as "BillStatus",
MB."Total",MB."Discount",MB."NetTotal",MB."Rounding",--GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",
P."FullName" as "PatientName",P."Mobile",P."UMRNo",prv."FullName" as "ProviderName",
L."Name" as "LocationName",nlbh."LocationId",MM."Name" as "ModuleName",
nlbh."RequisitionNumber" as "AppointmentNo",nlbh."CreatedDate" as "AppointmentDate"
FROM "MasterBill" MB
join "NewLabBookingHeader" nlbh on nlbh."NewLabBookingHeaderId"=MB."ModuleId"
join "Provider" prv on prv."ProviderId" = nlbh."DoctorId"
join "BillStatusType" BST on BST."BillStatusTypeId"=MB."BillStatusTypeId"
join "Patient" P on P."PatientId"=MB."PatientId"
--join "ModulesMaster" MM on MM."ModulesMasterId"=MB."ModulesMasterId"
join "ReceiptAreaType" MM on MM."ReceiptAreaTypeId"=MB."ReceiptAreaTypeId"
-- join "getreceipts" GR on GR."MasterBillId"=MB."MasterBillId"
join "AppointmentTransaction" AT on AT."AppointmentId"=nlbh."NewLabBookingHeaderId"
join "Location" L on L."LocationId"=AT."LocationId"
where
case when "fromDate" is null then 1=1 else "fromDate"<= nlbh."CreatedDate"::date end
and case when "toDate" is null then 1=1 else nlbh."CreatedDate"::date<= "toDate" end
and case when "locationid" is null then 1=1 else AT."LocationId" = "locationid" end
)
,pharma as (
SELECT distinct on (MB."MasterBillId")
MB."BillNumber",MB."MasterBillId",MB."BillDate",MB."BillStatusTypeId",BST."Name" as "BillStatus",
MB."Total",MB."Discount",MB."NetTotal",MB."Rounding",--GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",
P."FullName" as "PatientName",P."Mobile",P."UMRNo",nlbh."ProviderName",
L."Name" as "LocationName",nlbh."LocationId",MM."Name" as "ModuleName",
nlbh."BillNumber" as "AppointmentNo",nlbh."CreatedDate" as "AppointmentDate"
FROM "MasterBill" MB
join "PharmacySaleHeader" nlbh on nlbh."PharmacySaleHeaderId"=MB."ModuleId"
join "BillStatusType" BST on BST."BillStatusTypeId"=MB."BillStatusTypeId"
join "Patient" P on P."PatientId"=MB."PatientId"
--join "ModulesMaster" MM on MM."ModulesMasterId"=MB."ModulesMasterId"
join "ReceiptAreaType" MM on MM."ReceiptAreaTypeId"=MB."ReceiptAreaTypeId"
-- join "getreceipts" GR on GR."MasterBillId"=MB."MasterBillId"
join "AppointmentTransaction" AT on AT."AppointmentId"=nlbh."PharmacySaleHeaderId"
join "Location" L on L."LocationId"=AT."LocationId"
where
case when "fromDate" is null then 1=1 else "fromDate"<= nlbh."CreatedDate"::date end
and case when "toDate" is null then 1=1 else nlbh."CreatedDate"::date<= "toDate" end
and case when "locationid" is null then 1=1 else AT."LocationId" = "locationid" end
)
,scan as(
SELECT distinct on (MB."MasterBillId")
MB."BillNumber",MB."MasterBillId",MB."BillDate",MB."BillStatusTypeId",BST."Name" as "BillStatus",
MB."Total",MB."Discount",MB."NetTotal",MB."Rounding",--GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",
P."FullName" as "PatientName",P."Mobile",P."UMRNo",SM."MachineName" as "ProviderName",
L."Name" as "LocationName",nlbh."LocationId",MM."Name" as "ModuleName",
nlbh."RequisitionNumber" as "AppointmentNo",nlbh."AppointmentDate"
FROM "MasterBill" MB
join "BookScanAppointment" nlbh on nlbh."BookScanAppointmentId"=MB."ModuleId"
join "ScanMachineMaster" SM on SM."ScanMachineMasterId"=nlbh."ScanMachineMasterId"
join "BillStatusType" BST on BST."BillStatusTypeId"=MB."BillStatusTypeId"
join "Patient" P on P."PatientId"=MB."PatientId"
--join "ModulesMaster" MM on MM."ModulesMasterId"=MB."ModulesMasterId"
join "ReceiptAreaType" MM on MM."ReceiptAreaTypeId"=MB."ReceiptAreaTypeId"
-- join "getreceipts" GR on GR."MasterBillId"=MB."MasterBillId"
join "AppointmentTransaction" AT on AT."AppointmentId"=nlbh."BookScanAppointmentId"
join "Location" L on L."LocationId"=AT."LocationId"
where
case when "fromDate" is null then 1=1 else "fromDate"<= nlbh."AppointmentDate"::date end
and case when "toDate" is null then 1=1 else nlbh."AppointmentDate"::date<= "toDate" end
and case when "locationid" is null then 1=1 else AT."LocationId" = "locationid" end
)
SELECT O."BillNumber",O."BillDate",O."BillStatusTypeId",O."BillStatus",
O."Total",O."Discount",O."NetTotal",O."Rounding",O."Receipts",O."Receipts_Cost",O."ReceiptSum",O."ReceiptAreaTypeId",
O."PatientName",O."Mobile",O."UMRNo",O."ProviderName",
O."LocationId",O."ModuleName",O."LocationName",
O."AppointmentNo",O."AppointmentDate",
coalesce(case when O."ReceiptAreaTypeId"=4 then O."ReceiptSum" end,0) as "OPConsultation" ,
coalesce(case when O."ReceiptAreaTypeId"=10 then O."ReceiptSum" end,0) as "ScanConsultation",
coalesce(case when O."ReceiptAreaTypeId"=8 then O."ReceiptSum" end,0) as "Lab" ,
coalesce(case when O."ReceiptAreaTypeId"=1 then O."ReceiptSum" end,0) as "Pharmacy",
coalesce(case when O."ReceiptAreaTypeId"=3 then O."ReceiptSum" end,0) as "RegistrationCharges"
from
(
Select AP."BillNumber",AP."BillDate",AP."BillStatusTypeId",AP."BillStatus",
AP."Total",AP."Discount",AP."NetTotal",AP."Rounding",GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",GR."ReceiptAreaTypeId",
AP."PatientName",AP."Mobile",AP."UMRNo",AP."ProviderName",
AP."LocationId",AP."ModuleName",AP."LocationName",
AP."AppointmentNo",AP."AppointmentDate"
from getreceipts GR
join "appointment" AP on GR."MasterBillId"=AP."MasterBillId"
UNION
Select AP."BillNumber",AP."BillDate",AP."BillStatusTypeId",AP."BillStatus",
AP."Total",AP."Discount",AP."NetTotal",AP."Rounding",GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",GR."ReceiptAreaTypeId",
AP."PatientName",AP."Mobile",AP."UMRNo",AP."ProviderName",
AP."LocationId",AP."ModuleName",AP."LocationName",
AP."AppointmentNo",AP."AppointmentDate"
from getreceipts GR
join "lab" AP on GR."MasterBillId"=AP."MasterBillId"
UNION
Select AP."BillNumber",AP."BillDate",AP."BillStatusTypeId",AP."BillStatus",
AP."Total",AP."Discount",AP."NetTotal",AP."Rounding",GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",GR."ReceiptAreaTypeId",
AP."PatientName",AP."Mobile",AP."UMRNo",AP."ProviderName",
AP."LocationId",AP."ModuleName",AP."LocationName",
AP."AppointmentNo",AP."AppointmentDate"
from getreceipts GR
join "pharma" AP on GR."MasterBillId"=AP."MasterBillId"
UNION
Select AP."BillNumber",AP."BillDate",AP."BillStatusTypeId",AP."BillStatus",
AP."Total",AP."Discount",AP."NetTotal",AP."Rounding",GR."Receipts",GR."Receipts_Cost",GR."ReceiptSum",GR."ReceiptAreaTypeId",
AP."PatientName",AP."Mobile",AP."UMRNo",AP."ProviderName",
AP."LocationId",AP."ModuleName",AP."LocationName",
AP."AppointmentNo",AP."AppointmentDate"
from getreceipts GR
join "scan" AP on GR."MasterBillId"=AP."MasterBillId"
)O
where
case when "moduleid" is null then 1=1 else O."ReceiptAreaTypeId" = "moduleid" end
GROUP BY GROUPING SETS((O."BillNumber",O."BillDate",O."BillStatusTypeId",O."BillStatus",
O."Total",O."Discount",O."NetTotal",O."Rounding",O."Receipts",O."Receipts_Cost",O."ReceiptSum",O."ReceiptAreaTypeId",
O."PatientName",O."Mobile",O."UMRNo",O."ProviderName",
O."LocationId",O."ModuleName",O."LocationName",
O."AppointmentNo",O."AppointmentDate"))
order by O."ModuleName" asc;
end
$BODY$;
ALTER FUNCTION public."Masterbills_AppointmentReports"(date, date, integer, integer)
OWNER TO postgres;
---------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
\ No newline at end of file
alter table "BirthCertificate" add column "BabyWeight" INTEGER
alter table "BirthCertificate" add column "TypeOfDelivery" character varying
alter table "BirthCertificate" add column "MethodOfDelivery" character varying
alter table "BirthCertificate" add column "DurationOfPregnancy" character varying
alter table "BirthCertificate" add column "NoOfChildBorn" character varying
\ No newline at end of file
ALTER TABLE "Denverchart"
ADD COLUMN if not exists "AppointmentId" integer,
ADD COLUMN if not exists "DenverChartData" text,
ADD COLUMN if not exists "Question" text;
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."EmergencyType_EmergencyTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
----------------------------------------------------
CREATE TABLE IF NOT EXISTS public."EmergencyType"
(
"EmergencyTypeId" integer NOT NULL DEFAULT nextval('"EmergencyType_EmergencyTypeId_seq"'::regclass),
"EmergencyTypeName" text COLLATE pg_catalog."default",
"Active" boolean DEFAULT true,
CONSTRAINT "EmergencyType_pkey" PRIMARY KEY ("EmergencyTypeId")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."EmergencyType"
OWNER to postgres;
--------------------------------------------------------
INSERT INTO "EmergencyType" ("EmergencyTypeId", "EmergencyTypeName","Active")
VALUES (1,'Red',true),(2,'Yellow',true),(3,'Green',true);
-----------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."EmergencyDetail_EmergencyDetailId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
------------------------------------
CREATE TABLE IF NOT EXISTS public."EmergencyDetail"
(
"EmergencyDetailId" integer NOT NULL DEFAULT nextval('"EmergencyDetail_EmergencyDetailId_seq"'::regclass),
"DetailName" text COLLATE pg_catalog."default",
"Active" boolean DEFAULT true,
"EmergencyTypeId" integer not null,
CONSTRAINT "EmergencyDetail_pkey" PRIMARY KEY ("EmergencyDetailId"),
CONSTRAINT "FK_EmergencyDetail_EmergencyTypeId" FOREIGN KEY ("EmergencyTypeId")
REFERENCES public."EmergencyType" ("EmergencyTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
-------------------------------------------------------------------
insert into "EmergencyDetail" ("EmergencyDetailId","DetailName","Active","EmergencyTypeId")
values(1,'CARDIAC ARREST',true,1),(2,'CARDIO RESPIRATORY DISTRESS',true,1),(3,'ECLAMPSIA OR IMMINENT SYMPTOMS',TRUE,1),(4,'SEVERE OR HEAVY BLEEDING',TRUE,1),
(5,'LIFE THREATENING CONDITION',TRUE,1),(6,'URGE TO PUSH',TRUE,1),(7,'OBJECTS PROTRUDING FROM VAGINA',TRUE,1),(8,'NO FETAL MOVEMENTS',TRUE,1),(9,'DIABETIC COMA',TRUE,1),
(10,'TRAUMA',TRUE,1);
insert into "EmergencyDetail" ("EmergencyDetailId","DetailName","Active","EmergencyTypeId")
values(11,'UTERINE CONTRACTIONS EVERY 2 MINS UNCOMFORTABLE',true,2),(12,'MULTIPARA IN ACTIVE LABOUR',true,2),(13,'ABDOMINAL PAIN',TRUE,2),(14,'PRETERM LABOUR/PPROM',TRUE,2),
(15,'PRE-ECLAMPSIA',TRUE,2),(16,'RUPTURE OF MEMBRANCES',TRUE,2),(17,'WOUND INFECTION',TRUE,2),(18,'BLEEDING P/V NOT HEAVY',TRUE,2),(19,'ELECTIVE LSCS ADMISSION',TRUE,2),
(20,'IOL ADMISSION',TRUE,2);
insert into "EmergencyDetail" ("EmergencyDetailId","DetailName","Active","EmergencyTypeId")
values(21,'NAUSEA VOMITNG',true,3),(22,'URINARY COMPLAINTS',true,2),(23,'STABLE GESTATIONAL HTN',TRUE,3),(24,'UPPER RESPIRATORY INFECTION',TRUE,3),
(25,'VAGINAL DISCHARGE',TRUE,3),(26,'WOUND CHECKS/SUTURE REMOVAL',TRUE,3),(27,'INJECTIONS AND LAB TESTS',TRUE,3),(28,'REPORTS/OUTSIDE REPORT OF CYST/TORSION/ECTOPIC/ PUL BUT ASYMPTOMATIC',TRUE,3),(29,'ANC BOOKING VISIT',TRUE,3),
(30,'SYMPTOMS OF FLU/COLD/UTI',TRUE,3),(31,'TRAVEL HISTORY',TRUE,3),(32,'CONTACT / EXPOSURE TO COV',TRUE,3);
----------------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."EmergencyEncounter_EmergencyEncounterId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
----------------------------------------------------
CREATE TABLE IF NOT EXISTS public."EmergencyEncounter"
(
"EmergencyEncounterId" integer NOT NULL DEFAULT nextval('"EmergencyEncounter_EmergencyEncounterId_seq"') ,
"AppointmentId" integer,
"EmergencyTriage" text,
"NursingERForm" text,
"Active" boolean DEFAULT true,
"PatientId" INTEGER,
CONSTRAINT "EmergencyEncounter_PatientId_fkey" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
alter table "EmergencyEncounter" add column "CreatedBy" integer;
alter table "EmergencyEncounter" add column "ModifiedBy" integer;
alter table "EmergencyEncounter" add column "CreatedDate" timestamp(6) without time zone;
alter table "EmergencyEncounter" add column "ModifiedDate" timestamp(6) without time zone;
\ No newline at end of file
alter table "GynEncounter"
add "RefferalOrder" text
\ No newline at end of file
alter table "GynEncounter"
add column "GyneacAdmissionSheet" text
alter table "GynEncounter"
add column "GyneacSurgery" text
alter table "GynEncounter"
add column "GyneacDiscargeSummary" text
\ No newline at end of file
alter table "GynEncounter"
add "Measure" text
\ No newline at end of file
alter table "GynEncounter"
add column "SpeacialFeature" text,
add column "ReferralForm" text
\ No newline at end of file
alter table "GynEncounter"
add column "Colposcopic" text,
add column "Ectopic" text
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_FetchPatientsFilter_For_Appointment"(character varying, character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatientsFilter_For_Appointment"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"patientName" character varying DEFAULT NULL::text)
RETURNS TABLE("PatientId" integer, "Salutation" character varying, "FirstName" text, "MiddleName" text, "LastName" text, "FullName" text, "DateOfBirth" date, "Age" smallint, "Gender" character, "UMRNo" character varying, "Email" character varying, "Mobile" character varying, "CountryId" integer, "ProfileImageUrl" text,"TempPatient" boolean, "HowDidYouKnowId" integer, "Active" boolean, "PaymentStatus" boolean, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (
select row_number() over(partition by a."PatientId" order by a."AppointmentId" desc, a."AppointmentDate" desc )"Max" ,a."PatientId",a."AppointmentId" from "Appointment" a
join "Patient" pat on a."PatientId" =pat."PatientId"
where a."Active"=true
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
)
, maxapt as (
select a.* from "Appointment" a
join cts on a."AppointmentId"=cts."AppointmentId"
where "Max"=1)
,ctsadmission as (
select distinct max(a."AdmissionId") over(partition by a."PatientId" )"MaxAdmissionId" ,a."PatientId",
a."AppointmentId" from "Admission" a
join "Patient" pat on a."PatientId" =pat."PatientId"
where a."Active"=true
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
)
, maxadmision as (
select a.* from "Admission" a
join ctsadmission cts on a."AdmissionId"=cts."MaxAdmissionId"
)
SELECT DISTINCT pat."PatientId" ,
pat."Salutation" ,
pat."FirstName" ,
pat."MiddleName" ,
pat."LastName" ,
pat."FullName" ,
pat."DateOfBirth" ,
pat."Age" ,
pat."Gender" ,
pat."UMRNo" ,
pat."Email" ,
pat."Mobile" ,
pat."CountryId" ,
pat."ProfileImageUrl" ,
pat."TempPatient",
pat."HowDidYouKnowId",
-- pat."ThumbnailUrl" ,
pat."Active" ,
pat."PaymentStatus",
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT('https://hims-qa.s3.amazonaws.com/', pat."Guid", '/', pat."ThumbnailUrl") ELSE NULL END) AS "ThumbnailUrl"
,(max(apt."AppointmentDate")over(partition by apt."PatientId")::text ||' ' || max(apt."AppointmentTime")over(partition by apt."PatientId",apt."AppointmentDate")::text)::timestamp as "AppointmentDate",
(case when (max(apt."AppointmentDate")over(partition by apt."PatientId")::text ||' ' || max(apt."AppointmentTime")over(partition by apt."PatientId")::text)::timestamp > now() at time zone 'UTC-5:30' then true else false end)"isActiveAppointmentExists"
,(case when max(adm."AdmissionId")over(partition by adm."PatientId") is null then false
when max(adm."AdmissionId")over(partition by adm."PatientId") is not null and max(dc."DischargeId")over(partition by pat."PatientId") is null then true
when max(adm."AdmissionId")over(partition by adm."PatientId") is not null and max(dc."DischargeId")over(partition by pat."PatientId") is not null then false end
)"isActiveAdmissionExists"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
WHERE pat."Active" IS TRUE
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "uMRNo" is null then 1=1 else pat."UMRNo" ilike'%'|| "uMRNo"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchPatientsFilter_For_Appointment"(character varying, character varying, character varying, character varying)
OWNER TO postgres;
-- added this line "and case when pat."TempPatient" = TRUE THEN pat."HowDidYouKnowId" <> 11 ELSE 1 = 1 END"
DROP FUNCTION IF EXISTS public."udf_FetchPatients_For_QuickScheduleFollowUp"(character varying, character varying, character varying, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_QuickScheduleFollowUp"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"patientName" character varying DEFAULT NULL::text,
"urlLink" character varying DEFAULT NULL::text)
RETURNS TABLE("PatientId" integer, "Salutation" character varying, "FirstName" text, "MiddleName" text, "LastName" text, "FullName" text, "DateOfBirth" date, "Age" smallint, "Gender" character, "UMRNo" character varying, "Email" character varying, "Mobile" character varying, "CountryId" integer, "ProfileImageUrl" text, "Active" boolean, "PaymentStatus" boolean, "HowDidYouKnowId" integer, "EducationId" integer, "OccupationId" integer, "ProviderId" integer, "ProviderName" character varying, "ThumbnailUrl" text, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "isActiveAdmissionExists" boolean, "HWCName" character varying, "HWCPatientId" integer, "Description" text, "RowColor" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (
select row_number() over(partition by a."PatientId" order by a."AppointmentId" desc,
a."AppointmentDate" desc )"Max" ,a."PatientId",a."AppointmentId"
from "Appointment" a
join "Patient" pat on a."PatientId" =pat."PatientId"
join "Provider" pr on a."ProviderId" = pr."ProviderId"
where a."Active"=true
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%')|| "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
)
, maxapt as (
select a.* from "Appointment" a
join cts on a."AppointmentId"=cts."AppointmentId"
where "Max"=1)
,ctsadmission as (
select distinct max(a."AdmissionId") over(partition by a."PatientId" )"MaxAdmissionId" ,a."PatientId",
a."AppointmentId" from "Admission" a
join "Patient" pat on a."PatientId" =pat."PatientId"
where a."Active"=true
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%') || "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
)
, maxadmision as (
select a.* from "Admission" a
join ctsadmission cts on a."AdmissionId"=cts."MaxAdmissionId"
)
SELECT DISTINCT pat."PatientId" ,
pat."Salutation" ,
pat."FirstName" ,
pat."MiddleName" ,
pat."LastName" ,
pat."FullName" ,
pat."DateOfBirth" ,
pat."Age" ,
pat."Gender" ,
pat."UMRNo" ,
pat."Email" ,
pat."Mobile" ,
pat."CountryId" ,
pat."ProfileImageUrl" ,
-- pat."ThumbnailUrl" ,
pat."Active" ,
pat."PaymentStatus",
pat."HowDidYouKnowId",
pat."EducationId",
pat."OccupationId",
apt."ProviderId",
pr."FullName" as "ProviderName",
(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT("urlLink", pat."Guid", '/', pat."ThumbnailUrl") ELSE NULL END) AS "ThumbnailUrl"
,(max(apt."AppointmentDate")over(partition by apt."PatientId")::text ||' ' || max(apt."AppointmentTime")over(partition by apt."PatientId",apt."AppointmentDate")::text)::timestamp as "AppointmentDate",
(case when (max(apt."AppointmentDate")over(partition by apt."PatientId")::text ||' ' || max(apt."AppointmentTime")over(partition by apt."PatientId")::text)::timestamp > now() at time zone 'UTC-5:30' then true else false end)"isActiveAppointmentExists"
,(case when max(adm."AdmissionId")over(partition by adm."PatientId") is null then false
when max(adm."AdmissionId")over(partition by adm."PatientId") is not null and max(dc."DischargeId")over(partition by pat."PatientId") is null then true
when max(adm."AdmissionId")over(partition by adm."PatientId") is not null and max(dc."DischargeId")over(partition by pat."PatientId") is not null then false end
)"isActiveAdmissionExists", HWC."HWCName",HWC."HWCPatientId", HWC."Description", HWC."RowColor"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join "Provider" pr on pr."ProviderId" = apt."ProviderId"
left join maxadmision adm on adm."PatientId" = pat."PatientId" and adm."Active"=true
left join "Discharge" dc on dc."AdmissionId" = adm."AdmissionId"
left join "HWCPatient" HWC on HWC."HWCPatientId" = pat."HWCPatientId"
WHERE pat."Active" IS TRUE
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%')|| "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchPatients_For_QuickScheduleFollowUp"(character varying, character varying, character varying, character varying)
OWNER TO postgres;
\ No newline at end of file
ALTER TABLE "ObEncounter"
ADD "Allergies" text;
\ No newline at end of file
-- FUNCTION: public.udf_FetchPatients_For_AppointmentScheduleFollowUp(character varying, character varying, character varying, character varying, integer)
-- DROP FUNCTION IF EXISTS public."udf_FetchPatients_For_AppointmentScheduleFollowUp"(character varying, character varying, character varying, character varying, integer);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_AppointmentScheduleFollowUp"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"patientName" character varying DEFAULT NULL::text,
"urlLink" character varying DEFAULT NULL::text,
"appointmentId" integer DEFAULT NULL::integer)
RETURNS TABLE("IdProofName" character varying, "RelativeName" character varying, "Relation" character varying, "EducationName" text, "HowDidYouKnow" text, "OccupationName" text, "PatientId" integer, "Salutation" character varying, "FirstName" text, "MiddleName" text, "LastName" text, "FullName" text, "DateOfBirth" date, "Age" smallint, "Gender" character, "MaritalStatus" character, "UMRNo" character varying, "Email" character varying, "Mobile" character varying, "StreetAddress" character varying, "Area" character varying, "City" character varying, "State" character varying, "Zipcode" character varying, "CountryId" integer, "ProfileImageUrl" text, "ThumbnailUrl" text, "Active" boolean, "CreatedBy" integer, "CreatedDate" timestamp without time zone, "ModifiedBy" integer, "ModifiedDate" timestamp without time zone, "Guid" uuid, "ReferralBy" integer, "ReferralCode" character varying, "AadharNo" character varying, "ReferredBy" character varying, "ReferredByName" character varying, "FatherOrHusband" text, "HWCPatientId" integer, "Education" character varying, "Occupation" character varying, "Religion" character varying, "Nationality" character varying, "PatientReferredById" integer, "IdProofValue" character varying, "IdProofId" integer, "BloodGroup" character varying, "Amount" numeric, "PaymentStatus" boolean, "TempPatient" boolean, "HowDidYouKnowId" integer, "EducationId" integer, "OccupationId" integer, "BirthMark1" text, "BirthMark2" text, "RelationType" text, "OccupationDetail" text, "IsNewPatient" boolean, "REGID" character varying, "REGNO" integer, "InsuranceCompanyId" integer, "ProviderId" integer, "AppointmentId" integer, "PatientType" character, "AppointmentNo" character varying, "AppointmentTime" time without time zone, "AppointmentEndTime" time without time zone, "AppointmentNotes" character varying, "CouponId" integer, "AppointmentAmount" numeric, "Discount" numeric, "Total" numeric, "Status" character, "PatientFamilyId" integer, "DepartmentId" integer, "PaymentType" character varying, "PaymentNumber" character varying, "AppointmentPaymentStatus" boolean, "VisitTypeId" integer, "ChargeTypesId" integer, "LocationId" integer, "AppointmentTypeId" integer, "PayTypeId" integer, "TokenNumber" integer, "SpecializationId" integer, "ProviderAvailabilityId" integer, "ConsultationTypeId" integer, "DoctorSpecializationChargeModuleDetailsId" integer, "OtherRemarks" character varying, "AuthorityMasterId" integer, "ReasonsId" integer, "Remarks" character varying, "ProviderName" character varying, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "HWCName" character varying, "Description" text, "RowColor" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (
select row_number() over(partition by a."PatientId" order by a."AppointmentId" desc,
a."AppointmentDate" desc )"Max" ,a."PatientId",a."AppointmentId"
from "Appointment" a
join "Patient" pat on a."PatientId" =pat."PatientId"
join "Provider" pr on a."ProviderId" = pr."ProviderId"
where a."Active"=true
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%')|| "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
and case when "appointmentId" is null then 1=1 else a."AppointmentId" = "appointmentId" end
)
, maxapt as (
select a.* from "Appointment" a
join cts on a."AppointmentId"=cts."AppointmentId"
where "Max"=1)
SELECT DISTINCT
id."IdProofName",pf."FullName" as "RelativeName",pf."Relation",
eid."Name" as "EducationName",hid."Name" as "HowDidYouKnow",oid."Name" as "OccupationName",
pat."PatientId",pat. "Salutation",pat. "FirstName",pat. "MiddleName",pat. "LastName",pat. "FullName",pat. "DateOfBirth",pat. "Age",pat. "Gender",pat. "MaritalStatus",pat. "UMRNo",pat. "Email",pat. "Mobile",pat. "StreetAddress",pat. "AddressLine2" as "Area",pat. "City",pat. "State",pat. "Zipcode",pat. "CountryId"
,(CASE WHEN pat."ProfileImageUrl" IS NOT NULL THEN CONCAT("urlLink",'/', pat."Guid", '/', pat."ProfileImageUrl") ELSE '' END) AS "ProfileImageUrl"
,(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT("urlLink", '/', pat."Guid", '/', pat."ThumbnailUrl") ELSE '' END) AS "ThumbnailUrl"
,pat. "Active",pat. "CreatedBy",pat. "CreatedDate",pat. "ModifiedBy",pat. "ModifiedDate",pat. "Guid",pat. "ReferralBy",pat. "ReferralCode",pat. "AadharNo",referred."Name" as "ReferredBy",pat. "ReferredByName",pat. "FatherOrHusband",pat. "HWCPatientId",pat. "Education",pat. "Occupation",pat. "Religion",pat. "Nationality",pat. "PatientReferredById",pat. "IdProofValue",pat. "IdProofId",pat. "BloodGroup",pat. "Amount",pat. "PaymentStatus",pat. "TempPatient",pat. "HowDidYouKnowId",pat. "EducationId",pat. "OccupationId",pat. "BirthMark1",pat. "BirthMark2",pat. "RelationType",pat. "OccupationDetail",pat. "IsNewPatient",pat. "REGID",pat. "REGNO",pat. "InsuranceCompanyId",
apt."ProviderId",
apt."AppointmentId",
apt."PatientType",
apt."AppointmentNo"
,apt."AppointmentTime"
,apt. "AppointmentEndTime"
,apt. "AppointmentNotes",
apt."CouponId",
apt. "Amount" as "AppointmentAmount",
apt."Discount"
,apt. "Total"
,apt. "Status"
,apt. "PatientFamilyId"
,apt. "DepartmentId"
,apt. "PaymentType"
,apt. "PaymentNumber"
,apt. "PaymentStatus"
, apt."VisitTypeId"
, apt."ChargeTypesId"
, apt."LocationId"
, apt."AppointmentTypeId"
, apt."PayTypeId"
, apt."TokenNumber"
, apt."SpecializationId"
, apt."ProviderAvailabilityId"
, apt."ConsultationTypeId"
, apt."DoctorSpecializationChargeModuleDetailsId"
, apt."OtherRemarks"
, apt."AuthorityMasterId"
, apt."ReasonsId"
, apt."Remarks"
,pr."FullName" as "ProviderName"
,(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"
, HWC."HWCName", HWC."Description", HWC."RowColor"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join "Provider" pr on pr."ProviderId" = apt."ProviderId"
left join "HWCPatient" HWC on HWC."HWCPatientId" = pat."HWCPatientId"
LEFT JOIN "PatientReferredBy" referred ON referred."PatientReferredById" = pat."PatientReferredById"
left join "IdProof" id on id."IdProofId" = pat."IdProofId"
left join "HowDidYouKnow" hid on hid."HowDidYouKnowId" = pat."HowDidYouKnowId"
left join "Education" eid on eid."EducationId" = pat."EducationId"
left join "Occupation" oid on oid."OccupationId" = pat."OccupationId"
left join "PatientFamily" pf on pf."PatientId" = pat."PatientId"
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
and case when "appointmentId" is null then 1=1 else apt."AppointmentId" = "appointmentId" end
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchPatients_For_AppointmentScheduleFollowUp"(character varying, character varying, character varying, character varying, integer)
OWNER TO postgres;
update "Menu" set "EncounterKey"='gynIUI' where "Url" ilike '%/app/gyn-encounter/:id/:type/gyneac-iui%';
update "Menu" set "EncounterKey"='gynIUI' where "Url" ilike '%/app/gyn-encounter/:id/:type/gyneac-iui%';
update "Menu" set "EncounterKey"='gyneacCard' where "Url" ilike '%/app/gyn-encounter/:id/:type/gynaec-card-generation%';
update "Menu" set "EncounterKey"='vitals'where "Url" ilike '%/app/gyn-encounter/:id/:type/vital-signs%';
update "Menu" set "EncounterKey"='breastScreening'where "Url" ilike '%/app/gyn-encounter/:id/:type/breast-screening%';
update "Menu" set "EncounterKey"='additionalLabs'where "Url" ilike '%/app/gyn-encounter/:id/:type/additional-labs%';
update "Menu" set "EncounterKey"='lastBreastUltraSound'where "Url" ilike '%/app/gyn-encounter/:id/:type/last-breast-ultra-sound%';
update "Menu" set "EncounterKey"='skin'where "Url" ilike '%/app/gyn-encounter/:id/:type/skin%';
update "Menu" set "EncounterKey"='physicalExam'where "Url" ilike '%/app/gyn-encounter/:id/:type/physical-exam%';
update "Menu" set "EncounterKey"='pelvic'where "Url" ilike '%/app/gyn-encounter/:id/:type/pelvic%';
update "Menu" set "EncounterKey"='gynUltraSound'where "Url" ilike '%/app/gyn-encounter/:id/:type/gyn-ultra-sound%';
update "Menu" set "EncounterKey"='patientDeferred'where "Url" ilike '%/app/gyn-encounter/:id/:type/patient-deferred%';
update "Menu" set "EncounterKey"='abdomen'where "Url" ilike '%/app/gyn-encounter/:id/:type/abdomen%';
update "Menu" set "EncounterKey"='gynLabs'where "Url" ilike '%/app/gyn-encounter/:id/:type/gyn-lab%';
update "Menu" set "EncounterKey"='heent'where "Url" ilike '%/app/gyn-encounter/:id/:type/heent%';
update "Menu" set "EncounterKey"='menopausalHistory'where "Url" ilike '%/app/gyn-encounter/:id/:type/menopausal-history%';
update "Menu" set "EncounterKey"='mensutralHistory'where "Url" ilike '%/app/gyn-encounter/:id/:type/menstural-history%';
update "Menu" set "EncounterKey"='cardiovascular'where "Url" ilike '%/app/gyn-encounter/:id/:type/cv%';
update "Menu" set "EncounterKey"='breast'where "Url" ilike '%/app/gyn-encounter/:id/:type/breast%';
update "Menu" set "EncounterKey"='birthControl'where "Url" ilike '%/app/gyn-encounter/:id/:type/birth-control%';
update "Menu" set "EncounterKey"='gynIUI'where "Url" ilike '%/app/gyn-encounter/:id/:type/gyn-iui%';
update "Menu" set "EncounterKey"='gynaecVisit'where "Url" ilike '%/app/gyn-encounter/:id/:type/gynaec-visit%';
update "Menu" set "EncounterKey"='gynaecOrders'where "Url" ilike '%/app/gyn-encounter/:id/:type/gyneac-orders%';
update "Menu" set "EncounterKey"='procedure'where "Url" ilike '%/app/gyn-encounter/:id/:type/procedure-form%';
update "Menu" set "EncounterKey"='proformaForOasi'where "Url" ilike '%/app/gyn-encounter/:id/:type/proforma-For-Oasi%';
update "Menu" set "EncounterKey"='gynHistory'where "Url" ilike '%/app/gyn-encounter/:id/:type/gynaec-history-new%';
update "Menu" set "EncounterKey"='allergies'where "Url" ilike '%/app/gyn-encounter/:id/:type/obAllergies%';
update "Menu" set "EncounterKey"='cancerHistory'where "Url" ilike '%/app/gyn-encounter/:id/:type/cancer-history%';
update "Menu" set "EncounterKey"='surgeries'where "Url" ilike '%/app/gyn-encounter/:id/:type/procedure-surgeries%';
update "Menu" set "EncounterKey"='problemList'where "Url" ilike '%/app/gyn-encounter/:id/:type/problem-list%';
update "Menu" set "EncounterKey"='familyHistory'where "Url" ilike '%/app/gyn-encounter/:id/:type/family-history%';
update "Menu" set "EncounterKey"='gyneacPartner'where "Url" ilike '%/app/gyn-encounter/:id/:type/gyneac-partner%';
update "Menu" set "EncounterKey"='musculoSkeletal'where "Url" ilike '%/app/gyn-encounter/:id/:type/musculoskeletal%';
update "Menu" set "EncounterKey"='lymphatic'where "Url" ilike '%/app/gyn-encounter/:id/:type/lymphatic%';
update "Menu" set "EncounterKey"='respiratory'where "Url" ilike '%/app/gyn-encounter/:id/:type/respiratory%';
update "Menu" set "EncounterKey"='lastMammogram'where "Url" ilike '%/app/gyn-encounter/:id/:type/last-mammogram%';
update "Menu" set "EncounterKey"='lastDexaScan'where "Url" ilike '%/app/gyn-encounter/:id/:type/last-dexa-scan%';
update "Menu" set "EncounterKey"='lastPelvicUltraSound'where "Url" ilike '%/app/gyn-encounter/:id/:type/last-pelvic-ultra-sounds%';
\ No newline at end of file
alter table "LabBookingTimeLine"
add column if not exists "NewLabBookingDetailId" integer null,
ADD CONSTRAINT "FK_LabBookingTimeLine_NewLabBookingDetailId" FOREIGN KEY ("NewLabBookingDetailId")
REFERENCES public."NewLabBookingDetail" ("NewLabBookingDetailId") ;
alter table "ObEncounter" add "OutPatientManagement" TEXT;
alter table "ObEncounter" add "PrePregnancyPlan" TEXT;
alter table "ObEncounter" add "SpecialFeature" TEXT;
create table "TemplateHeader"(
"TemplateHeaderId" serial primary key,
"ModulesMasterId" int references "ModulesMaster"("ModulesMasterId"),
"TemplateName" 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 "TemplateDetail"(
"TemplateDetailId" serial primary key,
"TemplateHeaderId" int references "TemplateHeader"("TemplateHeaderId"),
"JSONValue" text
);
---------
insert into "Lookup" ("Name","Description") values ('MedRoute','For medication taking ways') returning "LookupId"; -- 23;
-------
insert into "LookupValue" ("LookupId","Name","CreatedBy","CreatedDate")
values
(23,'Oral',1029,now()),
(23,'IV', 1029,now()),
(23,'SC',1029,now()),
(23,'SL',1029,now()),
(23,'INS',1029,now()),
(23,'LA',1029,now()),
(23,'PR',1029,now()),
(23,'PV',1029,now()),
(23,'ID',1029,now()),
(23,'External',1029,now()),
(23,'Intramuscular',1029,now());
--------
create table "MedFrequencyMaster"(
"MedFrequencyMasterId" serial primary key,
"FrequencyName" text,
"FrequencyDescription" text,
"FreqType" varchar(10),
"CalculationUnit" int default 0,
"Active" bool default true,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone
);
------
INSERT INTO "MedFrequencyMaster"
("FrequencyName", "FrequencyDescription", "CalculationUnit")
values
('Once Daily','Once Daily',1),
('0.5 ml SOS','0.5 ml SOS',0),
('1st Booster','1st Booster',0),
('1st Dose','1st Dose',0),
('2 Tab. Once daily','2 Tab. Once daily',2),
('2 Tab. Twice daily','2 Tab. Twice daily',4),
('2nd Booster','2nd Booster ',0),
('2nd Dose','2nd Dose',0),
('3rd Dose','3rd Dose',0),
('5 ml / 3 times / day','5 ml / 3 times / day',0),
('HS (Bed Time)','HS (Bed Time)',0),
('Monthly','Monthly',1),
('Once a Week','Once a Week',1),
('SOS - AS AND WHEN REQUIRED','SOS - AS AND WHEN REQUIRED',0),
('Stat','Stat (Single Dose)',1),
('Thrice a Day','Thrice Daily',3),
('Twice a Week','Twice a Week',2),
('Twice a Day','Twice Daily',2),
('6th hourly',NULL,4),
('5 minutes','Every 5 minutes',288),
('30 minutes','Every 30 minutes',48),
('PRN','IP',1),
('1 drop every three hours','1 drop every three hours',0),
('15 minutes','Every 15 minutes',96),
('2 Tab. thrice daily','2 Tab. thrice daily',12),
('Hourly','Every 60 minutes',24),
('Once Daily',NULL,1),
('12th hourly',' ',2),
('8th hourly',NULL,3),
('6th hourly',NULL,4),
('4th hourly',' ',6),
('2nd hourly','ÿ ',12),
('Hourly',NULL,24),
('30 minutes',NULL,42),
('15 minutes',NULL,96),
('5 minutes',NULL,288),
('HS (Bed Time)',NULL,NULL),
('Monthly',NULL,NULL),
('SOS',NULL,NULL),
('Stat',NULL,NULL),
('Once a Week',NULL,NULL),
('1st Dose',NULL,NULL),
('2nd Dose',NULL,NULL),
('3rd Dose',NULL,NULL),
('1st Booster',NULL,NULL),
('2nd Booster',NULL,NULL),
('Alternate Days',NULL,NULL),
('4 times a day',NULL,4),
('12 th hourly',NULL,2),
('8th hourly',NULL,3),
('4th hourly','For IP EMR',6),
('5 times a day',NULL,5);
update "MedFrequencyMaster" set "CreatedBy" = 1029, "FreqType" = 'G' , "CreatedDate" = now();
--------
alter table "PatientMedicationDetail" add column "Route" text;
\ No newline at end of file
create schema vendors;
create table vendors."TendorStatus"(
"TenderStatusId" serial primary key,
"Status" varchar(300)
);
create table vendors."PharmacyProductRequest"(
"PharmacyProductRequestId" bigserial primary key,
"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"PharmacyStockId" int references "PharmacyStock"("PharmacyStockId"),
"RolStocksId" text,
"TenderStatusId" int references vendors."TendorStatus"( "TenderStatusId"),
"RaisedBy" int references "Account"("AccountId"),
"RaisedDate" timestamp without time zone,
"ApprovedBy" int references "Account"("AccountId"),
"ApprovedDate" timestamp without time zone
);
insert into vendors."TendorStatus"("Status") values ('Pending');
alter table "SupplierProduct" add column "Mrp" numeric(10,2);
create sequence "ANCCardGeneration_ANCCardGenerationId_seq";
CREATE TABLE IF NOT EXISTS public."ANCCardGeneration"
(
"ANCCardGenerationId" integer NOT NULL DEFAULT nextval('"ANCCardGeneration_ANCCardGenerationId_seq"'::regclass),
"Department" text,
"ANCNo" character varying(255),
"HusbandName"character varying(255),
"HusbandAge" int,
"Remarks" text,
"RegistrationDate" text,
"ANCNoExists" text,
"Active" boolean DEFAULT true,
"ProviderId" integer NOT NULL,
"PatientId" integer NOT NULL,
CONSTRAINT "ANCCardGeneration_pkey" PRIMARY KEY ("ANCCardGenerationId"),
CONSTRAINT "FK_ANCCardGeneration_PatientId" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_ANCCardGeneration_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
\ No newline at end of file
DROP TABLE IF EXISTS public."PackageModuleDetail" cascade;
------------------------------------------------------
DROP TABLE IF EXISTS public."PackageModule" cascade;
------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."PackageModule"
(
"PackageModuleId" integer NOT NULL DEFAULT nextval('"PackageModule_PackageIdModule_Seq"'::regclass),
"PackageName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"PackageType" character varying(2) COLLATE pg_catalog."default" NOT NULL,
"ModuleType" character varying(10) COLLATE pg_catalog."default" NOT NULL DEFAULT 'Package'::character varying,
"LocationId" integer NOT NULL,
"ProviderId" integer,
"ChargeModuleTemplateId" integer NOT NULL,
"ModulesMasterIds" text COLLATE pg_catalog."default" NOT NULL,
"Notes" character varying(500) COLLATE pg_catalog."default",
"Quantity" smallint NOT NULL DEFAULT 0,
"FreeQuantity" smallint DEFAULT 0,
"Exclusions" character varying(1000) COLLATE pg_catalog."default",
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL DEFAULT now(),
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "PK_PackageModule_PackageModuleId" PRIMARY KEY ("PackageModuleId"),
CONSTRAINT "FK_PackageModule_ChargeModuleTemplateId" FOREIGN KEY ("ChargeModuleTemplateId")
REFERENCES public."ChargeModuleTemplate" ("ChargeModuleTemplateId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_PackageModule_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
------------------------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."PackageModuleDetail"
(
"PackageModuleDetailId" integer NOT NULL DEFAULT nextval('"PackageModuleDetail_PackageIdModuleDetail_Seq"'::regclass),
"PackageModuleId" integer NOT NULL,
"ModulesMasterId" integer,
"ReferenceId" integer NOT NULL,
"Quantity" smallint NOT NULL DEFAULT 1,
"IsFree" boolean NOT NULL DEFAULT false,
"Amount" numeric(8,2),
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" numeric NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL DEFAULT now(),
"ModifiedBy" numeric,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "PackageModuleDetail_pkey" PRIMARY KEY ("PackageModuleDetailId"),
CONSTRAINT "FK_PackageModuleDetail_PackageModuleId" FOREIGN KEY ("PackageModuleId")
REFERENCES public."PackageModule" ("PackageModuleId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
);
------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public."udf_fetch_moduleChargeDetails"(
"@modulesMasterId" integer DEFAULT NULL::integer,
"@locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("LocationId" integer, "ModulesMasterId" integer, "ModuleName" character varying, "ModuleIcon" character varying, "ReferenceId" integer, "ChargeName" text, "DepartmentId" integer, "DepartmentName" text, "ChargeGroupId" integer, "ChargeGroupName" text, "RepeatTypeId" integer, "RepeatTypeName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
RETURN query SELECT distinct
-- CMD."ChargeModuleDetailsId",
-- CMD."ChargeModuleCategoryId",
CMD."LocationId",
CMC."ModulesMasterId",
MM."ModuleName",
MM."ModuleIcon",
-- CMD."Amount",
CMD."ReferenceId",
LMD."TestName" AS "ChargeName",
NULL :: INT AS "DepartmentId",
NULL :: TEXT AS "DepartmentName",
NULL :: INT AS "ChargeGroupId",
NULL :: TEXT AS "ChargeGroupName",
NULL :: INT "RepeatTypeId",
NULL :: TEXT "RepeatTypeName"
FROM
"ChargeModuleDetails" CMD
JOIN "ChargeModuleCategory" CMC ON CMC."ChargeModuleCategoryId" = CMD."ChargeModuleCategoryId"
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = CMC."ModulesMasterId"
JOIN "LabMainDetail" LMD ON LMD."LabMainDetailId" = CMD."ReferenceId"
AND MM."ModuleName" = 'Lab'
WHERE
MM."ModulesMasterId" = "@modulesMasterId"
AND CMD."LocationId" = "@locationId"
UNION ALL
SELECT DIstinct
-- CMD."ChargeModuleDetailsId",
-- CMD."ChargeModuleCategoryId",
CMD."LocationId",
CMC."ModulesMasterId",
MM."ModuleName",
MM."ModuleIcon",
-- CMD."Amount",
CMD."ReferenceId",
STM."ScanTestName" AS "ChargeName",
NULL :: INT AS "DepartmentId",
NULL :: TEXT AS "DepartmentName",
NULL :: INT AS "ChargeGroupId",
NULL :: TEXT AS "ChargeGroupName",
NULL :: INT "RepeatTypeId",
NULL :: TEXT "RepeatTypeName"
FROM
"ChargeModuleDetails" CMD
JOIN "ChargeModuleCategory" CMC ON CMC."ChargeModuleCategoryId" = CMD."ChargeModuleCategoryId"
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = CMC."ModulesMasterId"
JOIN "ScanTestMaster" STM ON STM."ScanTestMasterId" = CMD."ReferenceId"
AND MM."ModuleName" = 'Scan'
WHERE
MM."ModulesMasterId" = "@modulesMasterId"
AND CMD."LocationId" = "@locationId"
UNION ALL
SELECT distinct
-- CMD."ChargeModuleDetailsId",
-- CMD."ChargeModuleCategoryId",
CMD."LocationId",
CMC."ModulesMasterId",
MM."ModuleName",
MM."ModuleIcon",
-- CMD."Amount",
CMD."ReferenceId",
s."Name" AS "ChargeName",
NULL :: INT AS "DepartmentId",
NULL :: TEXT AS "DepartmentName",
NULL :: INT AS "ChargeGroupId",
NULL :: TEXT AS "ChargeGroupName",
NULL :: INT "RepeatTypeId",
NULL :: TEXT "RepeatTypeName"
FROM
"ChargeModuleDetails" CMD
JOIN "ChargeModuleCategory" CMC ON CMC."ChargeModuleCategoryId" = CMD."ChargeModuleCategoryId"
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = CMC."ModulesMasterId"
JOIN "Surgery" s ON s."SurgeryId" = CMD."ReferenceId"
AND MM."ModuleName" = 'OT'
WHERE
MM."ModulesMasterId" = "@modulesMasterId"
AND CMD."LocationId" = "@locationId"
UNION ALL
SELECT DISTINCT
-- CMD."ChargeModuleDetailsId",
-- CMD."ChargeModuleCategoryId",
CMD."LocationId",
CMC."ModulesMasterId",
MM."ModuleName",
MM."ModuleIcon",
-- CMD."Amount",
CMD."ReferenceId",
c."ChargeName",
d."DepartmentId" AS "DepartmentId",
d."DepartmentName" AS "DepartmentName",
g."ChargeGroupId",
g."ChargeGroupName",
c."RepeatTypeId",
t."RepeatTypeName" "Unit"
FROM
"ChargeModuleDetails" CMD
JOIN "ChargeModuleCategory" CMC ON CMC."ChargeModuleCategoryId" = CMD."ChargeModuleCategoryId"
JOIN "ModulesMaster" MM ON MM."ModulesMasterId" = CMC."ModulesMasterId"
JOIN "Charge" C ON C."ModulesMasterId" = CMC."ModulesMasterId"
AND C."ChargeId" = CMD."ReferenceId"
LEFT JOIN "ChargeGroup" G ON G."ChargeGroupId" = C."ChargeGroupId"
LEFT JOIN "Department" d ON G."DepartmentId" = d."DepartmentId"
LEFT JOIN "RepeatType" t ON t."RepeatTypeId" = c."RepeatTypeId"
WHERE
1 = 1
AND MM."ModulesMasterId" = "@modulesMasterId"
AND MM."ModuleName" = 'Services'
AND CMD."LocationId" = "@locationId" ;
END
$BODY$;
-- FUNCTION: public.udf_fetchProviderAvailabilityDatesNew(integer, integer, integer, text, text, integer)
-- DROP FUNCTION IF EXISTS public."udf_fetchProviderAvailabilityDatesNew"(integer, integer, integer, text, text, integer);
CREATE OR REPLACE FUNCTION public."udf_fetchProviderAvailabilityDatesNew"(
providerid integer,
locationid integer,
specializationid integer,
startdate text,
enddate text,
consultationtypeid 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 regexp_split_to_table(A."AvailableDate",',') ::date "Dates" ,
A."ProviderId",A."ProviderAvailabilityId",A."LocationId", A."StartDate", A."EndDate", A."LocationId", S."SpecializationId" , A."ConsultationTypeId"
from "ProviderAvailability" A
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Provider" PR on A."ProviderId" = PR."ProviderId" AND PR."Active" = TRUE
JOIN "Specialization" S on S."SpecializationId" =A."SpecializationId" AND S."Active" IS TRUE
--JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."LocationId" = locationid And S."SpecializationId" = specializationid And A."ConsultationTypeId" = consultationTypeId and A."Active" IS TRUE
)
,Availability as (
select A."AvailableDay", A."ProviderAvailabilityId",A."AvailableDate"
--A."ProviderId"
--,A."ProviderLocationId"
,A."LocationId", A."StartDate", A."EndDate", S."SpecializationId", A."ConsultationTypeId"
--,json_array_elements(case when (A."Availability" is null or A."Availability"='') then '[]' else (A."Availability"::json)end) "Availability"
from "ProviderAvailability" A
--left join "ProviderAvailabilitySlot" PAS on PAS."ProviderAvailabilityId" = A."ProviderAvailabilityId"
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Provider" PR on A."ProviderId" = PR."ProviderId" AND PR."Active" = TRUE
JOIN "Specialization" S on S."SpecializationId" = ANY(PR."Specializations") AND S."Active" IS TRUE
--JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
--JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."LocationId" = locationid And S."SpecializationId" = specializationid and A."ConsultationTypeId" = consultationTypeId And A."Active" IS TRUE
--and case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
)
,Avail as (
SELECT unnest(string_to_array(A."AvailableDay", ',')) AS "Day",unnest(string_to_array(A."AvailableDate", ',')) AS "AvailableDate", A."ProviderAvailabilityId",A."LocationId", A."StartDate", A."EndDate", A."SpecializationId"
from Availability A
)
, LeaveAvailability as (
select A."ProviderId",A."LeaveDate",coalesce(A."ProviderAvailabilityId"::text,
(
select string_agg(D."ProviderAvailabilityId"::text,',') "ProviderAvailabilityId" from "ProviderAvailability" D where D."ProviderId"= providerid and D."LocationId" = locationid
))
"ProviderAvailabilityId" from "ProviderLeave" A where A."ProviderId"=providerid and A."LocationId" = locationid
)
,LeaveData as (
select A."ProviderId",A."LeaveDate",regexp_split_to_table(A."ProviderAvailabilityId",',') ::int "ProviderAvailabilityId"
from LeaveAvailability A
)
,FinalData as (
select DISTINCT C."LeaveDate", A."Dates" "Date", A."ProviderId",A."ProviderAvailabilityId",A."StartDate",A."EndDate"
--,A."LocationId"
,extract(ISODOW from "Dates")"DateNo", CASE
WHEN extract(ISODOW from "Dates") =1 THEN 'Monday'
WHEN extract(ISODOW from "Dates") =2 THEN 'Tuesday'
WHEN extract(ISODOW from "Dates")=3 THEN 'Wednesday'
WHEN extract(ISODOW from "Dates")=4 THEN 'Thursday'
WHEN extract(ISODOW from "Dates")=5 THEN 'Friday'
WHEN extract(ISODOW from "Dates")=6 THEN 'Saturday'
WHEN extract(ISODOW from "Dates")=7 THEN 'Sunday' end "Day" ,
case when C."LeaveDate" is not null then 'L' when "AvailableDate"::date is not null is not null then 'A' else '' end "Status"
from TotalDates A
left join Avail B on "AvailableDate"::date= A."Dates" ::date and A."ProviderId"=A."ProviderId" and A."ProviderAvailabilityId"=B."ProviderAvailabilityId"
--and A."LocationId"=B."LocationId"
left join LeaveData C on C."LeaveDate"::date =A."Dates" and A."ProviderAvailabilityId"=C."ProviderAvailabilityId"
where
A."Dates"::Date between startdate::Date and enddate::Date
)
select DISTINCT A."Date",A."DateNo"::int,A."Day"::text::character varying(10),A."Status"::char
from FinalData A
where trim(A."Status") <> ''
--A."Date" >= A."StartDate"::Date or
--A."Date" <= A."EndDate"::Date
order by A."Date";
end
$BODY$;
ALTER FUNCTION public."udf_fetchProviderAvailabilityDatesNew"(integer, integer, integer, text, text, integer)
OWNER TO postgres;
alter table "ObEncounter" add "FamilyHistory" text;
\ No newline at end of file
create sequence "Tpa_TpaId_seq";
-----------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."Tpa"
(
"TpaId" integer NOT NULL DEFAULT nextval('"Tpa_TpaId_seq"'::regclass),
"Name" Character Varying(150) unique,
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "Tpa_pkey" PRIMARY KEY ("TpaId"),
CONSTRAINT "Tpa_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "Tpa_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
----------------------------------
alter table "Admission"
add column "TpaId" integer,
add column "PatientOrganization" character varying(150),
add CONSTRAINT "Admission_TpaId_fkey" FOREIGN KEY ("TpaId")
REFERENCES public."Tpa" ("TpaId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
ALTER TABLE "OTRegister" ALTER COLUMN "AssitantId" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "AnaesthetistId" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "AnaesthetistId" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "NurseId" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "OREntryDate" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "SignInDate" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "SignOutDate" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "ShiftWardToDate" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "AnaesthesiaTypeId" DROP NOT NULL;
ALTER TABLE "OTRegister" ALTER COLUMN "SurgeryTypeId" DROP NOT NULL;
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_PatientMedicationReport"(integer, text, text, text, integer, timestamp without time zone, timestamp without time zone, text);
CREATE OR REPLACE FUNCTION public."udf_PatientMedicationReport"(
"patientId" integer DEFAULT NULL::integer,
"uMRNo" text DEFAULT NULL::text,
"patientMobile" text DEFAULT NULL::text,
"billNumber" text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PatientName" text, "UMRNo" character varying, "PatientMobile" character varying, "BillNumber" character varying, "BillType" character varying, "SaleDate" timestamp without time zone, "OverallNetAmount" numeric, "ProductName" character varying, "GenericName" text, "CategoryName" character varying, "CompanyName" text, "BatchNumber" character varying, "PaidVia" character varying, "PaymentNumber" character varying, "Quantity" integer, "NetAmount" numeric, "TotalAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
Declare
BEGIN
return query
select P."FullName" "PatientName",P."UMRNo",p."Mobile" "PatientMobile" ,Ph."BillNumber",PH."BillType",
PH."CreatedDate" "SaleDate",PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" "CategoryName ",c."Name" "CompanyName",PRS."BatchNumber", PT."PayTypeName" as "PaidVia",PH."PaymentNumber" ,sum(PS."Quantity")::int "Quantity",
PS."NetAmount" ,sum(PS."NetAmount") "TotalAmount"
from "PharmacySaleHeader" PH
join "PharmacySaleDetail" PS on PH."PharmacySaleHeaderId"=PS."PharmacySaleHeaderId"
join "PharmacyProduct" pp on PS."PharmacyProductId"=PP."PharmacyProductId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PS."PharmacyRetailStockId" and PRS."PharmacyProductId"=PP."PharmacyProductId"
join "Company" c on c."CompanyId"=PP."CompanyId"
join "LookupValue" ci on ci."LookupValueId"=pp."CategoryId"
join "Patient" P on P."PatientId"=ph."PatientId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
--where p."UMRNo" ='UMR21050206'
where case when "uMRNo" ='' then 1=1 when "uMRNo" is null then 1=1 else p."UMRNo" ilike '%'||"uMRNo"||'%' end and
--case when "patientName" ='' then 1=1 when "patientName" is null then 1=1 else P."FullName" ilike '%'||"patientName"||'%' end and
case when "patientId" is null then 1=1 else P."PatientId"="patientId" end and
case when "patientMobile" ='' then 1=1 when "patientMobile" is null then 1=1 else p."Mobile" ilike '%'||"patientMobile"||'%' end and
case when "billNumber" ='' then 1=1 when "billNumber" is null then 1=1 else Ph."BillNumber" ilike '%'||"billNumber"||'%' end
and case when "payTypeId" is null then 1=1 else PT."PayTypeId" ="payTypeId" end
and case when "fromDate" is null then 1=1 else "fromDate" <= PH."CreatedDate" and PH."CreatedDate" <= "toDate" end
and case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
GROUP BY GROUPING SETS(( P."FullName",P."UMRNo",p."Mobile" ,Ph."BillNumber",PH."CreatedDate",PH."BillType",
PH."OverallNetAmount",PP."ProductName",pp."GenericName",
ci."Name" ,c."Name" ,PRS."BatchNumber",PT."PayTypeName", PH."PaymentNumber" ,PS."Quantity",PS."NetAmount" ),
( P."FullName",Ph."BillNumber",PH."BillType"), ())
order by Ph."CreatedDate" desc
;
END
$BODY$;
ALTER FUNCTION public."udf_PatientMedicationReport"(integer, text, text, text, integer, timestamp without time zone, timestamp without time zone, text)
OWNER TO postgres;
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_PharmacyBills_Report"(text, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text);
CREATE OR REPLACE FUNCTION public."udf_PharmacyBills_Report"(
"billNumber" text DEFAULT NULL::text,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"toDate" timestamp without time zone DEFAULT (now())::timestamp without time zone,
"retailName" text DEFAULT NULL::text,
"retailPharmacyId" integer DEFAULT NULL::integer,
"locationId" text DEFAULT NULL::text)
RETURNS TABLE("PharmacySaleHeaderId" integer, "BillNumber" character varying, "SaleDate" timestamp without time zone, "PatientName" character varying, "PatientMobile" character varying, "UMRNo" character varying, "PaidVia" character varying, "PaymentNumber" character varying, "CreatedByName" text, "RoleName" character varying, "ProviderName" character varying, "TotalAmount" numeric, "RetailName" text, "OverallTaxes" numeric, "LocationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
select PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."CreatedDate" "SaleDate",PH."PatientName",PH."Mobile"
,Pa."UMRNo",PT."PayTypeName" as "PaidVia",PH."PaymentNumber",A."FullName"
"CreatedByName",R."RoleName" "Role" ,
PH."ProviderName", PH."OverallNetAmount" ,RP."RetailName",PH."OverallTaxes",L."Name" as "LocationName"
from "PharmacySaleHeader" PH
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
--join "Provider" pr on pr."ProviderId"::text=PH."ProviderId"::text
join "Account" A on A."AccountId"=PH."CreatedBy"
join "Role" R on R."RoleId"=A."RoleId"
join "PharmacySaleDetail" PSD on PSD."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "PharmacyRetailStock" PRS on PRS."PharmacyRetailStockId"=PSD."PharmacyRetailStockId"
join "RetailWareHouseLink" RWL on RWL."RetailWareHouseLinkId" = PRS."RetailWareHouseLinkId"
join "RetailPharmacy" RP on RP."RetailPharmacyId"=RWL."RetailPharmacyId"
join "Location" L on L."LocationId" = PH."LocationId"
left join "PayType" PT on PT."PayTypeId"=PH."PayTypeId"
where case when "billNumber" is null then 1=1 else PH."BillNumber" ilike '%' || "billNumber" ||'%' end and
case when "patientId" is null then 1=1 else PH."PatientId"="patientId" end and
case when "patientMobile" is null then 1=1 else PH."Mobile" ilike '%' || "patientMobile" ||'%' end and
case when "uMRNo" is null then 1=1 else Pa."UMRNo" ilike '%' || "uMRNo" ||'%' end and
case when "payTypeId" is null then 1=1 else PT."PayTypeId" = "payTypeId" end and
case when "providerId" is null then 1=1 else PH."ProviderId" ="providerId" end and
case when "createdBy" is null then 1=1 else A."AccountId"="createdBy" end and
case when "fromDate" is null then 1=1 else PH."SaleDate" >= "fromDate" end and
case when "toDate" is null then 1=1 else PH."SaleDate" <= "toDate" end and
case when "retailName" is null then 1=1 else RP."RetailName" ilike '%' || "retailName" ||'%' end and
case when "retailPharmacyId" is null then 1=1 else RP."RetailPharmacyId" = "retailPharmacyId" end and
case when "locationId" is null then 1=1 else PH."LocationId" = "locationId"::int end
group by PH."PharmacySaleHeaderId" ,PH."BillNumber",PH."SaleDate", PH."OverallNetAmount",PH."PatientName",PH."Mobile",Pa."UMRNo",PT."PayTypeName", PH."PaymentNumber", A."FullName"
,R."RoleName" ,PH."ProviderName",RP."RetailName",PH."OverallTaxes",L."Name"
order by PH."SaleDate" desc;
END
$BODY$;
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_pharmacypatientbills_finalreport"(text, integer, integer, character varying, character varying, integer, integer, integer, date, date, text, integer, text, boolean);
CREATE OR REPLACE FUNCTION public."udf_pharmacypatientbills_finalreport"(
"billNumber" text DEFAULT NULL::text,
"accountId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"patientMobile" character varying DEFAULT NULL::text,
"uMRNo" character varying DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"providerId" integer DEFAULT NULL::integer,
"createdBy" integer DEFAULT NULL::integer,
"fromDate" 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 "fromDate"<= PH."SaleDate" 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_pharmacypatientbills_finalreport"(text, integer, integer, character varying, character varying, integer, integer, integer, timestamp without time zone, timestamp without time zone, text, integer, text, boolean)
OWNER TO postgres;
\ No newline at end of file
CREATE OR REPLACE FUNCTION public."widget_Table_otAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying, "SurgeryId" integer, "SurgeryName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(ot."SignInDate", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName",ot."SurgeryId",s1."Name" as "SurgeryName"
from "OTRegister" ot
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = ot."PatientId"
join "Provider" Pr on Pr."ProviderId" = ot."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (Pr."Specializations")
join "Appointment" apt on apt."PatientId"=ot."PatientId"
join "Surgery" s1 on s1."SurgeryId"=ot."SurgeryId"
where
ot."SignInDate"::date="fromDate" and apt."Active" is true
and case when "referenceId" is null then 1=1 else ot."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else ot."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_otAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
-------------------------------------------------------------------------------------------
-- FUNCTION: public.widget_Table_WalkinAppointmentDashboard(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_WalkinAppointmentDashboard"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_WalkinAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName"
from "Appointment" apt
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (Pr."Specializations")
where
apt."AppointmentDate"::date="fromDate" and apt."Active" is true and apt."VisitTypeId" =9
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_WalkinAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
--------------------------------------------------------------------------
-- FUNCTION: public.widget_Table_OnlineAppointmentDashboard(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_OnlineAppointmentDashboard"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_OnlineAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation", Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName"
from "Appointment" apt
join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (pa."Specializations")
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and AT."AppointmentTypeId" =3
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_OnlineAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
------------------------------------------------------------------------
-- FUNCTION: public.widget_Table_NewPatientAppointmentDashboard(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_NewPatientAppointmentDashboard"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_NewPatientAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName"
from "Appointment" apt
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (pr."Specializations")
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and apt."VisitTypeId" =43
and Pa."CreatedDate"::date="fromDate" and Pa."Active" is true
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_NewPatientAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
-------------------------------------------------------------------------
-- FUNCTION: public.widget_Table_NewAppointmentDashboard(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_NewAppointmentDashboard"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_NewAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName"
from "Appointment" apt
--left join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
left join "Patient" Pa on Pa."PatientId" = apt."PatientId"
left join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (Pr."Specializations")
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and apt."VisitTypeId" <>10
and case when "referenceId" is null then 1=1 else apt."ProviderId"="referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
--LIMIT 10 offset 0
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_NewAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
---------------------------------------------------------------------
-- FUNCTION: public.widget_Table_FollowUpAppointmentDashboard(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_FollowUpAppointmentDashboard"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_FollowUpAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation", Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName"
from "Appointment" apt
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (Pr."Specializations")
where apt."AppointmentDate"::date="fromDate" and apt."VisitTypeId" =10
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_FollowUpAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.udf_FetchPatients_For_AppointmentScheduleFollowUp(character varying, character varying, character varying, character varying, integer)
-- DROP FUNCTION IF EXISTS public."udf_FetchPatients_For_AppointmentScheduleFollowUp"(character varying, character varying, character varying, character varying, integer);
CREATE OR REPLACE FUNCTION public."udf_FetchPatients_For_AppointmentScheduleFollowUp"(
filter character varying DEFAULT NULL::text,
"patientMobile" character varying DEFAULT NULL::text,
"patientName" character varying DEFAULT NULL::text,
"urlLink" character varying DEFAULT NULL::text,
"appointmentId" integer DEFAULT NULL::integer)
RETURNS TABLE("IdProofName" character varying, "RelativeName" character varying, "Relation" character varying, "EducationName" text, "HowDidYouKnow" text, "OccupationName" text, "PatientId" integer, "Salutation" character varying, "FirstName" text, "MiddleName" text, "LastName" text, "FullName" text, "DateOfBirth" date, "Age" smallint, "Gender" character, "MaritalStatus" character, "UMRNo" character varying, "Email" character varying, "Mobile" character varying, "StreetAddress" character varying, "Area" character varying, "City" character varying, "State" character varying, "Zipcode" character varying, "CountryId" integer, "ProfileImageUrl" text, "ThumbnailUrl" text, "Active" boolean, "CreatedBy" integer, "CreatedDate" timestamp without time zone, "ModifiedBy" integer, "ModifiedDate" timestamp without time zone, "Guid" uuid, "ReferralBy" integer, "ReferralCode" character varying, "AadharNo" character varying, "ReferredBy" character varying, "ReferredByName" character varying, "FatherOrHusband" text, "HWCPatientId" integer, "Education" character varying, "Occupation" character varying, "Religion" character varying, "Nationality" character varying, "PatientReferredById" integer, "IdProofValue" character varying, "IdProofId" integer, "BloodGroup" character varying, "Amount" numeric, "PaymentStatus" boolean, "TempPatient" boolean, "HowDidYouKnowId" integer, "EducationId" integer, "OccupationId" integer, "BirthMark1" text, "BirthMark2" text, "RelationType" text, "OccupationDetail" text, "IsNewPatient" boolean, "REGID" character varying, "REGNO" integer, "InsuranceCompanyId" integer, "ProviderId" integer, "AppointmentId" integer, "PatientType" character, "AppointmentNo" character varying, "AppointmentTime" time without time zone, "AppointmentEndTime" time without time zone, "AppointmentNotes" character varying, "CouponId" integer, "AppointmentAmount" numeric, "Discount" numeric, "Total" numeric, "Status" character, "PatientFamilyId" integer, "DepartmentId" integer, "PaymentType" character varying, "PaymentNumber" character varying, "AppointmentPaymentStatus" boolean, "VisitTypeId" integer, "ChargeTypesId" integer, "LocationId" integer, "AppointmentTypeId" integer, "PayTypeId" integer, "TokenNumber" integer, "SpecializationId" integer, "ProviderAvailabilityId" integer, "ConsultationTypeId" integer, "DoctorSpecializationChargeModuleDetailsId" integer, "OtherRemarks" character varying, "AuthorityMasterId" integer, "ReasonsId" integer, "Remarks" character varying, "ProviderName" character varying , "ModuleName" character varying, "AppointmentDate" timestamp without time zone, "isActiveAppointmentExists" boolean, "HWCName" character varying, "Description" text, "RowColor" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (
select row_number() over(partition by a."PatientId" order by a."AppointmentId" desc,
a."AppointmentDate" desc )"Max" ,a."PatientId",a."AppointmentId"
from "Appointment" a
join "Patient" pat on a."PatientId" =pat."PatientId"
join "Provider" pr on a."ProviderId" = pr."ProviderId"
where a."Active"=true
--and case when "filter" is null then 1=1 else (TRIM(UPPER(pat."FullName")) ILIKE '%' OR pat."UMRNo" ilike'%' OR pat."Mobile" ILIKE '%')|| "filter"||'%' end
and case when "filter" is null then 1=1 else TRIM(UPPER(pat."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."UMRNo")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(pat."Mobile")) ilike'%'|| "filter"||'%' end
and case when "patientMobile" is null then 1=1 else pat."Mobile" ilike'%'|| "patientMobile"||'%' end
and case when "patientName" is null then 1=1 else pat."FullName" ilike'%'|| "patientName"||'%' end
and case when "appointmentId" is null then 1=1 else a."AppointmentId" = "appointmentId" end
)
, maxapt as (
select a.* from "Appointment" a
join cts on a."AppointmentId"=cts."AppointmentId"
where "Max"=1)
SELECT DISTINCT
id."IdProofName",pf."FullName" as "RelativeName",pf."Relation",
eid."Name" as "EducationName",hid."Name" as "HowDidYouKnow",oid."Name" as "OccupationName",
pat."PatientId",pat. "Salutation",pat. "FirstName",pat. "MiddleName",pat. "LastName",pat. "FullName",pat. "DateOfBirth",pat. "Age",pat. "Gender",pat. "MaritalStatus",pat. "UMRNo",pat. "Email",pat. "Mobile",pat. "StreetAddress",pat. "AddressLine2" as "Area",pat. "City",pat. "State",pat. "Zipcode",pat. "CountryId"
,(CASE WHEN pat."ProfileImageUrl" IS NOT NULL THEN CONCAT("urlLink",'/', pat."Guid", '/', pat."ProfileImageUrl") ELSE '' END) AS "ProfileImageUrl"
,(CASE WHEN pat."ThumbnailUrl" IS NOT NULL THEN CONCAT("urlLink", '/', pat."Guid", '/', pat."ThumbnailUrl") ELSE '' END) AS "ThumbnailUrl"
,pat. "Active",pat. "CreatedBy",pat. "CreatedDate",pat. "ModifiedBy",pat. "ModifiedDate",pat. "Guid",pat. "ReferralBy",pat. "ReferralCode",pat. "AadharNo",referred."Name" as "ReferredBy",pat. "ReferredByName",pat. "FatherOrHusband",pat. "HWCPatientId",pat. "Education",pat. "Occupation",pat. "Religion",pat. "Nationality",pat. "PatientReferredById",pat. "IdProofValue",pat. "IdProofId",pat. "BloodGroup",pat. "Amount",pat. "PaymentStatus",pat. "TempPatient",pat. "HowDidYouKnowId",pat. "EducationId",pat. "OccupationId",pat. "BirthMark1",pat. "BirthMark2",pat. "RelationType",pat. "OccupationDetail",pat. "IsNewPatient",pat. "REGID",pat. "REGNO",pat. "InsuranceCompanyId",
apt."ProviderId",
apt."AppointmentId",
apt."PatientType",
apt."AppointmentNo"
,apt."AppointmentTime"
,apt. "AppointmentEndTime"
,apt. "AppointmentNotes",
apt."CouponId",
apt. "Amount" as "AppointmentAmount",
apt."Discount"
,apt. "Total"
,apt. "Status"
,apt. "PatientFamilyId"
,apt. "DepartmentId"
,apt. "PaymentType"
,apt. "PaymentNumber"
,apt. "PaymentStatus"
, apt."VisitTypeId"
, apt."ChargeTypesId"
, apt."LocationId"
, apt."AppointmentTypeId"
, apt."PayTypeId"
, apt."TokenNumber"
, apt."SpecializationId"
, apt."ProviderAvailabilityId"
, apt."ConsultationTypeId"
, apt."DoctorSpecializationChargeModuleDetailsId"
, apt."OtherRemarks"
, apt."AuthorityMasterId"
, apt."ReasonsId"
, apt."Remarks"
,pr."FullName" as "ProviderName",MM."ModuleName"
,(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"
, HWC."HWCName", HWC."Description", HWC."RowColor"
FROM "Patient" pat
left join maxapt apt on apt."PatientId" = pat."PatientId" and apt."Status" <> 'C' and apt."Active"=true
left join "Provider" pr on pr."ProviderId" = apt."ProviderId"
left join "HWCPatient" HWC on HWC."HWCPatientId" = pat."HWCPatientId"
LEFT JOIN "PatientReferredBy" referred ON referred."PatientReferredById" = pat."PatientReferredById"
left join "IdProof" id on id."IdProofId" = pat."IdProofId"
left join "HowDidYouKnow" hid on hid."HowDidYouKnowId" = pat."HowDidYouKnowId"
left join "Education" eid on eid."EducationId" = pat."EducationId"
left join "Occupation" oid on oid."OccupationId" = pat."OccupationId"
left join "PatientFamily" pf on pf."PatientId" = pat."PatientId"
left join "WebNotification" wn on wn."PatientId" = pat."PatientId"
left join "ModulesMaster" MM on MM."ModulesMasterId" = wn."ModulesMasterId"
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
and case when "appointmentId" is null then 1=1 else apt."AppointmentId" = "appointmentId" end
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchPatients_For_AppointmentScheduleFollowUp"(character varying, character varying, character varying, character varying, integer)
OWNER TO postgres;
INSERT INTO public."ModulesMaster"(
"ModulesMasterId", "ModuleName", "ModuleIcon", "ModuleDescription", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "PackageType", "IsChargeCategoryApplicable", "IsDoctorChargeCategoryApplicable")
VALUES (11, 'NewPatients','mdi mdi-eye', 'This is for New Patient Booking Appointment with pay later',null,null,null,null,null,false,false);
INSERT INTO public."ModulesMaster"(
"ModulesMasterId", "ModuleName", "ModuleIcon", "ModuleDescription", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "PackageType", "IsChargeCategoryApplicable", "IsDoctorChargeCategoryApplicable")
VALUES (12, 'Emergency','mdi mdi-eye', 'This is for Emergency Patient Booking Appointment with pay later',null,null,null,null,null,false,false);
INSERT INTO public."ModulesMaster"(
"ModulesMasterId", "ModuleName", "ModuleIcon", "ModuleDescription", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "PackageType", "IsChargeCategoryApplicable", "IsDoctorChargeCategoryApplicable")
VALUES (13, 'WalkIn','mdi mdi-eye', 'This is for walk- inPatient Booking Appointment with pay later',null,null,null,null,null,false,false);
Alter table "LocationAccountMap" Add column "Active" boolean;
Alter table "LocationAccountMap" Add column "CreatedBy" integer;
Alter table "LocationAccountMap" Add column "CreatedDate" timestamp without time zone;
Alter table "LocationAccountMap" Add column "ModifiedBy" integer;
Alter table "LocationAccountMap" Add column "ModifiedDate" timestamp without time zone;
ALTER TABLE "LocationAccountMap" ALTER COLUMN "Active" SET DEFAULT true;
update "LocationAccountMap" set "Active" = true;
---------function query for fetching doctors while booking appointments query where location is not available query change ----------
-- FUNCTION: public.udf_FetchDoctor_With_Availability_Specialization_Op(character varying, integer, integer, character varying)
-- DROP FUNCTION IF EXISTS public."udf_FetchDoctor_With_Availability_Specialization_Op"(character varying, integer, integer, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchDoctor_With_Availability_Specialization_Op"(
filter character varying DEFAULT NULL::text,
"locationId" integer DEFAULT NULL::integer,
"consultationTypeId" integer DEFAULT NULL::integer,
"appointmentDate" character varying DEFAULT NULL::text)
RETURNS TABLE("ProviderAvailabilityId" integer, "FullName" character varying, "DepartmentName" character varying, "DepartmentId" integer, "ProviderId" integer, "SpecializationId" integer, "SpecializationName" character varying, "LocationId" integer, "ConsultationTypeId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
SELECT DISTINCT on (pr2."ProviderId", s."SpecializationId") prl."ProviderAvailabilityId" ,pr2."FullName"
, d."DepartmentName" , d."DepartmentId"
,pr2."ProviderId"
, s. "SpecializationId", s."SpecializationName"
, CMT."LocationId", prl."ConsultationTypeId"
FROM "ProviderAvailability" prl
Join "DoctorSpecializationMap" LSM on LSM."ProviderId" = prl."ProviderId" and LSM."SpecializationId" = prl."SpecializationId" and LSM."ConsultationTypeId" = prl."ConsultationTypeId"
join "DoctorSpecializationChargeModuleDetails" DSCD on DSCD."ReferenceId" = LSM."DoctorSpecializationMapId"
join "DoctorSpecializationChargeModuleCategory" DSCC on DSCC."DoctorSpecializationChargeModuleCategoryId" = DSCD."DoctorSpecializationChargeModuleCategoryId"
join "ChargeModuleTemplate" CMT on CMT."ChargeModuleTemplateId" = DSCC."ChargeModuleTemplateId"
JOIN "Provider" pr2 on pr2."ProviderId" = LSM."ProviderId" and pr2."Active" is true
join "Account" pa on pa."ReferenceId" = pr2."ProviderId" and pa."Active" is true and pa."RoleId" = 3
JOin "LocationAccountMap" LAM on LAM."AccountId" = pa."AccountId" and LAM."Active" IS TRUE
join "Specialization" s on s."SpecializationId" = ANY (pr2."Specializations")
JOIN "Location" pral on pral."LocationId" = CMT."LocationId" AND pral."Active" IS TRUE
JOIN "Practice" pra on pra."PracticeId" = pral."PracticeId" AND pra."Active" IS TRUE
JOIN "Department" d on d."DepartmentId" = pr2."DepartmentId"
where pr2."Active" is true and CMT."LocationId" = "locationId" and s."Active" = true
--and CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date
and "IsInUse" is true
and case when "filter" is null then 1=1 else TRIM(UPPER(pr2."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(s."SpecializationName")) ilike'%'|| "filter"||'%' end
and case when "consultationTypeId" is null then 1=1 else prl."ConsultationTypeId" = "consultationTypeId" end
and case when "appointmentDate" is null then CMT."StartDate"::date <= current_date::date and CMT."EndDate"::date >= current_date::date else CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date end
--and case when "locationId" is null then 1=1 else LAM."LocationId" = "LocationId" end
--order by "FullName" asc
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchDoctor_With_Availability_Specialization_Op"(character varying, integer, integer, character varying)
OWNER TO postgres;
-- FUNCTION: public.widget_Table_OnlineAppointmentDashboard(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_OnlineAppointmentDashboard"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_OnlineAppointmentDashboard"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentNo" character varying, "AppointmentTime" text, "AppointmentId" integer, "SpecializationName" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation", Pa."FullName" as "PatientName",Pa."UMRNo",
apt."AppointmentNo" ,-- apt."AppointmentTime"::text
TO_CHAR(apt."AppointmentTime", 'hh12:mi AM'),
apt."AppointmentId",s."SpecializationName"
from "Appointment" apt
join "ConsultationType" AT on AT."ConsultationTypeId" =apt."ConsultationTypeId"
join "Patient" Pa on Pa."PatientId" = apt."PatientId"
join "Provider" Pr on Pr."ProviderId" = apt."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (Pr."Specializations")
where apt."AppointmentDate"::date="fromDate" and apt."Active" is true and AT."ConsultationTypeId" =2
and case when "referenceId" is null then 1=1 else apt."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else apt."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_OnlineAppointmentDashboard"(date, integer, integer)
OWNER TO postgres;
CREATE SEQUENCE "NurseNote_NurseNoteId_seq";
CREATE TABLE IF NOT EXISTS public."NurseNote"
(
"NurseNoteId" integer NOT NULL DEFAULT nextval('"NurseNote_NurseNoteId_seq"'::regclass),
"Note" text COLLATE pg_catalog."default" NOT NULL,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"AdmissionId" integer NOT NULL,
CONSTRAINT "PK_NurseNoteId" PRIMARY KEY ("NurseNoteId"),
CONSTRAINT "FK_NurseNote_AdmissionId" FOREIGN KEY ("AdmissionId")
REFERENCES public."Admission" ("AdmissionId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_NurseNote_CreatedById" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
\ No newline at end of file
alter table IF EXISTS "PatientMedicationHeader"
add column IF NOT EXISTS "AdmissionId" integer,
add CONSTRAINT "PatientMedicationHeader" FOREIGN KEY ("AdmissionId")
REFERENCES public."Admission" ("AdmissionId") MATCH SIMPLE;
---------------------------------------
alter table IF EXISTS "PatientLabHeader"
add column IF NOT EXISTS "AdmissionId" integer,
add CONSTRAINT "PatientLabHeader_AdmissionId_fkey" FOREIGN KEY ("AdmissionId")
REFERENCES public."Admission" ("AdmissionId") MATCH SIMPLE;
\ No newline at end of file
-- SEQUENCE: public.DoctorAvailabilityVisitType_DoctorAvailabilityVisitTypeId_seq
-- DROP SEQUENCE IF EXISTS public."DoctorAvailabilityVisitType_DoctorAvailabilityVisitTypeId_seq";
CREATE SEQUENCE IF NOT EXISTS public."DoctorAvailabilityVisitType_DoctorAvailabilityVisitTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."DoctorAvailabilityVisitType_DoctorAvailabilityVisitTypeId_seq"
OWNER TO postgres;
-------------------------------------------------------
-- Table: public.DoctorAvailabilityVisitType
-- DROP TABLE IF EXISTS public."DoctorAvailabilityVisitType";
CREATE TABLE IF NOT EXISTS public."DoctorAvailabilityVisitType"
(
"DoctorAvailabilityVisitTypeId" integer NOT NULL DEFAULT nextval('"DoctorAvailabilityVisitType_DoctorAvailabilityVisitTypeId_seq"'::regclass),
"Duration" integer,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"LocationId" integer,
"ProviderId" integer,
"SpecializationId" integer,
CONSTRAINT "DoctorAvailabilityVisitType_pkey" PRIMARY KEY ("DoctorAvailabilityVisitTypeId"),
CONSTRAINT "DoctorAvailabilityVisitType_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorAvailabilityVisitType_ProviderId_fkey" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DoctorAvailabilityVisitType_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."DoctorAvailabilityVisitType"
OWNER to postgres;
COMMENT ON COLUMN public."DoctorAvailabilityVisitType"."DoctorAvailabilityVisitTypeId"
IS ' ';
\ No newline at end of file
create table "VaccineGroup"(
"VaccineGroupId" serial primary key,
"VaccineGroupName" text,
"Description" text,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
create table "VaccineType"(
"VaccineTypeId" serial primary key,
"TypeName" varchar(300),
"RowColor" varchar(250)
);
create table "VaccineMaster"(
"VaccineMasterId" serial primary key,
"VaccineGroupId" int references "VaccineGroup"("VaccineGroupId"),
"VaccineName" text,
"DisplayName" text,
"VaccineInstruction" text,
"Order" int,
"VaccineTypeId" int references "VaccineType"("VaccineTypeId"),
"AllowedDays" int,
"AllowedYear" int,
"AllowedMonth" int,
"ExclusionDays" text,
"AllowedLapsDays" int,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
create table "VaccineDependency"(
"VaccineDependencyId" serial primary key,
"VaccineMasterId" int references "VaccineMaster"("VaccineMasterId"),
"DependentOn" int references "VaccineMaster"("VaccineMasterId")
);
insert into "VaccineType" ("TypeName", "RowColor")
values
('Compulsory','#ffff'),
('Additional Vaccine','#90ee90'),
('Special Vaccine','#ffc0cb');
alter table "VaccineMaster" drop column"AllowedYear",drop column"AllowedMonth" ,
add column "AllowedType" varchar(10);
alter table "ProviderLeave" add column "ProviderLeaveStartTime" time without time zone;
alter table "ProviderLeave" add column "ProviderLeaveEndTime" time without time zone;
\ No newline at end of file
CREATE OR REPLACE FUNCTION public.upgrade_chargetemplate(
chargetemplateid integer,
locationid integer,
templatename text,
startdate timestamp without time zone,
endtdate timestamp without time zone,
modulesmasterid integer,
increasetype character varying,
increasevalue numeric)
RETURNS integer
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
new_id INTEGER;
BEGIN
-- Insert the new user and retrieve the value of the id column into the new_id variable
INSERT INTO public."ChargeModuleTemplate"(
"StartDate", "EndDate", "Active", "TemplateName", "CreatedBy", "CreatedDate", "LocationId")
VALUES (startdate,endtdate,True,TemplateName,6776,now(),LocationId)
RETURNING "ChargeModuleTemplateId" INTO new_id;
INSERT INTO public."ChargeModuleCategory"(
"Active", "ChargeCategoryId", "ModulesMasterId", "ChargeModuleTemplateId", "ChargeModuleRefTemplateId", "CreatedBy", "CreatedDate")
--VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
select "Active", "ChargeCategoryId", "ModulesMasterId",new_id as "ChargeModuleTemplate", ChargeTemplateId as "ChargeModuleRefTemplateId"
, 6776 "CreatedBy",now () as "CreatedDate"
from public."ChargeModuleCategory" where "ChargeModuleTemplateId"=ChargeTemplateId
and case when ModulesMasterId is null then 1=1 else "ModulesMasterId"=ModulesMasterId end
;
INSERT INTO public."ChargeModuleDetails"(
"ReferenceId", "ChargeModuleCategoryId", "Amount", "LocationId", "CreatedBy", "CreatedDate")
--VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
select b."ReferenceId",a."Refcatid",
case when IncreaseType='P' then b."Amount"+round((b."Amount"*IncreaseValue)/100,2)
when IncreaseType='P' then b."Amount"+IncreaseValue else b."Amount" end
, b."LocationId",6776,now() from (
select a."ChargeModuleCategoryId",b."ChargeModuleCategoryId" as "Refcatid" from "ChargeModuleCategory" a
join "ChargeModuleCategory" b on a."ChargeCategoryId"=b."ChargeCategoryId"
where a."ChargeModuleRefTemplateId" is null and b."ChargeModuleRefTemplateId" is not null
and b."ChargeModuleRefTemplateId"=ChargeTemplateId and a."ChargeModuleTemplateId"=ChargeTemplateId ) a
join "ChargeModuleDetails" b on a."ChargeModuleCategoryId"=b."ChargeModuleCategoryId";
INSERT INTO "ChargeModuleTemplateByLog" ("TemplateId","StartDate" ,"EndDate" ,"LocationId",
"RefTemplateId","ModulesMasterId" ,"IncreaseType","IncreaseValue" )
select new_id,startdate,endtdate,LocationId,ChargeTemplateId,ModulesMasterId,IncreaseType,IncreaseValue
;
-- Return the new_id value
RETURN new_id;
END;
$BODY$;
--------------------------------------------------------------------------------------------------------------------------
ALTER TABLE "LabMainDetail"
ADD COLUMN "NablRequired" boolean DEFAULT false;
\ No newline at end of file
alter table "ObEncounter"
add column "IsAppointmentClosed" boolean default false
\ No newline at end of file
INSERT INTO "Lookup" ( "Name", "Description")
VALUES ('DoctorWeek', 'To select what are the weeks available');
INSERT INTO "LookupValue" ( "LookupId", "Name", "CreatedDate", "CreatedBy")
VALUES (22, 'EveryDay', Current_date, 1029);
INSERT INTO "LookupValue" ( "LookupId", "Name", "CreatedDate", "CreatedBy")
VALUES (22, 'Weekly', Current_date, 1029);
INSERT INTO "LookupValue" ( "LookupId", "Name", "CreatedDate", "CreatedBy")
VALUES (22, 'Biweekly', Current_date, 1029);
alter table "ProviderAvailability" add column "DoctorWeekId" integer;
alter table "ProviderBreak" add column "DoctorWeekId" integer;
\ No newline at end of file
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, text[], integer, integer)
-- DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, text[], integer, integer);
CREATE OR REPLACE FUNCTION public."udf_uiReport_fetch_Appointments_Location"(
locationid integer DEFAULT NULL::integer,
"appointmentNo" text DEFAULT NULL::text,
"departmentId" integer[] DEFAULT NULL::integer[],
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"uMRNo" text DEFAULT NULL::text,
"patientReferredById" integer[] DEFAULT NULL::integer[],
"referredByName" text DEFAULT NULL::text,
mobile text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"appointmentTypeId" integer[] DEFAULT NULL::integer[],
"paymentStatus" boolean DEFAULT NULL::boolean,
status text[] DEFAULT NULL::text[],
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "AppointmentTypeName" character varying, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "VisitorName" character varying, "ReferredByName" character varying, "PatientName" character varying, "PatientAge" smallint, "UMRNo" character varying, "Mobile" character varying, "PatientGender" character, "AppointmentTime" time without time zone, "VisitType" character, "PaymentType" character varying, "PaymentNumber" character varying, "TotalAppointments" bigint, "TotalAmount" bigint, "TotalAmountStr" text, "ReceiptCreatedByName" text, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" text, "PaymentStatus" boolean, "EncounterType" encountertype_elements, "Status" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (select coalesce(A."DepartmentId"::text,'GrandTotal') "DepartmentId",
A."ProviderId"::text as "ProviderId",
A."AppointmentDate",A."AppointmentTypeId",
ATN."VisitorName" "AppointmentTypeName",
A."AppointmentNo",A."PatientId" "PatientId",PRB."Name",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
case when ATN."VisitorName"='Follow Up' and sum(A."Total")=0 then 'Free Follow Up'
else PT."PayTypeName" end as "PaymentType" ,A."PaymentNumber",
A."AppointmentId",
case when A."Status"='B' then 'Booked' when A."Status"='R' then 'Rescheduled' when A."Status"='C' then 'Cancel' end::text as "Status",
COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::text as "TotalAmountStr" ,
sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband",
A."PaymentStatus",
A."EncounterType"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "VisitType" ATN on A."VisitTypeId"=ATN."VisitTypeId"
where
--A."Status"<>'C' and
case when "departmentId" is null then 1=1 else A."DepartmentId" = any("departmentId") end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END and
case when "patientId" is null then 1=1 else Pa."PatientId" = any("patientId") end and
case when "appointmentNo" is null then 1=1 when "appointmentNo" ='' then 1=1 else A."AppointmentNo" ilike'%'||"appointmentNo" ||'%' end and
case when "providerId" is null then 1=1 else A."ProviderId" = any("providerId") end and
case when "uMRNo" is null then 1=1 when "uMRNo" ='' then 1=1 else Pa."UMRNo" ilike'%'||"uMRNo" ||'%' end and
case when "patientReferredById" is null then 1=1 else Pa."PatientReferredById" = any("patientReferredById") end and
case when "appointmentTypeId" is null then 1=1 else ATN."VisitTypeId" = any("appointmentTypeId") end and
case when "referredByName" is null then 1=1 when "referredByName" ='' then 1=1 else Pa."ReferredByName" ilike'%'||"referredByName" ||'%' end and
case when "mobile" is null then 1=1 when "mobile" ='' then 1=1 else Pa."Mobile" ilike'%'||"mobile" ||'%' end and
case when "payTypeId" is null then 1=1 else A."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end and
case when "paymentStatus" is null then 1=1 else A."PaymentStatus" ="paymentStatus" end
and case when "status" is null then 1=1 else A."Status" =any("status") end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."PatientId",PRB."Name",
Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",A."AppointmentTypeId",
ATN."VisitorName" ,
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband",A."PaymentStatus",A."EncounterType"), (A."DepartmentId",A."ProviderId"), ())
order by A."AppointmentId")
select A."DepartmentId",coalesce(D."DepartmentName",'GrandTotal') "DepartmentName",
case when A."AppointmentNo" is null then 'Total' else A."ProviderId" end "ProviderId",
case when A."AppointmentNo" is null then 'Total' else Pr."FullName" end as "ProviderName",
ATN."Name" "AppointmentTypeName",
A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else PRB."Name"::varchar end as "Name",
case when A."AppointmentNo" is null then null else Pa."ReferredByName"::varchar end as "ReferredByName",
case when A."AppointmentNo" is null then null else Pa."FullName"::varchar end as "PatientName",
case when A."AppointmentNo" is null then null else Pa."Age" end "PatientAge",
case when A."AppointmentNo" is null then null else Pa."UMRNo" end "UMRNo",
case when A."AppointmentNo" is null then null else Pa."Mobile" end "Mobile",
case when A."AppointmentNo" is null then null else Pa."Gender" end "PatientGender",
A."AppointmentTime",
A."VisitType",A."PaymentType",A."PaymentNumber",A."TotalAppointments",A."TotalAmount",A."TotalAmountStr",
CA."FullName" "ReceiptCreatedByName", R."CreatedDate" "ReceiptDate",R."ReceiptId",
case when A."AppointmentNo" is null then null else Pa."StreetAddress" end "StreetAddress",
case when A."AppointmentNo" is null then null else Pa."City" end "City",
case when A."AppointmentNo" is null then null else Pa."State" end "State",
A."FatherOrHusband",
A."PaymentStatus",A."EncounterType",A."Status"
from cts A
left join "Department" D on A."DepartmentId"=D."DepartmentId"::text
left join "Provider" Pr on Pr."ProviderId"::text=A."ProviderId"
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left Join "Receipt" R on R."RespectiveId"=A."AppointmentId" and R."ReceiptAreaTypeId"=4
Left Join "Account" CA on CA."AccountId"=R."CreatedBy"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on ATN."AppointmentTypeId"=A."AppointmentTypeId"
order by A."AppointmentId"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, text[], integer, integer)
OWNER TO postgres;
alter table "Menu" add "EncounterKey" varchar(150)
\ No newline at end of file
-- FUNCTION: public.widget_Table_otAppointmentDashboard1(date, integer, integer)
-- DROP FUNCTION IF EXISTS public."widget_Table_otAppointmentDashboard1"(date, integer, integer);
CREATE OR REPLACE FUNCTION public."widget_Table_otAppointmentDashboard1"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("Salutation" character varying, "PatientName" text, "UMRNo" character varying, "AppointmentTime" text, "SpecializationName" character varying, "SurgeryId" integer, "SurgeryName" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select Pa."Salutation",Pa."FullName" as "PatientName",Pa."UMRNo",
TO_CHAR(ot."SignInDate", 'hh12:mi AM') as "AppointmentTime",
s."SpecializationName",ot."SurgeryId",s1."Name" as "SurgeryName"
from "OTRegister" ot
--join "AppointmentType" AT on AT."AppointmentTypeId" =apt."AppointmentTypeId"
join "Patient" Pa on Pa."PatientId" = ot."PatientId"
join "Provider" Pr on Pr."ProviderId" = ot."ProviderId"
join "Specialization" s on s."SpecializationId" = ANY (Pr."Specializations")
join "Surgery" s1 on s1."SurgeryId"=ot."SurgeryId"
where
ot."SignInDate"::date="fromDate" and ot."Active" is true
and case when "referenceId" is null then 1=1 else ot."ProviderId"= "referenceId" end
and case when "locationId" is null then 1=1 else ot."LocationId"= "locationId" end
;
end
$BODY$;
ALTER FUNCTION public."widget_Table_otAppointmentDashboard1"(date, integer, integer)
OWNER TO postgres;
ALTER TYPE encountertype_elements ADD VALUE 'DietPlanEncounter' after 'PediatricEncounter' ;
CREATE TABLE IF NOT EXISTS public."DietPlanEncounter"
(
"DietPlanEncounterId" serial primary key,
"AppointmentId" integer,
"DietPlanEncounterDate" timestamp(6) without time zone NOT NULL,
"DietPlanPrescribed" text COLLATE pg_catalog."default",
"OpNutritionScreening" text COLLATE pg_catalog."default",
"OpNutritionAssessment" text COLLATE pg_catalog."default",
"IpNutritionScreening" text COLLATE pg_catalog."default",
"PediatricCDCScreening" text COLLATE pg_catalog."default",
"DietGuidlines" text COLLATE pg_catalog."default",
"AdmissionId" integer,
CONSTRAINT "UQ_DietPlanEncounter" UNIQUE ("AppointmentId")
);
alter table "Admission" add column "BedAssociatedData" text;
alter table "Admission" add column "NRIData" text;
alter table "Admission" add column "SurrogacyData" text;
alter table "Admission" add column "EmergencyInfo" text;
alter table "ChargeModuleDetails" drop CONSTRAINT "ChargeModuleDetails_LocationId_fkey";
\ No newline at end of file
DROP FUNCTION IF EXISTS public."udf_fetch_Admission_Location"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer);
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public."udf_fetch_Admission_Location"(
"admissionNo" text DEFAULT NULL::text,
"providerId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"isDischarged" boolean DEFAULT NULL::boolean,
"patientMobileNo" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"dischargeDate" date DEFAULT NULL::date,
"uMRNo" text DEFAULT NULL::text,
active boolean DEFAULT NULL::boolean,
locationid integer DEFAULT NULL::integer,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("AdmissionId" integer, "AdmissionNo" text, "IsConvertedFromOPtoIp" boolean, "AdmissionDate" timestamp without time zone, "AdmissionTime" time without time zone, "PatientName" text, "UMRNo" character varying, "PatientAge" smallint, "PatientGender" character, "patientMobile" character varying, "ProviderAge" smallint, "ProviderGender" character, "ProviderName" text, "DepartmentName" text, "WardName" character varying, "RoomName" character varying, "BedNumber" character varying, "AttendantName" character varying, "AttendantRelationWithPatient" character varying, "AttendantContactNo" character varying, "IsDischarged" boolean, "DischargeDate" date, "DischargeTime" time without time zone, "DischargeStatus" character varying, "IsMaternity" boolean, "EncounterId" integer, "SurgeryName" character varying, "ProviderThumbnailUrl" text, "PatientThumbnailUrl" text, "BedId" integer, "RoomId" integer, "WardId" integer, "DepartmentId" integer, "PatientId" integer, "ProviderId" integer, "SurgeryTypeId" integer, "PatientType" character, "AdmissionNotes" text, "PaidAmount" numeric, "FinalAmount" numeric, "PaymentStatus" text, "IsFinalBill" boolean, "TotalItems" bigint, "Active" boolean, "ExpectedDischargeDate" timestamp without time zone, "DischargedBy" integer, "DischargedByRole" text, "DischargedByName" text,"ChargeCategoryId" integer,"ChargeCategoryName" character varying,"CaseTypeId" integer,"AdmissionPayTypeId" integer,"ReferralDoctorId" integer,"InsuranceCompanyId" integer,"TpaId" integer,"PatientOrganization" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
With TotalItems as (
select count(distinct A."AdmissionId")::bigint "TotalItems"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
join "ChargeCategory" cc on cc."ChargeCategoryId" = R."ChargeCategoryId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
where
case when "admissionNo" is null then 1=1
when "admissionNo"='' then 1=1
else A."AdmissionNo" ilike '%'||"admissionNo"||'%' end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END AND
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "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
)
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",R."ChargeCategoryId",cc."ChargeCategoryName",A."CaseTypeId",
A."AdmissionPayTypeId",A."ReferralDoctorId",A."InsuranceCompanyId",A."TpaId" ,A."PatientOrganization"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
join "ChargeCategory" cc on cc."ChargeCategoryId" =R."ChargeCategoryId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
left join "Account" AC on AC."AccountId"=A."DischargedBy"
left join "Role" RL on RL."RoleId"= AC."RoleId"
left join "Provider" PRO on PRO."ProviderId"=AC."ReferenceId"
left join "Department" DP on DP."DepartmentId"=PRO."DepartmentId"
where
case when "admissionNo" is null then 1=1
when "admissionNo"='' then 1=1
else A."AdmissionNo" ilike '%'||"admissionNo"||'%' end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END AND
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "providerId" is null then 1=1
else Pr."ProviderId" = "providerId" end and
case when "isDischarged" is null then 1=1
when "isDischarged" =true then ds."AdmissionId"=A."AdmissionId"
when "isDischarged" =false then ds."AdmissionId" is null
end AND
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate"::date and A."AdmissionDate"::date <="toDate" end
AND
case when "dischargeDate" is null then 1=1 else "dischargeDate" =ds."DischargeDate"::date end
and
case when "uMRNo" is null then 1=1
when "uMRNo"='' then 1=1
else Pa."UMRNo" ilike '%'||"uMRNo"||'%' end
group by A."AdmissionId",A."AdmissionNo",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName",Pa."UMRNo",Pa."Age" ,Pa."Gender" ,Pr."Age" ,Pr."Gender" ,
Pr."FullName",D."DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName",A."AttendantRelationWithPatient",A."AttendantContactNo" , ds."DischargeId"
,ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus",pa."Mobile"
,A."IsMaternity",A."EncounterId",st."SurgeryName",pr."ThumbnailUrl", pr."Guid",pr."ThumbnailUrl" ,pa."Guid", pa."ThumbnailUrl",
A."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,FB."FinalAmount" ,FB."FinalBillId",
RL."RoleId",DP."DepartmentName",PRO."FullName",AC."FullName",R."ChargeCategoryId",cc."ChargeCategoryName"
order by A."AdmissionId" desc
limit "pageSize" offset ("pageSize"*"pageIndex");
END
$BODY$;
create sequence "DynamicTemplateConfig_DynamicTemplateConfigId_seq"
CREATE TABLE IF NOT EXISTS public."DynamicTemplateConfig"
(
"DynamicTemplateConfigId" bigint NOT NULL DEFAULT nextval('"DynamicTemplateConfig_DynamicTemplateConfigId_seq"'::regclass),
"ReportName" character varying(255) COLLATE pg_catalog."default",
"DynamicReportId" bigint NOT NULL,
"Active" boolean DEFAULT true,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DynamicTemplateConfig_pkey" PRIMARY KEY ("DynamicTemplateConfigId"),
CONSTRAINT "FK_DynamicTemplateConfig_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DynamicTemplateConfig_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DynamicTemplateConfig_DynamicReportId" FOREIGN KEY ("DynamicReportId")
REFERENCES public."DynamicReport" ("DynamicReportId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
--------------------------------------------------------------------------------------------------------------------------
insert into "LogType" values (77, 'DynamicTemplateConfig', true)
Alter Table "GynEncounter"
add column "ProformaForOasi" text
\ No newline at end of file
alter table "VaccineMaster" alter column "AllowedDays" type numeric(8,2);
alter table "VaccineMaster" add column "Active" boolean default true;
\ No newline at end of file
alter table "ChargeModuleCategory" add "ChargeModuleRefTemplateId" int
--------------------------------------------------------------------------------------------------------------------------------------------
create sequence "ChargeModuleTemplateByLog_ChargeModuleTemplateByLogId_seq";
CREATE TABLE IF NOT EXISTS public."ChargeModuleTemplateByLog"
(
"ChargeModuleTemplateByLogId" integer NOT NULL DEFAULT nextval('"ChargeModuleTemplateByLog_ChargeModuleTemplateByLogId_seq"'::regclass),
"TemplateId" integer,
"StartDate" date,
"EndDate" date,
"LocationId" integer,
"RefTemplateId" integer,
"ModulesMasterId" integer,
"IncreaseType" character varying(10) COLLATE pg_catalog."default",
"IncreaseValue" numeric,
"CreatedDate" timestamp without time zone DEFAULT now(),
CONSTRAINT "ChargeModuleTemplateByLog_pkey" PRIMARY KEY ("ChargeModuleTemplateByLogId")
);
--------------------------------------------------------------------------------------------------------------------------------------------
DROP FUNCTION IF EXISTS public.upgrade_chargetemplate(integer, integer, text, timestamp without time zone, timestamp without time zone, integer, character varying, numeric);
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public.upgrade_chargetemplate(
chargetemplateid integer,
locationid integer,
templatename text,
startdate timestamp without time zone,
endtdate timestamp without time zone,
modulesmasterid integer,
increasetype character varying,
increasevalue numeric)
RETURNS integer
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
new_id INTEGER;
BEGIN
-- Insert the new user and retrieve the value of the id column into the new_id variable
INSERT INTO public."ChargeModuleTemplate"(
"StartDate", "EndDate", "Active", "TemplateName", "CreatedBy", "CreatedDate", "LocationId")
VALUES (startdate,endtdate,True,TemplateName,6776,now(),LocationId)
RETURNING "ChargeModuleTemplateId" INTO new_id;
INSERT INTO public."ChargeModuleCategory"(
"Active", "ChargeCategoryId", "ModulesMasterId", "ChargeModuleTemplateId", "ChargeModuleRefTemplateId", "CreatedBy", "CreatedDate")
--VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
select "Active", "ChargeCategoryId", "ModulesMasterId",new_id as "ChargeModuleTemplate", ChargeTemplateId as "ChargeModuleRefTemplateId"
, 6776 "CreatedBy",now () as "CreatedDate"
from public."ChargeModuleCategory" where "ChargeModuleTemplateId"=ChargeTemplateId
and case when ModulesMasterId is null then 1=1 else "ModulesMasterId"=ModulesMasterId end
;
INSERT INTO public."ChargeModuleDetails"(
"ReferenceId", "ChargeModuleCategoryId", "Amount", "LocationId", "CreatedBy", "CreatedDate")
--VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
select b."ReferenceId",a."Refcatid",
case when IncreaseType='P' then b."Amount"+round((b."Amount"*IncreaseValue)/100,2)
when IncreaseType='A' then b."Amount"+IncreaseValue else b."Amount" end
, b."LocationId",6776,now() from (
select a."ChargeModuleCategoryId",b."ChargeModuleCategoryId" as "Refcatid" from "ChargeModuleCategory" a
right join "ChargeModuleCategory" b on a."ChargeModuleTemplateId"=b."ChargeModuleRefTemplateId"
and a."ChargeCategoryId"=b."ChargeCategoryId" and a."ModulesMasterId"=b."ModulesMasterId"
where b."ChargeModuleRefTemplateId"=ChargeTemplateId and b."ChargeModuleTemplateId"=new_id
and a."ChargeModuleTemplateId"=ChargeTemplateId
) a
join "ChargeModuleDetails" b on a."ChargeModuleCategoryId"=b."ChargeModuleCategoryId";
INSERT INTO "ChargeModuleTemplateByLog" ("TemplateId","StartDate" ,"EndDate" ,"LocationId",
"RefTemplateId","ModulesMasterId" ,"IncreaseType","IncreaseValue" )
select new_id,startdate,endtdate,LocationId,ChargeTemplateId,ModulesMasterId,IncreaseType,IncreaseValue
;
-- Return the new_id value
RETURN new_id;
END;
$BODY$;
-------------------------------------------------------------------------------------------------------------------------------------------------
insert into "LabLogType" ("LogTypeName","Active")
values('Lab_Masters_Machine',true),('Lab_Masters_Parameter',true),
('Lab_Masters_Component',true),('Lab_Masters_Template',true),
('Lab_Cancelling_Test',true),('Lab_Sample_Collection',true),
('Lab_Sample_Transfer',true),('Lab_Sample_Receive',true);
---------------------------------------------------------------------------------------
ALTER TABLE IF EXISTS public."PackageModule" ADD COLUMN "ExpiresIn" smallint;
\ No newline at end of file
DROP FUNCTION IF EXISTS public."revenue_EmployeeDetailTransactionWise"(date, date, integer, integer);
CREATE OR REPLACE FUNCTION public."revenue_EmployeeDetailTransactionWise"(
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
accountid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer)
RETURNS TABLE("AccountId" integer, "ReceiptCreatedBy" text, "RoleName" character varying, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "ReceiptTypeId" integer, "AreaType" character varying, "RefId" character varying, "PayTypeName" character varying, "PaymentDetails" character varying, "PaidAmount" numeric, "PatientName" text, "UMRNo" character varying, "Mobile" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" and lower(rol."RoleName") <> lower('Patient')
where a."RoleId"<>4 --and a."AccountId"=6776 and LAM."LocationId"=2
and case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationid IS NULL OR locationid=0) THEN 1=1 ELSE LAM."LocationId"=locationid END
)
, appointment as (
select R."ReceiptId",A."FullName" "ReceiptCreatedBy",Rl."RoleName",R."CreatedDate" "ReceiptDate",R."CreatedBy",RT."Name" as "AreaType"
, R."Cost" as "PaidAmount" ,R."ReceiptTypeId"
,Ad."FollowUpForAppointmentId",
Ad."AppointmentDate",Ad."AppointmentNo", Ad."AppointmentTime",Ad."LocationId",
pa."FullName" "PatientName",Pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",Ad."PaymentType",
pt."PayTypeName",R."PaymentDetails" , R."AppointmentId",R."IsAppointmentReceipt"
from "Receipt" R
join "Appointment" Ad on Ad."AppointmentId"=R."RespectiveId"
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"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."Active" <> false and R."ReceiptAreaTypeId" in (4,5) and
--R."CreatedBy" =6776 and Ad."LocationId" = 2
--and R."CreatedDate"::date ='2023-04-18'
case when "accountid" is null then 1=1 else R."CreatedBy" = "accountid" end
and case when "locationid" is null then 1=1 else Ad."LocationId" = "locationid" end
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end
and case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end
)
,patient as(
select
R."Cost" as "PaidAmount",
A."FullName" as "ReceiptCreatedBy",Rl."RoleName",
P."FullName" as "PatientName",P."FirstName",P."MiddleName",P."LastName",
P."Age",P."Gender",P."UMRNo",P."Mobile",P."DateOfBirth",
R."ReceiptId",R."CreatedBy",RT."Name" as "AreaType",P."PatientId",
PT."PayTypeName",R."PaymentDetails",R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
FROM "Receipt" R
join "Patient" P on P."PatientId" = R."RespectiveId"
join "Account" PA on PA."ReferenceId"=P."PatientId"
JOIN "LocationAccountMap" LAM on LAM."AccountId"=PA."AccountId"
join "Account" A on A."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" PT on PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId" in (3,6)
-- and LAM."LocationId"=2 and R."CreatedDate"::date='2023-04-14 and R."CreatedBy"=6776
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else LAM."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end
)
,admission as (
select R."ReceiptId",Rl."RoleName",R."CreatedDate" "ReceiptDate",
A."FullName" "ReceiptCreatedBy" ,pt."PayTypeName",R."PaymentDetails"
,R."CreatedBy",RT."Name" as "AreaType",R."ReceiptTypeId",
R."Cost" as "PaidAmount"
,Ad."AdmissionNo",ad."AdmissionDate",
pa."FullName" "PatientName",pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName"
from "Receipt" R
join "Admission" ad on Ad."AdmissionId"=R."RespectiveId" 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"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."Active" is not false and R."ReceiptAreaTypeId" in (12,13) and
--and Ad."LocationId"=2 and R."CreatedBy"=6776
case when "accountid" is null then 1=1 else R."CreatedBy" = "accountid" end
and case when "locationid" is null then 1=1 else Ad."LocationId" = "locationid" end
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end
and case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end
)
,lab as (
-- select
-- R."Cost" as "PaidAmount",PT."PayTypeName",R."PaymentDetails",
-- AR."FullName" "ReceiptCreatedBy",Rl."RoleName",R."CreatedBy",
-- nlbh."RequisitionNumber",
-- nlbh."PatientId", nlbh."DoctorId",
-- COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
-- R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
SELECT
R."Cost" as "PaidAmount",PT."PayTypeName",R."PaymentDetails",
AR."FullName" "ReceiptCreatedBy",Rl."RoleName",R."CreatedBy",
nlbh."RequisitionNumber",
nlbh."PatientId", nlbh."DoctorId",
COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
R."ReceiptId",RT."Name" as "AreaType" ,R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
from "Receipt" R
join "NewLabBookingHeader" nlbh on nlbh."NewLabBookingHeaderId"=R."RespectiveId"
join "PayType" pt ON PT."PayTypeId" = nlbh."PayTypeId"
left join "Patient" p ON p."PatientId" =nlbh."PatientId"
left join "Provider" prv on prv."ProviderId" = nlbh."DoctorId"
left join "Account" e on e."AccountId" = nlbh."EmployeeId"
left join "Account" AR on AR."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=AR."RoleId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId" = 8
--and nlbh."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else nlbh."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else nlbh."CreatedBy"="accountid" end
UNION
SELECT
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
AR."FullName" "ReceiptCreatedBy" ,Rl."RoleName",R."CreatedBy",
nlbh."RequisitionNumber",
nlbh."PatientId", nlbh."DoctorId",
COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
from "NewLabBookingHeader" nlbh
join "NewLabCancelBookingHeader" SH on SH."NewLabBookingHeaderId"=nlbh."NewLabBookingHeaderId"
join "Receipt" R on R."RespectiveId"= SH."NewLabCancelBookingHeaderId"
join "PayType" pt ON PT."PayTypeId" = nlbh."PayTypeId"
left join "Patient" p ON p."PatientId" =nlbh."PatientId"
left join "Account" AR on AR."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=AR."RoleId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId" = 9
--and nlbh."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else nlbh."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else nlbh."CreatedBy"="accountid" end
)
,pharma as (
select
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
PH."PharmacySaleHeaderId" ,PH."BillNumber",
A."FullName" "ReceiptCreatedBy",AR."RoleName" ,R."CreatedBy",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptTypeId"
from "Receipt" R
join "PharmacySaleHeader" PH on PH."PharmacySaleHeaderId"=R."RespectiveId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where R."ReceiptAreaTypeId"=1
--and PH."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
UNION
select
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
PH."PharmacySaleHeaderId" ,PH."BillNumber",
A."FullName" "ReceiptCreatedBy",AR."RoleName" ,R."CreatedBy",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptTypeId"
from "PharmacySaleHeader" PH
join "SaleReturnHeader" SH on SH."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "Receipt" R on R."RespectiveId"= SH."SaleReturnHeaderId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where R."ReceiptAreaTypeId"=7
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
)
,scan as(
select
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
PH."RequisitionNumber",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptTypeId",
PA."FullName" as "PatientName",PA."Mobile" ,PA."UMRNo",
R."CreatedBy",A."FullName" "ReceiptCreatedBy",AR."RoleName"
from "Receipt" R
join "BookScanAppointment" PH on PH."BookScanAppointmentId"=R."RespectiveId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" PA on PA."PatientId"=PH."PatientId"
where R."ReceiptAreaTypeId" in (10,11)
--PH."LocationId"=2 and R."CreatedDate"::date='2023-04-14'
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
)
SELECT O."AccountId",O."ReceiptCreatedBy",O."RoleName",O."ReceiptDate",O."ReceiptId",O."ReceiptTypeId",
O."AreaType",O."RefId",O."PayTypeName",O."PaymentDetails"
,O."PaidAmount",--O."RefundAmount",O."BalanceAmount",
O."PatientName",O."UMRNo",O."Mobile"
from
(
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."AppointmentNo" as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join appointment AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."AdmissionNo" as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join admission AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."PatientId"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join patient AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."RequisitionNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join lab AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."BillNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join pharma AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."RequisitionNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join scan AP on AP."CreatedBy"=A."AccountId"
)O
order by O."AccountId",O."ReceiptDate" desc;
end
$BODY$;
\ No newline at end of file
DROP FUNCTION IF EXISTS public."allModule_CancelReport"(date, date, integer, integer);
CREATE OR REPLACE FUNCTION public."allModule_CancelReport"(
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
accountid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer)
RETURNS TABLE("AccountId" integer, "ReceiptCreatedBy" text, "RoleName" character varying, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "AreaType" character varying, "RefId" character varying, "PayTypeName" character varying, "PaymentDetails" character varying, "RefundAmount" numeric, "PatientName" text, "UMRNo" character varying, "Mobile" character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" and lower(rol."RoleName") <> lower('Patient')
where a."RoleId"<>4 --and a."AccountId"=6776 and LAM."LocationId"=2
and case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationid IS NULL OR locationid=0) THEN 1=1 ELSE LAM."LocationId"=locationid END
)
, appointment as (
select R."ReceiptId",A."FullName" "ReceiptCreatedBy",Rl."RoleName",
R."CreatedDate" "ReceiptDate",R."CreatedBy",RT."Name" as "AreaType",R."ReceiptTypeId"
,Ad."AppointmentNo",Ad."LocationId",
pa."FullName" "PatientName",Pa."UMRNo",pa."Mobile",
pt."PayTypeName",R."PaymentDetails" ,coalesce(case when "ReceiptTypeId"=2 then R."Cost" end,0) as "RefundAmount"
from "Receipt" R
join "Appointment" Ad on Ad."AppointmentId"=R."RespectiveId"
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"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."Active" <> false and R."ReceiptAreaTypeId"=5 and
--R."CreatedBy" =6776 and Ad."LocationId" = 2;
--and R."CreatedDate"::date ='2023-04-14'
case when "accountid" is null then 1=1 else R."CreatedBy" = "accountid" end
and case when "locationid" is null then 1=1 else Ad."LocationId" = "locationid" end
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end
and case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end
)
,patient as(
select
R."Cost" as "RefundAmount", PT."PayTypeName",R."PaymentDetails",
A."FullName" as "ReceiptCreatedBy",Rl."RoleName",R."CreatedBy",
P."FullName" as "PatientName",P."UMRNo",P."Mobile",P."PatientId",
R."ReceiptId",RT."Name" as "AreaType",R."ReceiptTypeId",R."CreatedDate" "ReceiptDate"
FROM "Receipt" R
join "Patient" P on P."PatientId" = R."RespectiveId"
join "Account" PA on PA."ReferenceId"=P."PatientId"
JOIN "LocationAccountMap" LAM on LAM."AccountId"=PA."AccountId"
join "Account" A on A."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" PT on PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId"=6
-- and LAM."LocationId"=2 and R."CreatedDate"::date='2023-04-14 and R."CreatedBy"=6776
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else LAM."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end
)
,admission as (
select
R."ReceiptId",R."CreatedDate" "ReceiptDate",RT."Name" as "AreaType",
Rl."RoleName",R."CreatedBy",A."FullName" as "ReceiptCreatedBy",R."ReceiptTypeId"
,pt."PayTypeName",R."PaymentDetails",R."Cost" as "RefundAmount"
,Ad."AdmissionNo",
pa."FullName" "PatientName",pa."UMRNo",pa."Mobile"
from "Receipt" R
join "Admission" ad on Ad."AdmissionId"=R."RespectiveId" 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"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."Active" is not false and R."ReceiptAreaTypeId"=13 and
--and Ad."LocationId"=2 and R."CreatedBy"=6776
case when "accountid" is null then 1=1 else R."CreatedBy" = "accountid" end
and case when "locationid" is null then 1=1 else Ad."LocationId" = "locationid" end
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end
and case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end
)
,lab as (
SELECT
R."Cost" as "RefundAmount",PT."PayTypeName",R."PaymentDetails",
AR."FullName" as "ReceiptCreatedBy",Rl."RoleName",R."CreatedBy",
nlbh."NewLabBookingHeaderId", nlbh."RequisitionNumber",
COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
R."CreatedDate" "ReceiptDate", R."ReceiptId",RT."Name" as "AreaType",R."ReceiptTypeId"
from "NewLabBookingHeader" nlbh
join "NewLabCancelBookingHeader" SH on SH."NewLabBookingHeaderId"=nlbh."NewLabBookingHeaderId"
join "Receipt" R on R."RespectiveId"= SH."NewLabCancelBookingHeaderId"
join "PayType" pt ON PT."PayTypeId" = R."PayTypeId"
left join "Patient" p ON p."PatientId" =nlbh."PatientId"
left join "Account" AR on AR."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=AR."RoleId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId"=9
--and nlbh."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else nlbh."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else nlbh."CreatedBy"="accountid" end
)
,pharma as (
select
R."Cost" as "RefundAmount", PT."PayTypeName",R."PaymentDetails",
PH."PharmacySaleHeaderId" ,PH."BillNumber",
R."CreatedBy",A."FullName" "ReceiptCreatedBy" ,AR."RoleName"
,RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptId", R."ReceiptTypeId",
PH."PatientName",PH."Mobile" ,Pa."UMRNo"
from "PharmacySaleHeader" PH
join "SaleReturnHeader" SH on SH."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "Receipt" R on R."RespectiveId"= SH."SaleReturnHeaderId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where R."ReceiptAreaTypeId"=7
--and PH."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
)
,scan as(
select
R."Cost" as "RefundAmount",PT."PayTypeName",R."PaymentDetails",
PH."RequisitionNumber", PH."BookScanAppointmentId",
R."CreatedBy",R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",
A."FullName" "ReceiptCreatedBy",AR."RoleName" ,
PA."FullName" as "PatientName",PA."Mobile" ,PA."UMRNo"
from "Receipt" R
join "BookScanAppointment" PH on PH."BookScanAppointmentId"=R."RespectiveId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" PA on PA."PatientId"=PH."PatientId"
where R."ReceiptAreaTypeId" =11 and
--PH."LocationId"=2 and R."CreatedDate"::date='2023-04-14'
case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
)
SELECT O."AccountId",O."ReceiptCreatedBy",O."RoleName",O."ReceiptDate",O."ReceiptId",
O."AreaType",O."RefId",O."PayTypeName",O."PaymentDetails"
,O."RefundAmount",
O."PatientName",O."UMRNo",O."Mobile"
from
(
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",
AP."AreaType",AP."AppointmentNo" as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."RefundAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join appointment AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",
AP."AreaType",AP."AdmissionNo" as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."RefundAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join admission AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",
AP."AreaType",AP."PatientId"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."RefundAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join patient AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",
AP."AreaType",AP."RequisitionNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."RefundAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join lab AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",
AP."AreaType",AP."BillNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."RefundAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join pharma AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",
AP."AreaType",AP."RequisitionNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."RefundAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join scan AP on AP."CreatedBy"=A."AccountId"
)O
order by O."AreaType" asc,O."AccountId";
end
$BODY$;
\ No newline at end of file
DROP FUNCTION IF EXISTS public."collection_userLogin"(date, date, integer, integer);
CREATE OR REPLACE FUNCTION public."collection_userLogin"("fromDate" date DEFAULT NULL::date, "toDate" date DEFAULT NULL::date, accountid integer DEFAULT NULL::integer, locationid integer DEFAULT NULL::integer)
RETURNS TABLE("AccountId" integer, "ReceiptCreatedBy" text, "RoleName" character varying, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "ReceiptTypeId" integer, "AreaType" character varying, "RefId" character varying, "PayTypeName" character varying, "PaymentDetails" character varying, "PaidAmount" numeric, "PatientName" text, "UMRNo" character varying, "Mobile" character varying)
LANGUAGE plpgsql
AS $function$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" and lower(rol."RoleName") <> lower('Patient')
where a."RoleId"<>4 --and a."AccountId"=6776 and LAM."LocationId"=2
and case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationid IS NULL OR locationid=0) THEN 1=1 ELSE LAM."LocationId"=locationid END
)
, appointment as (
select R."ReceiptId",A."FullName" "ReceiptCreatedBy",Rl."RoleName",R."CreatedDate" "ReceiptDate",R."CreatedBy",RT."Name" as "AreaType"
, R."Cost" as "PaidAmount" ,R."ReceiptTypeId"
,Ad."FollowUpForAppointmentId",
Ad."AppointmentDate",Ad."AppointmentNo", Ad."AppointmentTime",Ad."LocationId",
pa."FullName" "PatientName",Pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName",Ad."PaymentType",
pt."PayTypeName",R."PaymentDetails" , R."AppointmentId",R."IsAppointmentReceipt"
from "Receipt" R
join "Appointment" Ad on Ad."AppointmentId"=R."RespectiveId"
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"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."Active" <> false and R."ReceiptAreaTypeId" in (4,5) and
--R."CreatedBy" =6776 and Ad."LocationId" = 2
--and R."CreatedDate"::date ='2023-04-18'
case when "accountid" is null then 1=1 else R."CreatedBy" = "accountid" end
and case when "locationid" is null then 1=1 else Ad."LocationId" = "locationid" end
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end
and case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end
)
,patient as(
select
R."Cost" as "PaidAmount",
A."FullName" as "ReceiptCreatedBy",Rl."RoleName",
P."FullName" as "PatientName",P."FirstName",P."MiddleName",P."LastName",
P."Age",P."Gender",P."UMRNo",P."Mobile",P."DateOfBirth",
R."ReceiptId",R."CreatedBy",RT."Name" as "AreaType",P."PatientId",
PT."PayTypeName",R."PaymentDetails",R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
FROM "Receipt" R
join "Patient" P on P."PatientId" = R."RespectiveId"
join "Account" PA on PA."ReferenceId"=P."PatientId"
JOIN "LocationAccountMap" LAM on LAM."AccountId"=PA."AccountId"
join "Account" A on A."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=A."RoleId"
join "PayType" PT on PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId" in (3,6)
-- and LAM."LocationId"=2 and R."CreatedDate"::date='2023-04-14 and R."CreatedBy"=6776
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else LAM."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end
)
,admission as (
select R."ReceiptId",Rl."RoleName",R."CreatedDate" "ReceiptDate",
A."FullName" "ReceiptCreatedBy" ,pt."PayTypeName",R."PaymentDetails"
,R."CreatedBy",RT."Name" as "AreaType",R."ReceiptTypeId",
R."Cost" as "PaidAmount"
,Ad."AdmissionNo",ad."AdmissionDate",
pa."FullName" "PatientName",pa."UMRNo",pa."Mobile",pr."FullName" as "ProviderName"
from "Receipt" R
join "Admission" ad on Ad."AdmissionId"=R."RespectiveId" 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"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."Active" is not false and R."ReceiptAreaTypeId" in (12,13) and
--and Ad."LocationId"=2 and R."CreatedBy"=6776
case when "accountid" is null then 1=1 else R."CreatedBy" = "accountid" end
and case when "locationid" is null then 1=1 else Ad."LocationId" = "locationid" end
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end
and case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end
)
,lab as (
-- select
-- R."Cost" as "PaidAmount",PT."PayTypeName",R."PaymentDetails",
-- AR."FullName" "ReceiptCreatedBy",Rl."RoleName",R."CreatedBy",
-- nlbh."RequisitionNumber",
-- nlbh."PatientId", nlbh."DoctorId",
-- COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
-- R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
SELECT
R."Cost" as "PaidAmount",PT."PayTypeName",R."PaymentDetails",
AR."FullName" "ReceiptCreatedBy",Rl."RoleName",R."CreatedBy",
nlbh."RequisitionNumber",
nlbh."PatientId", nlbh."DoctorId",
COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
R."ReceiptId",RT."Name" as "AreaType" ,R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
from "Receipt" R
join "NewLabBookingHeader" nlbh on nlbh."NewLabBookingHeaderId"=R."RespectiveId"
join "PayType" pt ON PT."PayTypeId" = nlbh."PayTypeId"
left join "Patient" p ON p."PatientId" =nlbh."PatientId"
left join "Provider" prv on prv."ProviderId" = nlbh."DoctorId"
left join "Account" e on e."AccountId" = nlbh."EmployeeId"
left join "Account" AR on AR."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=AR."RoleId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId" = 8
--and nlbh."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else nlbh."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else nlbh."CreatedBy"="accountid" end
UNION
SELECT
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
AR."FullName" "ReceiptCreatedBy" ,Rl."RoleName",R."CreatedBy",
nlbh."RequisitionNumber",
nlbh."PatientId", nlbh."DoctorId",
COALESCE (nlbh."PatientName" ,p."FullName" ) as "PatientName",COALESCE (p."Mobile" ,nlbh."Mobile" ) as "Mobile", p."UMRNo",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate" ,R."ReceiptTypeId"
from "NewLabBookingHeader" nlbh
join "NewLabCancelBookingHeader" SH on SH."NewLabBookingHeaderId"=nlbh."NewLabBookingHeaderId"
join "Receipt" R on R."RespectiveId"= SH."NewLabCancelBookingHeaderId"
join "PayType" pt ON PT."PayTypeId" = nlbh."PayTypeId"
left join "Patient" p ON p."PatientId" =nlbh."PatientId"
left join "Account" AR on AR."AccountId" = R."CreatedBy"
join "Role" Rl on Rl."RoleId"=AR."RoleId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
where R."ReceiptAreaTypeId" = 9
--and nlbh."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else nlbh."LocationId" = "locationid"::int end and
case when "accountid" is null then 1=1 else nlbh."CreatedBy"="accountid" end
)
,pharma as (
select
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
PH."PharmacySaleHeaderId" ,PH."BillNumber",
A."FullName" "ReceiptCreatedBy",AR."RoleName" ,R."CreatedBy",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptTypeId"
from "Receipt" R
join "PharmacySaleHeader" PH on PH."PharmacySaleHeaderId"=R."RespectiveId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where R."ReceiptAreaTypeId"=1
--and PH."LocationId"=2 and R."CreatedDate"::date='2023-04-18'
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
UNION
select
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
PH."PharmacySaleHeaderId" ,PH."BillNumber",
A."FullName" "ReceiptCreatedBy",AR."RoleName" ,R."CreatedBy",
PH."PatientName",PH."Mobile" ,Pa."UMRNo",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptTypeId"
from "PharmacySaleHeader" PH
join "SaleReturnHeader" SH on SH."PharmacySaleHeaderId"=PH."PharmacySaleHeaderId"
join "Receipt" R on R."RespectiveId"= SH."SaleReturnHeaderId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" Pa on Pa."PatientId"::text=PH."PatientId"::text
where R."ReceiptAreaTypeId"=7
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
)
,scan as(
select
R."Cost" as "PaidAmount", PT."PayTypeName",R."PaymentDetails",
PH."RequisitionNumber",
R."ReceiptId",RT."Name" as "AreaType",R."CreatedDate" "ReceiptDate",R."ReceiptTypeId",
PA."FullName" as "PatientName",PA."Mobile" ,PA."UMRNo",
R."CreatedBy",A."FullName" "ReceiptCreatedBy",AR."RoleName"
from "Receipt" R
join "BookScanAppointment" PH on PH."BookScanAppointmentId"=R."RespectiveId"
join "Account" A on A."AccountId"=R."CreatedBy"
join "Role" AR on AR."RoleId"=A."RoleId"
join "PayType" PT ON PT."PayTypeId" = R."PayTypeId"
join "ReceiptAreaType" RT on R."ReceiptAreaTypeId"=RT."ReceiptAreaTypeId"
left join "Patient" PA on PA."PatientId"=PH."PatientId"
where R."ReceiptAreaTypeId" in (10,11)
--PH."LocationId"=2 and R."CreatedDate"::date='2023-04-14'
and case when "accountid" is null then 1=1 else R."CreatedBy"="accountid" end and
case when "fromDate" is null then 1=1 else "fromDate"<= R."CreatedDate"::date end and
case when "toDate" is null then 1=1 else R."CreatedDate"::date<= "toDate" end and
case when "locationid" is null then 1=1 else PH."LocationId" = "locationid" end
)
SELECT O."AccountId",O."ReceiptCreatedBy",O."RoleName",O."ReceiptDate",O."ReceiptId",O."ReceiptTypeId",
O."AreaType",O."RefId",
coalesce(O."PayTypeName"::character varying,'GRAND')"PayTypeName"
,O."PaymentDetails"
,sum(O."PaidAmount")"PaidAmount",--O."RefundAmount",O."BalanceAmount",sum(A."PaidAmount") "PaidAmount"
O."PatientName",O."UMRNo",O."Mobile"
from
(
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."AppointmentNo" as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join appointment AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."AdmissionNo" as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join admission AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."PatientId"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join patient AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."RequisitionNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join lab AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."BillNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join pharma AP on AP."CreatedBy"=A."AccountId"
UNION
Select A."AccountId",AP."ReceiptCreatedBy",AP."RoleName",AP."ReceiptDate",AP."ReceiptId",AP."ReceiptTypeId",
AP."AreaType",AP."RequisitionNumber"::character varying as "RefId",AP."PayTypeName",AP."PaymentDetails"
,AP."PaidAmount",--AP."RefundAmount",AP."BalanceAmount",
AP."PatientName",AP."UMRNo",AP."Mobile"
from accountdata A
join scan AP on AP."CreatedBy"=A."AccountId"
)O
GROUP BY GROUPING SETS((O."AccountId",O."ReceiptCreatedBy",O."RoleName",O."ReceiptDate",
O."ReceiptId",O."ReceiptTypeId",O."AreaType",O."RefId",O."PayTypeName",
O."PaymentDetails",O."PatientName",O."UMRNo",O."Mobile"),(O."PayTypeName"), ())
order by O."PayTypeName" asc;
end
$function$
;
alter table "GynEncounter" add "GyneacPartner" text
alter table "GynEncounter" add "Procedure" text
\ No newline at end of file
delete from "DoctorSpecializationChargeModuleDetails" cascade;
---------------------------------------------------------------------------
delete from "DoctorSpecializationChargeModuleCategory" cascade;
---------------------------------------------------------------------------
delete from "DoctorSpecializationMap" cascade;
---------------------------------------------------------------------------
alter table "DoctorSpecializationMap"
add column "LocationId" int,
add CONSTRAINT "DoctorSpecializationMap_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."HealthCard_HealthCardId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."HealthCard_HealthCardId_seq"
OWNER TO postgres;
---------------------------------------------------------------------------------------------------------------------
-- Table: public.HealthCard
-- DROP TABLE IF EXISTS public."HealthCard";
CREATE TABLE IF NOT EXISTS public."HealthCard"
(
"HealthCardId" integer NOT NULL DEFAULT nextval('"HealthCard_HealthCardId_seq"'::regclass),
"HealthCardName" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Amount" bigint NOT NULL,
"AllowMembers" integer,
"ValidityType" character varying COLLATE pg_catalog."default",
"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 "HealthCard_pkey" PRIMARY KEY ("HealthCardId"),
CONSTRAINT "UQ_HealthCard_HealthCardName" UNIQUE ("HealthCardName"),
CONSTRAINT "FK_HealthCard_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_HealthCard_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."HealthCard"
OWNER to postgres;
------------------------------------------------------------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."HealthCardMember_HealthCardMemberId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."HealthCardMember_HealthCardMemberId_seq"
OWNER TO postgres;
----------------------------------------------------------------------------------------------------
-- SEQUENCE: public.IssueHealthCard_IssueHealthCardId_seq
-- DROP SEQUENCE IF EXISTS public."IssueHealthCard_IssueHealthCardId_seq";
CREATE SEQUENCE IF NOT EXISTS public."IssueHealthCard_IssueHealthCardId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."IssueHealthCard_IssueHealthCardId_seq"
OWNER TO postgres;
------------------------------------------------------------------------------------------
-- Table: public.HealthCardMember
-- DROP TABLE IF EXISTS public."HealthCardMember";
CREATE TABLE IF NOT EXISTS public."HealthCardMember"
(
"HealthCardMemberId" integer NOT NULL DEFAULT nextval('"HealthCardMember_HealthCardMemberId_seq"'::regclass),
"IssueHealthCardId" integer,
"DependentPatientId" integer,
CONSTRAINT "HealthCardMember_pkey" PRIMARY KEY ("HealthCardMemberId"),
CONSTRAINT "HealthCardMember_DependentPatientId_fkey" FOREIGN KEY ("DependentPatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "HealthCardMember_IssueHealthCardId_fkey" FOREIGN KEY ("IssueHealthCardId")
REFERENCES public."IssueHealthCard" ("IssueHealthCardId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."HealthCardMember"
OWNER to postgres;
------------------------------------------------------------------------------------------------------------
-- Table: public.IssueHealthCard
-- DROP TABLE IF EXISTS public."IssueHealthCard";
CREATE TABLE IF NOT EXISTS public."IssueHealthCard"
(
"IssueHealthCardId" integer NOT NULL DEFAULT nextval('"IssueHealthCard_IssueHealthCardId_seq"'::regclass),
"HealthCardId" integer NOT NULL,
"CardNumber" text COLLATE pg_catalog."default",
"PatientId" integer,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"IssuedDate" date NOT NULL,
"Active" boolean DEFAULT true,
"PayTypeId" integer,
"PaymentNumber" character varying(50) COLLATE pg_catalog."default",
"NetAmount" numeric(8,2),
"ValidTill" date,
CONSTRAINT "IssueHealthCard_pkey" PRIMARY KEY ("IssueHealthCardId"),
CONSTRAINT "IssueHealthCard_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "IssueHealthCard_HealthCardId_fkey" FOREIGN KEY ("HealthCardId")
REFERENCES public."HealthCard" ("HealthCardId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "IssueHealthCard_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "IssueHealthCard_PatientId_fkey" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "IssueHealthCard_PayTypeId_fkey" FOREIGN KEY ("PayTypeId")
REFERENCES public."PayType" ("PayTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."IssueHealthCard"
OWNER to postgres;
-------------------------------------------------------
INSERT INTO "LogType" ("LogTypeId","LogTypeName","Active")
VALUES (79,'HealthCard',TRUE);
\ No newline at end of file
CREATE TABLE IF NOT EXISTS public."Ambulance"
(
"AmbulanceId" serial,
"AmbulanceNo" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"AssignedNo" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"CreatedBy" integer NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"LocationId" integer,
CONSTRAINT "Ambulance_pkey" PRIMARY KEY ("AmbulanceId"),
CONSTRAINT "UQ_Ambulance_AmbulanceNo" UNIQUE ("AmbulanceNo"),
CONSTRAINT "UQ_Ambulance_AssignedNo" UNIQUE ("AssignedNo"),
CONSTRAINT "Ambulance_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."Ambulance"
OWNER to postgres;
------------------------------------------------------------------------------------------------------
-- Table: public.DriverDetail
-- DROP TABLE IF EXISTS public."DriverDetail";
CREATE TABLE IF NOT EXISTS public."DriverDetail"
(
"DriverDetailId" serial,
"DriverDetailName" character varying(255) COLLATE pg_catalog."default",
"MobileNo" character varying(10) COLLATE pg_catalog."default",
"AadharNo" character varying(12) COLLATE pg_catalog."default",
"Address" character varying(255) COLLATE pg_catalog."default",
"Active" boolean,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
"FromTime" character varying(10) COLLATE pg_catalog."default",
"ToTime" character varying(10) COLLATE pg_catalog."default",
CONSTRAINT "DriverDetail_pkey" PRIMARY KEY ("DriverDetailId"),
CONSTRAINT "DriverDetail_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "DriverDetail_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."DriverDetail"
OWNER to postgres;
--------------------------------------------------------------------------------------------------------
-- Table: public.AmbulanceReciept
-- DROP TABLE IF EXISTS public."AmbulanceReciept";
CREATE TABLE IF NOT EXISTS public."AmbulanceReciept"
(
"AmbulanceRecieptId" integer NOT NULL DEFAULT nextval('"AmbulanceReciept_AmbulanceRecieptId_seq"'::regclass),
"RecieptNo" text COLLATE pg_catalog."default",
"FromLocation" character varying(50) COLLATE pg_catalog."default",
"Address" character varying(255) COLLATE pg_catalog."default",
"ToLocation" character varying(50) COLLATE pg_catalog."default",
"PatientName" character varying(50) COLLATE pg_catalog."default",
"PatientMobile" character varying(10) COLLATE pg_catalog."default",
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"DriverDetailId" integer,
"AmbulanceId" integer,
"Amount" numeric(8,2),
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "AmbulanceReciept_pkey" PRIMARY KEY ("AmbulanceRecieptId"),
CONSTRAINT "AmbulanceReciept_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "AmbulanceReciept_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."AmbulanceReciept"
OWNER to postgres;
alter table "AmbulanceReciept" add column "LocationId" integer references "Location"("LocationId");
---------------------------------------------------------------------------------------------------------------
\ No newline at end of file
alter table "NewLabBookingDetail" add column "ReportUrl" text,add column "ExternalLab" bool default false;
alter table "NewLabBookingDetail" add column "UploadedBy" int references "Account"("AccountId"),
add column "UploadedDate" timestamp without time zone;
alter table "Ambulance" add column "LocationId" integer references "Location"("LocationId");
alter table "AmbulanceReciept" add column "LocationId" integer references "Location"("LocationId");
update "Ambulance" set "LocationId"=1;
update "AmbulanceReciept" set "LocationId"=1;
insert into "LogType"( "LogTypeId","LogTypeName",true) values (80,'DriverDetail',true)
,(81,'AmbulanceReciept',true);
\ No newline at end of file
UPDATE public."LogType"
SET "LogTypeName"='OTAppointment'
WHERE "LogTypeId"=71;
\ No newline at end of file
create sequence "DynamicReportImages_DynamicReportImagesId_seq";
CREATE TABLE "DynamicReportImages"
(
"DynamicReportImagesId" bigint NOT NULL DEFAULT nextval('"DynamicReportImages_DynamicReportImagesId_seq"'::regclass),
"ImagePath" text ,
"Guid" uuid,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
CONSTRAINT "DynamicReportImages_pkey" PRIMARY KEY ("DynamicReportImagesId"),
CONSTRAINT "FK_DynamicReportImages_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
INSERT INTO public."LogType"(
"LogTypeId", "LogTypeName", "Active")
VALUES (82, 'OTAvailability', true);
\ No newline at end of file
INSERT INTO public."LogType"(
"LogTypeId", "LogTypeName", "Active")
VALUES (78, 'OTRoom', true);
\ No newline at end of file
create table "VaccineMasterPharmacyLink"(
"VaccineMasterPharmacyLinkId" serial primary key,
"VaccineMasterId" int references "VaccineMaster"("VaccineMasterId"),
"PharmacyProductId" int references "PharmacyProduct"("PharmacyProductId"),
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone
);
alter table "LabTransferHeader"
add column "TransferredTemperature" int,
add column "ReceivedTemperature" int,
add column "TransferredTemperatureComments" text,
add column "ReceivedTemperatureComments" text;
\ No newline at end of file
update "Settings" set "Value"='{
"salutation":false,
"showSalutation":false,
"dateOfBirth":false,
"showDateOfBirth":false,
"email":false,
"showEmail":false,
"maritalStatus":false,
"showMaritalStatus":false,
"religion":false,
"showReligion":null,
"nationality":false,
"showNationality":null,
"city":false,
"showCity":null,
"state":false,
"showState":null,
"streetAddress":false,
"showStreetAddress":null,
"zipcode":false,
"showZipcode":null,
"hwcPatientId":false,
"showHwcPatientId":null,
"idProofId":false,
"showIdProofId":null,
"referredBy":false,
"showReferredBy":null,
"bloodGroup":false,
"showBloodGroup":null,
"relativeMobile":false,
"showRelativeMobile":false,
"relativeEducation":false,
"showRelativeEducation":null,
"relativeOccupation":false,
"showRelativeOccupation":false,
"dob":false,
"showDob":false,
"howDidYouKnowId":false,
"showHowDidYouKnowId":null,
"educationId":false,
"showEducationId":null,
"occupationId":false,
"showOccupationId":false,
"birthMark1":false,
"showBirthMark1":null,
"birthMark2":false,
"showBirthMark2":null,
"insuranceId":null,
"showInsuranceId":null,
"occupationDetail":null,
"showOccupationDetail":null,
"addressLine2":null,
"showAddressLine2":null,
"occupationDetails":null,
"showOccupationDetails":null
}' where "Name"='Patient Validation'
\ No newline at end of file
alter table "Patient"
add column "ReferredByNameId" integer;
\ No newline at end of file
create sequence "ICDValues_ICDValuesId_seq"
CREATE TABLE IF NOT EXISTS public."ICDValues"
(
"ICDValuesId" integer NOT NULL DEFAULT nextval('"ICDValues_ICDValuesId_seq"'::regclass),
"Code" character varying(255) COLLATE pg_catalog."default",
"Usable" text,
"ShortDesc" text
)
-- FUNCTION: public.udf_FetchDoctor_With_Availability_Specialization_Op(character varying, integer, integer, character varying)
-- DROP FUNCTION IF EXISTS public."udf_FetchDoctor_With_Availability_Specialization_Op"(character varying, integer, integer, character varying);
CREATE OR REPLACE FUNCTION public."udf_FetchDoctor_With_Availability_Specialization_Op"(
filter character varying DEFAULT NULL::text,
"locationId" integer DEFAULT NULL::integer,
"consultationTypeId" integer DEFAULT NULL::integer,
"appointmentDate" character varying DEFAULT NULL::text)
RETURNS TABLE("ProviderAvailabilityId" integer, "FullName" character varying, "DepartmentName" character varying, "DepartmentId" integer, "ProviderId" integer, "SpecializationId" integer, "SpecializationName" character varying, "LocationId" integer, "ConsultationTypeId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
SELECT DISTINCT on (pr2."ProviderId", s."SpecializationId") prl."ProviderAvailabilityId" ,pr2."FullName"
, d."DepartmentName" , d."DepartmentId"
,pr2."ProviderId"
, s. "SpecializationId", s."SpecializationName"
, CMT."LocationId", prl."ConsultationTypeId"
FROM "ProviderAvailability" prl
left Join "DoctorSpecializationMap" LSM on LSM."ProviderId" = prl."ProviderId" and LSM."SpecializationId" = prl."SpecializationId" and LSM."ConsultationTypeId" = prl."ConsultationTypeId"
left join "DoctorSpecializationChargeModuleDetails" DSCD on DSCD."ReferenceId" = LSM."DoctorSpecializationMapId"
left join "DoctorSpecializationChargeModuleCategory" DSCC on DSCC."DoctorSpecializationChargeModuleCategoryId" = DSCD."DoctorSpecializationChargeModuleCategoryId"
left join "ChargeModuleTemplate" CMT on CMT."ChargeModuleTemplateId" = DSCC."ChargeModuleTemplateId"
left JOIN "Provider" pr2 on pr2."ProviderId" = LSM."ProviderId" and pr2."Active" is true
left join "Account" pa on pa."ReferenceId" = pr2."ProviderId" and pa."Active" is true and pa."RoleId" = 3
left JOin "LocationAccountMap" LAM on LAM."AccountId" = pa."AccountId" and LAM."Active" IS TRUE
join "Specialization" s on s."SpecializationId" = ANY (pr2."Specializations")
JOIN "Location" pral on pral."LocationId" = CMT."LocationId" AND pral."Active" IS TRUE
JOIN "Practice" pra on pra."PracticeId" = pral."PracticeId" AND pra."Active" IS TRUE
JOIN "Department" d on d."DepartmentId" = pr2."DepartmentId"
where pr2."Active" is true and CMT."LocationId" = "locationId" and s."Active" = true and prl."Active" is true
--and CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date
and "IsInUse" is true
and case when "filter" is null then 1=1 else TRIM(UPPER(pr2."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(s."SpecializationName")) ilike'%'|| "filter"||'%' end
and case when "consultationTypeId" is null then 1=1 else prl."ConsultationTypeId" = "consultationTypeId" end
and case when "appointmentDate" is null then CMT."StartDate"::date <= current_date::date and CMT."EndDate"::date >= current_date::date else CMT."StartDate"::date <= "appointmentDate"::date and CMT."EndDate"::date >= "appointmentDate"::date end
--and case when "locationId" is null then 1=1 else LAM."LocationId" = "LocationId" end
--order by "FullName" asc
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchDoctor_With_Availability_Specialization_Op"(character varying, integer, integer, character varying)
OWNER TO postgres;
create sequence "AuthorityMaster_AuthorityMasterId_seq";
CREATE TABLE "AuthorityMaster"
(
"AuthorityMasterId" int NOT NULL DEFAULT nextval('"AuthorityMaster_AuthorityMasterId_seq"'::regclass),
"Authority" character varying(255),
"Active" boolean DEFAULT true,
"CreatedBy" int NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" int,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "AuthorityMaster_pkey" PRIMARY KEY ("AuthorityMasterId"),
CONSTRAINT "FK_AuthorityMaster_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_AuthorityMaster_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
----------------------------------------------------------------------------------------------------------------------
insert into "LogType" values(84, 'AuthorityMaster', true);
drop table if exists "PatientQueue" cascade;
\ No newline at end of file
create sequence "Reasons_ReasonsId_seq";
CREATE TABLE "Reasons"
(
"ReasonsId" int NOT NULL DEFAULT nextval('"Reasons_ReasonsId_seq"'::regclass),
"Reason" character varying(255),
"Active" boolean DEFAULT true,
"CreatedBy" int NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" int,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "Reasons_pkey" PRIMARY KEY ("ReasonsId"),
CONSTRAINT "FK_Reasons_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_Reasons_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
---------------------------------------------------------------------------------------------------------------------
insert into "LogType" values(83, 'Reasons', true)
alter table "WebNotification" add column "ModulesMasterId" int references "ModulesMaster"("ModulesMasterId");
update "WebNotification" set "ModulesMasterId" = (select "ModulesMasterId" from "ModulesMaster" mm where "ModuleName" = 'Pharmacy') where "WebNotificationTypeId" = 1;
update "WebNotification" set "ModulesMasterId" = (select "ModulesMasterId" from "ModulesMaster" mm where "ModuleName" = 'Lab') where "WebNotificationTypeId" = 2;
alter table "WebNotification" drop column "WebNotificationTypeId";
drop table "WebNotificationType" cascade;
ALTER SEQUENCE "ModulesMaster_ModulesMasterId_seq" RESTART WITH 10;
ALTER TABLE "GynEncounter"
ADD COLUMN "FamilyHistory" text ,
ADD COLUMN "ProblemList" text ,
ADD COLUMN "Surgeries" text ,
ADD COLUMN "BirthHistory" text ,
ADD COLUMN "Allergies" text
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."BillStatusType_Seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
CREATE TABLE IF NOT EXISTS public."BillStatusType"
(
"BillStatusTypeId" integer NOT NULL DEFAULT nextval('"BillStatusType_Seq"'::regclass),
"Name" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "BillStatusType_pkey" PRIMARY KEY ("BillStatusTypeId")
)
TABLESPACE pg_default;
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."MasterBill_Seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
CREATE TABLE IF NOT EXISTS public."MasterBill"
(
"MasterBillId" integer NOT NULL DEFAULT nextval('"MasterBill_Seq"'::regclass),
"PatientId" integer,
"ModulesMasterId" integer NOT NULL,
"Total" numeric(10,2) NOT NULL,
"BillDate" timestamp without time zone NOT NULL,
"BillNumber" character varying COLLATE pg_catalog."default",
"BillStatusTypeId" integer NOT NULL,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedDate" timestamp without time zone,
"ModifiedBy" integer,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "MasterBill_pkey" PRIMARY KEY ("MasterBillId"),
CONSTRAINT "FK_Receipt_BillStatusTypeId" FOREIGN KEY ("BillStatusTypeId")
REFERENCES public."BillStatusType" ("BillStatusTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_Receipt_ModulesMasterId" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_Receipt_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_Receipt_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
TABLESPACE pg_default;
CREATE SEQUENCE IF NOT EXISTS public."GatePass_GatePassId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
CREATE TABLE IF NOT EXISTS public."GatePass"
(
"GatePassId" integer NOT NULL DEFAULT nextval('"GatePass_GatePassId_seq"'::regclass),
"AdmissionId" integer NOT NULL,
"ValidUpto" timestamp(6) without time zone NOT NULL,
"Remark" text COLLATE pg_catalog."default",
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
CONSTRAINT "GatePass_pkey" PRIMARY KEY ("GatePassId"),
CONSTRAINT "FK_GatePass_AdmissionId" FOREIGN KEY ("AdmissionId")
REFERENCES public."Admission" ("AdmissionId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_GatePass_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_GatePass_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Appointment"
ADD COLUMN "OtherRemarks" character varying(250),
ADD COLUMN "AuthorityMasterId" integer,
ADD COLUMN "ReasonsId" integer,
ADD COLUMN "Remarks" character varying(250),
ADD CONSTRAINT "Appointment_AuthorityMasterId_fkey" FOREIGN KEY ("AuthorityMasterId")
REFERENCES public."AuthorityMaster" ("AuthorityMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
ADD CONSTRAINT "Appointment_ReasonsId_fkey" FOREIGN KEY ("ReasonsId")
REFERENCES public."Reasons" ("ReasonsId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
ALTER TABLE IF EXISTS public."Patient"
ADD COLUMN "InsuranceCompanyId" integer,
ADD CONSTRAINT "Patient_InsuranceCompanyId_fkey" FOREIGN KEY ("InsuranceCompanyId")
REFERENCES public."InsuranceCompany" ("InsuranceCompanyId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
ALTER TABLE "DoctorUnitMaster"
ALTER COLUMN "DoctorUnitMasterId" TYPE INT;
ALTER TABLE "TagDoctor"
ALTER COLUMN "DoctorUnitMasterId" TYPE INT;
alter table "Admission" Add Column "DoctorUnitMasterId" INT;
ALTER TABLE "Admission" ADD CONSTRAINT "Admission_DoctorUnitMasterId_fkey" FOREIGN KEY ("DoctorUnitMasterId") REFERENCES "DoctorUnitMaster" ("DoctorUnitMasterId");
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DROP FUNCTION IF EXISTS public."udf_fetch_Admission_Location"(text, integer, integer, boolean, text, date, date, date, text, boolean, integer, integer, integer);
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public."udf_fetch_Admission_Location"(
"admissionNo" text DEFAULT NULL::text,
"providerId" integer DEFAULT NULL::integer,
"patientId" integer DEFAULT NULL::integer,
"isDischarged" boolean DEFAULT NULL::boolean,
"patientMobileNo" text DEFAULT NULL::text,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"dischargeDate" date DEFAULT NULL::date,
"uMRNo" text DEFAULT NULL::text,
active boolean DEFAULT NULL::boolean,
locationid integer DEFAULT NULL::integer,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("AdmissionId" integer, "AdmissionNo" text, "IsConvertedFromOPtoIp" boolean, "AdmissionDate" timestamp without time zone, "AdmissionTime" time without time zone, "PatientName" text, "UMRNo" character varying, "PatientAge" smallint, "PatientGender" character, "patientMobile" character varying, "ProviderAge" smallint, "ProviderGender" character, "ProviderName" text, "DepartmentName" text, "WardName" character varying, "RoomName" character varying, "BedNumber" character varying, "AttendantName" character varying, "AttendantRelationWithPatient" character varying, "AttendantContactNo" character varying, "IsDischarged" boolean, "DischargeDate" date, "DischargeTime" time without time zone, "DischargeStatus" character varying, "IsMaternity" boolean, "EncounterId" integer, "SurgeryName" character varying, "ProviderThumbnailUrl" text, "PatientThumbnailUrl" text, "BedId" integer, "RoomId" integer, "WardId" integer, "DepartmentId" integer, "PatientId" integer, "ProviderId" integer, "SurgeryTypeId" integer, "PatientType" character, "AdmissionNotes" text, "PaidAmount" numeric, "FinalAmount" numeric, "PaymentStatus" text, "IsFinalBill" boolean, "TotalItems" bigint, "Active" boolean, "ExpectedDischargeDate" timestamp without time zone, "DischargedBy" integer, "DischargedByRole" text, "DischargedByName" text, "ChargeCategoryId" integer, "ChargeCategoryName" character varying, "CaseTypeId" integer, "AdmissionPayTypeId" integer, "ReferralDoctorId" integer, "InsuranceCompanyId" integer, "TpaId" integer, "PatientOrganization" character varying, "DoctorUnitMasterId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
With TotalItems as (
select count(distinct A."AdmissionId")::bigint "TotalItems"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
left join "Ward" W on w."WardId"=R."WardId"
join "ChargeCategory" cc on cc."ChargeCategoryId" = R."ChargeCategoryId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
where
case when "admissionNo" is null then 1=1
when "admissionNo"='' then 1=1
else A."AdmissionNo" ilike '%'||"admissionNo"||'%' end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END AND
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "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
)
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",R."ChargeCategoryId",cc."ChargeCategoryName",A."CaseTypeId",
A."AdmissionPayTypeId",A."ReferralDoctorId",A."InsuranceCompanyId",A."TpaId" ,A."PatientOrganization",A."DoctorUnitMasterId"
from "Admission" A
join "Patient" Pa on A."PatientId"=Pa."PatientId"
join "Provider" Pr on A."ProviderId"=Pr."ProviderId"
join "Department" D on D."DepartmentId"=A."DepartmentId"
left join "Bed" B on B."BedId"=A."BedId"
left join "Room" R on B."RoomId"=R."RoomId"
join "ChargeCategory" cc on cc."ChargeCategoryId" =R."ChargeCategoryId"
left join "Ward" W on w."WardId"=R."WardId"
---left join "PatientFamily" pf on pf."PatientFamilyId"=A."PatientFamilyId"
left join "SurgeryType" st on st."SurgeryTypeId"=A."SurgeryTypeId"
left join "Discharge" ds on ds."AdmissionId"=A."AdmissionId" and ds."Active"=true
left join "DischargeStatus" dss on ds."DischargeStatusId"=dss."DischargeStatusId"
left join "Receipt" Re on A."AdmissionId" = Re."AdmissionId" and Re."ReceiptTypeId"=1 and Re."Active"=true
---left join "Receipt" Rf on Rf."ReceiptTypeId"=2 and A."AdmissionId"= Rf ."AdmissionId" and Rf."Active"=true and Rf."IsRefunded" =true
left join "FinalBill" FB on A."AdmissionId"= FB."AdmissionId" and FB."Active"=true
left join "Account" AC on AC."AccountId"=A."DischargedBy"
left join "Role" RL on RL."RoleId"= AC."RoleId"
left join "Provider" PRO on PRO."ProviderId"=AC."ReferenceId"
left join "Department" DP on DP."DepartmentId"=PRO."DepartmentId"
where
case when "admissionNo" is null then 1=1
when "admissionNo"='' then 1=1
else A."AdmissionNo" ilike '%'||"admissionNo"||'%' end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END AND
case when "patientMobileNo" is null then 1=1
when "patientMobileNo"='' then 1=1
else pa."Mobile" ilike '%'||"patientMobileNo"||'%' end and
case when "patientId" is null then 1=1
else Pa."PatientId"= "patientId" end and
case when "active" is null then 1=1
else A."Active"= "active" end and
case when "providerId" is null then 1=1
else Pr."ProviderId" = "providerId" end and
case when "isDischarged" is null then 1=1
when "isDischarged" =true then ds."AdmissionId"=A."AdmissionId"
when "isDischarged" =false then ds."AdmissionId" is null
end AND
case when "fromDate" is null then 1=1 else "fromDate" <=A."AdmissionDate"::date and A."AdmissionDate"::date <="toDate" end
AND
case when "dischargeDate" is null then 1=1 else "dischargeDate" =ds."DischargeDate"::date end
and
case when "uMRNo" is null then 1=1
when "uMRNo"='' then 1=1
else Pa."UMRNo" ilike '%'||"uMRNo"||'%' end
group by A."AdmissionId",A."AdmissionNo",A."IsConvertedFromOPtoIp",A."AdmissionDate",A."AdmissionTime",
Pa."FullName",Pa."UMRNo",Pa."Age" ,Pa."Gender" ,Pr."Age" ,Pr."Gender" ,
Pr."FullName",D."DepartmentName" , w."WardName", R."RoomName", B."BedNumber"
,A."AttendantName",A."AttendantRelationWithPatient",A."AttendantContactNo" , ds."DischargeId"
,ds."DischargeDate",ds."DischargeTime",
dss."DischargeStatus",pa."Mobile"
,A."IsMaternity",A."EncounterId",st."SurgeryName",pr."ThumbnailUrl", pr."Guid",pr."ThumbnailUrl" ,pa."Guid", pa."ThumbnailUrl",
A."BedId",B."RoomId",w."WardId",D."DepartmentId",A."PatientId", A."ProviderId", A."SurgeryTypeId", A."PatientType",A."AdmissionNotes"
,FB."FinalAmount" ,FB."FinalBillId",
RL."RoleId",DP."DepartmentName",PRO."FullName",AC."FullName",R."ChargeCategoryId",cc."ChargeCategoryName"
order by A."AdmissionId" desc
limit "pageSize" offset ("pageSize"*"pageIndex");
END
$BODY$;
\ No newline at end of file
insert into "LabBookingStatus"("Status","Active")
values('Hold',true),('UnHold',true);
---------------------------------------------------------------
alter table "NewLabBookingDetail"
add column "HoldBy" int,
add column "UnHoldBy" int,
add column "HoldComments" text,
add column "UnHoldComments" text,
add CONSTRAINT "NewLabBookingDetail_HoldBy_fkey" FOREIGN KEY ("HoldBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
add CONSTRAINT "NewLabBookingDetail_UnHoldBy_fkey" FOREIGN KEY ("UnHoldBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
\ No newline at end of file
-- SEQUENCE: public.GYNCardGeneration_GYNCardGenerationId_seq
-- DROP SEQUENCE IF EXISTS public."GYNCardGeneration_GYNCardGenerationId_seq";
CREATE SEQUENCE IF NOT EXISTS public."GYNCardGeneration_GYNCardGenerationId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."GYNCardGeneration_GYNCardGenerationId_seq"
OWNER TO postgres;
-- Table: public.GYNCardGeneration
-- DROP TABLE IF EXISTS public."GYNCardGeneration";
CREATE TABLE IF NOT EXISTS public."GYNCardGeneration"
(
"GYNCardGenerationId" integer NOT NULL DEFAULT nextval('"GYNCardGeneration_GYNCardGenerationId_seq"'::regclass),
"Department" text COLLATE pg_catalog."default",
"GYNNo" character varying(255) COLLATE pg_catalog."default",
"HusbandName" character varying(255) COLLATE pg_catalog."default",
"HusbandAge" integer,
"Remarks" text COLLATE pg_catalog."default",
"RegistrationDate" text COLLATE pg_catalog."default",
"GYNNoExists" text COLLATE pg_catalog."default",
"Active" boolean DEFAULT true,
"ProviderId" integer NOT NULL,
"PatientId" integer NOT NULL,
CONSTRAINT "GYNCardGeneration_pkey" PRIMARY KEY ("GYNCardGenerationId"),
CONSTRAINT "FK_GYNCardGeneration_PatientId" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_GYNCardGeneration_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."GYNCardGeneration"
OWNER to postgres;
ALTER TABLE "OrderPrescriptionMaster"
ADD COLUMN "EncounterTypeId" integer
-----------------------------------------------------
UPDATE "OrderPrescriptionMaster"
SET "EncounterTypeId" = 3
WHERE "EncounterTypeId" is null;
----------------------------------------
INSERT INTO public."OrderPrescriptionMaster"(
"EncounterTypeId")
VALUES (3) where "EncounterTypeId"=null;
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate" ,"EncounterTypeId")
VALUES (11, 'Gynaec Complaints', true, 1029,'2022-07-27 17:26:41.188772', 2);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate" ,"EncounterTypeId")
VALUES
(
12, 'Prescription (Medication)', true, 1029,'2022-05-11 17:26:41.188772', 2
),
(
13, 'Investigation Template', true, 1029,'2022-05-11 17:26:41.188772', 2
),
(
14, 'Other Investigations', true, 1029,'2022-05-11 17:26:41.188772', 2
),
(
15, 'Procedures Templates', true, 1029,'2022-05-11 17:26:41.188772', 2
),
(
16, 'Gynaec Notes', true, 1029,'2022-05-11 17:26:41.188772', 2
),
(
17, 'Referrals', true, 1029,'2022-05-11 17:26:41.188772', 2
),
(
18, 'Important Advice', true, 1029,'2022-05-11 17:26:41.188772', 2
);
\ No newline at end of file
alter table "PatientFamily"
add column "BloodGroup" character varying(5);
\ No newline at end of file
Insert into "PaymentModule" values(7,'ViewMachine',true);
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."DietGuidLines_DietGuidLinesId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."DietGuidLines_DietGuidLinesId_seq"
OWNER TO postgres;
---------------------------------------------------------------------------------------
-- Table: public.DietGuidLines
-- DROP TABLE IF EXISTS public."DietGuidLines";
CREATE TABLE IF NOT EXISTS public."DietGuidLines"
(
"DietGuidLinesId" integer NOT NULL DEFAULT nextval('"DietGuidLines_DietGuidLinesId_seq"'::regclass),
"PdfLink" 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,
"DietGuidLinesName" text COLLATE pg_catalog."default",
"ContentType" text COLLATE pg_catalog."default",
"Size" double precision,
"DocumentUrl" text COLLATE pg_catalog."default",
CONSTRAINT "DietGuidLines_pkey" PRIMARY KEY ("DietGuidLinesId"),
CONSTRAINT "FK_DietGuidLines_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_DietGuidLines_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."DietGuidLines"
OWNER to postgres;
\ No newline at end of file
alter table "GynEncounter"
add column "OrderPrescription" text
------------------------------------------
alter table "GYNCardGeneration"
add column "OtherDetails" text
\ No newline at end of file
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (19, 'vvf', true, 1029, '21-05-2020', 1029, '21-05-2023', 4);
\ No newline at end of file
alter table "GynEncounter"
add column "OrderPrescription" text
------------------------------------------
alter table "GYNCardGeneration"
add column "OtherDetails" text
\ No newline at end of file
create table "PediatricChartAuthority"(
"PediatricChartAuthorityId" serial primary key,
"AuthorityName" text,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone,
"Active" bool default true
);
create table "PediatricChartType"(
"PediatricChartTypeId" serial primary key,
"TypeName" varchar(20),
"Active" bool default true
);
create table "PediatricAgeWiseData"(
"PediatricAgeWiseDataId" serial primary key,
"PediatricChartAuthorityId" int references "PediatricChartAuthority"("PediatricChartAuthorityId"),
"PediatricChartTypeId" int references "PediatricChartType"("PediatricChartTypeId"),
"Gender" varchar(10),
"AgeInMonth" int ,
"SD" int default null,
"P1" int,
"P3" int,
"P5" int,
"P15" int,
"P25" int,
"P50" int,
"P75" int,
"P85" int,
"P95" int,
"P97" int,
"P99" int,
"CreatedBy" int references "Account"("AccountId"),
"CreatedDate" timestamp without time zone,
"ModifiedBy" int references "Account"("AccountId"),
"ModifiedDate" timestamp without time zone,
"Active" bool default true
);
INSERT INTO public."PediatricChartType"
("TypeName", "Active")
VALUES('BMI', true),('Height', true),('Weight', true),('HeadCircumference', true);
UPDATE "AdmissionPayType" SET "AdmissionPayTypeName" = 'Insurance' WHERE "AdmissionPayTypeName" = 'Credit';
ALTER TABLE "PackageModule" ALTER COLUMN "PackageType" TYPE varchar(4);
-------------------------------------------------------------------------------------------------------------------------
delete from "ChargeModuleDetails" cascade;
---------------------------------------------------------------------------
delete from "ChargeModuleCategory" cascade;
\ No newline at end of file
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (20, 'ClinicalNotes', true, 1029, '23-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (21, 'Diagnosis', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (22, 'Investigations', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (23, 'OtherMedcine', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (24, 'Vaccine', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (25, 'FollowUp', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (26, 'RefferedForAdmission', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (27, 'RefferedToDoctor', true, 1029, '22-05-2023', null, null, 4);
INSERT INTO public."OrderPrescriptionMaster"(
"OrderPrescriptionMasterId", "Name", "Active", "CreatedBy", "CreatedDate", "ModifiedBy", "ModifiedDate", "EncounterTypeId")
VALUES (28, 'Advice', true, 1029, '22-05-2023', null, null, 4);
=======================================================================================================================================
select * from "PediatricEncounter"
alter table "PediatricEncounter"
add column "OrdersPrescription" text
\ No newline at end of file
-- Table: public.PediatricEncounter
-- DROP TABLE public."PediatricEncounter";
create sequence "PediatricEncounter_PediatricEncounterId_seq"
CREATE TABLE IF NOT EXISTS public."PediatricEncounter"
(
"PediatricEncounterId" bigint NOT NULL DEFAULT nextval('"PediatricEncounter_PediatricEncounterId_seq"'::regclass),
"AppointmentId" 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,
"AdmissionId" integer,
"PediatricEncounterDate" timestamp(6) without time zone NOT NULL,
"Measurements" text COLLATE pg_catalog."default",
"NeonatalRisk" text COLLATE pg_catalog."default",
"PediatricRisk" text COLLATE pg_catalog."default",
"Syndrome" text COLLATE pg_catalog."default",
CONSTRAINT "PediatricEncounter_pkey" PRIMARY KEY ("PediatricEncounterId")
)
TABLESPACE pg_default;
ALTER TABLE public."PediatricEncounter"
OWNER to postgres;
===================================================================
ALTER TYPE encountertype_elements ADD VALUE 'PediatricEncounter' AFTER 'IvfEncounter'
alter table "PharmacyProduct" add column "ScheduledDrug" varchar(10) default null;
alter table "PharmacyProduct" add column "IsGeneralItem" bool default false;
alter table "Supplier" add column "Pan" varchar(200);
\ No newline at end of file
ALTER TYPE encountertype_elements RENAME VALUE 'DietPlanEncounter' TO 'DietEncounter';
alter table "LabMainDetail"
add column "SampleUsage" character varying(30) COLLATE pg_catalog."default";
--------------------------------------------------------------------------------------------
alter table "NewLabBookingDetail"
add column "Comment" character varying(150) COLLATE pg_catalog."default";
\ No newline at end of file
drop table if exists "ProductGroupForTender" cascade;
drop table if exists "RequestSupplierHeader" cascade; -- RequestIndentDetail RequestSupplierDetail
drop table if exists "RequestSupplierDetail" cascade;
drop table if exists "PharmacyRequestIndentHeader" cascade;
drop table if exists "PharmacyRequestIndentDetail" cascade;
drop table if exists "PharmacyRequestIndentStatus" cascade;
drop table if exists "RequestIndentStatus" cascade ;
drop table if exists "RequestIndentType" cascade;
drop table if exists "RequestIndentHeader" cascade;
drop table if exists "PdfReader" cascade;
drop table if exists "RequestIndentDetail" cascade ;
drop table if exists "RequestIndentPayment" cascade;
drop table if exists "RaiseTenderHeader" cascade ;
drop table if exists "RaiseTenderDetail" cascade;
drop table if exists "ProductRaiseStatus" cascade;
\ No newline at end of file
ALTER TABLE "PediatricEncounter"
ADD "ClinicalExamination" text;
\ No newline at end of file
ALTER TABLE "PediatricEncounter"
ADD "DownSyndromeFollowUp" text;
\ No newline at end of file
Alter table "ScanTestMaster" add column "ScanSubClassificationId" integer;
___________________________________________________________________
Alter table "ScanTestMaster" ADD CONSTRAINT "FK_ScanTestMaster_ScanSubClassificationId" FOREIGN KEY ("ScanSubClassificationId")
REFERENCES "ScanSubClassification" ("ScanSubClassificationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
_____________________________________________________________________
\ No newline at end of file
ALTER TABLE "BookScanAppointment" ADD COLUMN "Comment" character varying;
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."DietPlan_DietPlanId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."DietPlan_DietPlanId_seq"
OWNER TO postgres;
-----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."DietPlan"
(
"DietPlanId" integer NOT NULL DEFAULT nextval('"DietPlan_DietPlanId_seq"'::regclass),
"AppointmentId" integer not NULL,
"PatientId" integer not NULL,
"DietGuidLinesId" integer not NULL,
"EncounterType" text,
"EncounterId" INTEGER,
"Status" BOOLEAN,
"CreatedBy" integer not NULL,
"CreatedDate" timestamp without time zone,
"ModifiedBy" INTEGER,
"ModifiedDate" timestamp without time zone,
"Active" boolean DEFAULT true,
CONSTRAINT "DietPlan_pkey" PRIMARY KEY ("DietPlanId"),
CONSTRAINT "FK_DietPlan_PatientId" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DietPlan_AppointmentId" FOREIGN KEY ("AppointmentId")
REFERENCES public."Appointment" ("AppointmentId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DietPlan_DietGuidLinesId" FOREIGN KEY ("DietGuidLinesId")
REFERENCES public."DietGuidLines" ("DietGuidLinesId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DietPlan_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DietPlan_ModifiedBy" 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."DietPlan"
OWNER to postgres;
------------------------------------------------------
CREATE SEQUENCE IF NOT EXISTS public."DietType_DietTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."DietType_DietTypeId_seq"
OWNER TO postgres;
-----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."DietType"
(
"DietTypeId" integer NOT NULL DEFAULT nextval('"DietType_DietTypeId_seq"'::regclass),
"Name" text
)
----------------------------------------------------------
INSERT INTO "DietType" ("DietTypeId","Name")
VALUES (1, 'Diet'),(2,'Pediatric');
------------------------------------------------
alter table "DietGuidLines" add column "DietTypeId" integer
\ No newline at end of file
alter table "NewLabBookingDetail"
add column "Emergency" boolean default false;
--------------------------------------------------
DELETE FROM "PackageModule";
DELETE FROM "AdmissionPackage";
INSERT INTO "Lookup" ("Name") VALUES ('Module Type');
INSERT INTO "Lookup" ("Name") VALUES ('Package Type');
SELECT "LookupId", "Name" FROM "Lookup" WHERE "Name" = 'Module Type';
INSERT INTO "LookupValue" ("LookupId", "Name", "CreatedDate") VALUES ((SELECT "LookupId" FROM "Lookup" WHERE "Name" = 'Module Type'), 'Cash', NOW());
INSERT INTO "LookupValue" ("LookupId", "Name", "CreatedDate") VALUES ((SELECT "LookupId" FROM "Lookup" WHERE "Name" = 'Module Type'), 'Insurance', NOW());
SELECT * FROM "LookupValue" WHERE "LookupId" = 25;
SELECT "LookupId", "Name" FROM "Lookup" WHERE "Name" = 'Package Type';
INSERT INTO "LookupValue" ("LookupId", "Name", "CreatedDate") VALUES ((SELECT "LookupId" FROM "Lookup" WHERE "Name" = 'Package Type'), 'OP', NOW());
INSERT INTO "LookupValue" ("LookupId", "Name", "CreatedDate") VALUES ((SELECT "LookupId" FROM "Lookup" WHERE "Name" = 'Package Type'), 'IP', NOW());
INSERT INTO "LookupValue" ("LookupId", "Name", "CreatedDate") VALUES ((SELECT "LookupId" FROM "Lookup" WHERE "Name" = 'Package Type'), 'OP & IP', NOW());
SELECT * FROM "LookupValue" WHERE "LookupId" = 26;
SELECT * FROM "PackageModule";
ALTER TABLE "PackageModule" DROP COLUMN "PackageType";
ALTER TABLE "PackageModule" DROP COLUMN "ModuleType";
ALTER TABLE "PackageModule" ADD COLUMN "PackageTypeId" INT NOT NULL
CONSTRAINT "FK_PackageModule_PackageTypeId" REFERENCES "LookupValue" ("LookupValueId") ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE "PackageModule" ADD COLUMN "ModuleTypeId" INT NOT NULL
CONSTRAINT "FK_PackageModule_ModuleTypeId" REFERENCES "LookupValue" ("LookupValueId") ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE "Admission" DROP CONSTRAINT "Admission_AdmissionPayTypeId_fkey";
ALTER TABLE "Admission" ADD CONSTRAINT "FK_Admission_AdmissionPayTypeId"
FOREIGN KEY ("AdmissionPayTypeId") REFERENCES "LookupValue" ("LookupValueId") ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE "AdmissionPackage" DROP CONSTRAINT "FK_AdmissionPackage_PackageId";
ALTER TABLE "AdmissionPackage" ADD CONSTRAINT "FK_AdmissionPackage_PackageId"
FOREIGN KEY ("PackageId") REFERENCES "PackageModule" ("PackageModuleId") ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE "Appointment" ADD "ANCCardGenerationId" INT;
----------------------------------------------------------------------------------
alter table "ObEncounter" add "PatientId" int
references "Patient"("PatientId")
\ No newline at end of file
alter table "ObEncounter" add "AnaesthesiaRecord" text;
Alter table "ObEncounter" add "PrepregnancyCounseling" text;
\ No newline at end of file
alter table "PediatricEncounter"
add column "PediatricGuide" text;
alter table "PediatricEncounter"
add column "HighRiskIntial" text;
\ No newline at end of file
ALTER TABLE IF EXISTS public."Cubicle" DROP COLUMN IF EXISTS "ProviderId";
--ALTER TABLE IF EXISTS public."Cubicle" DROP CONSTRAINT IF EXISTS "FK_Cubicle_ProviderId";
ALTER TABLE IF EXISTS public."Cubicle"
ADD COLUMN "AccountId" integer;
ALTER TABLE IF EXISTS public."Cubicle"
ADD CONSTRAINT "FK_Cubicle_AccountId" FOREIGN KEY ("AccountId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
ALTER TABLE IF EXISTS public."Cubicle"
ADD CONSTRAINT "FK_Cubicle_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
--UPDATE "Appointment" set "CubicleId" = null;
--DELETE FROM "Cubicle";
CREATE SEQUENCE "AccountProviderMap_seq";
CREATE TABLE IF NOT EXISTS public."AccountProviderMap"
(
"AccountProviderMapId" integer NOT NULL DEFAULT nextval('"AccountProviderMap_seq"'::regclass),
"AccountId" integer,
"ProviderId" integer,
CONSTRAINT "AccountProviderMap_pkey" PRIMARY KEY ("AccountProviderMapId"),
CONSTRAINT "FK_AccountProviderMap_AccountId" FOREIGN KEY ("AccountId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_AccountProviderMap_ProviderId" FOREIGN KEY ("ProviderId")
REFERENCES public."Provider" ("ProviderId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."AccountProviderMap"
OWNER to postgres;
--select * from "Cubicle"
\ No newline at end of file
alter table "ObEncounter"
add column "IsAppointmentClosed" boolean default false
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."BillStatusType_Seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
CREATE TABLE IF NOT EXISTS public."BillStatusType"
(
"BillStatusTypeId" integer NOT NULL DEFAULT nextval('"BillStatusType_Seq"'::regclass),
"Name" character varying(50) COLLATE pg_catalog."default" NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
CONSTRAINT "BillStatusType_pkey" PRIMARY KEY ("BillStatusTypeId")
)
TABLESPACE pg_default;
insert into "BillStatusType"("Name") values ('Generated') ;
insert into "BillStatusType"("Name") values ('Not Generated') ;
CREATE SEQUENCE IF NOT EXISTS public."MasterBill_Seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
-- Table: public.MasterBill
-- DROP TABLE IF EXISTS public."MasterBill";
CREATE TABLE IF NOT EXISTS public."MasterBill"
(
"MasterBillId" integer NOT NULL DEFAULT nextval('"MasterBill_Seq"'::regclass),
"ModuleId" integer,
"ModulesMasterId" integer NOT NULL,
"Total" numeric(10,2) NOT NULL,
"BillDate" timestamp without time zone NOT NULL,
"BillNumber" character varying COLLATE pg_catalog."default",
"BillStatusTypeId" integer NOT NULL,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedDate" timestamp without time zone,
"ModifiedBy" integer,
"Active" boolean NOT NULL DEFAULT true,
"PatientId" integer,
"NetTotal" numeric(10,2),
"Tax" numeric(10,2),
"Discount" numeric(10,2),
"Deposit" numeric(10,2),
"Refund" numeric(10,2),
"Rounding" numeric(10,2),
CONSTRAINT "MasterBill_pkey" PRIMARY KEY ("MasterBillId"),
CONSTRAINT "FK_MasterBill_PatientId" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_Receipt_BillStatusTypeId" FOREIGN KEY ("BillStatusTypeId")
REFERENCES public."BillStatusType" ("BillStatusTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_Receipt_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_Receipt_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT "FK_Receipt_ModulesMasterId" FOREIGN KEY ("ModulesMasterId")
REFERENCES public."ModulesMaster" ("ModulesMasterId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
)
TABLESPACE pg_default;
alter Table "Receipt"
add column "MasterBillId" integer null,
add CONSTRAINT "Fk_Receipt_MasterBillId" FOREIGN KEY ("MasterBillId")
REFERENCES public."MasterBill" ("MasterBillId");
ALTER TABLE "AppointmentTransaction"
ADD COLUMN "PatientId" integer null,
ADD CONSTRAINT "FK_AppointmentTransaction_PatientId" FOREIGN KEY ("PatientId")
REFERENCES public."Patient" ("PatientId");
\ No newline at end of file
-----------------Pharmacy-/ReceiptAreaTypeId"=1;------------
with T as(
select PSH."PharmacySaleHeaderId",PSH."PatientId"
from "PharmacySaleHeader" PSH
)
update "AppointmentTransaction" P set "PatientId" = T."PatientId"
from T
where P."AppointmentId" = T."PharmacySaleHeaderId" and P."ReceiptAreaTypeId"=1;
-----------------patient Registration-/ReceiptAreaTypeId"=3;------------
update "AppointmentTransaction" P set "PatientId" = P."AppointmentId"
where P."ReceiptAreaTypeId"=3;
-----------------Appointment-/ReceiptAreaTypeId"=4;------------
with T as(
select A."AppointmentId",A."PatientId"
from "Appointment" A
)
update "AppointmentTransaction" P set "PatientId" = T."PatientId"
from T
where P."ReceiptAreaTypeId"=4 and P."AppointmentId" = T."AppointmentId"
-------------Appointment Cancel-/ReceiptAreaTypeId"=5;------------
with T as(
select A."AppointmentId",A."PatientId"
from "Appointment" A
)
update "AppointmentTransaction" P set "PatientId" = T."PatientId"
from T
where P."ReceiptAreaTypeId"=5 and P."AppointmentId" = T."AppointmentId"
-----------------Cancelpatient Registration-/ReceiptAreaTypeId"=6;------------
update "AppointmentTransaction" P set "PatientId" = P."AppointmentId"
where P."ReceiptAreaTypeId"=6;
-----------------PharmacyReturn -/ReceiptAreaTypeId"=7;------------
with T as(
select PSH."SaleReturnHeaderId",PSH."PatientId"
from "SaleReturnHeader" PSH
)
update "AppointmentTransaction" P set "PatientId" = T."PatientId"
from T
where P."AppointmentId" = T."SaleReturnHeaderId" and P."ReceiptAreaTypeId"=7;
-------------------------labs-/ReceiptAreaTypeId"=8;--------------------------------------
alter table "ANCCardGeneration" add "ConsultantDoctor" TEXT
\ No newline at end of file
ALTER TABLE "GynEncounter"
ADD COLUMN "FamilyHistory" text ,
ADD COLUMN "ProblemList" text ,
ADD COLUMN "Surgeries" text ,
ADD COLUMN "BirthHistory" text ,
ADD COLUMN "Allergies" text ;
alter table "GYNCardGeneration" add column "ConsultantDoctor" text
\ No newline at end of file
update "Menu"
set "EncounterKey"='PediatricRisk'
where "Url" ilike '%app/pediatric-encounter/:id/:type/pediatric-risk%'
=========================================================================
update "Menu"
set "EncounterKey"='DownSyndromeFollowUp'
where "Url" ilike '%/app/pediatric-encounter/:id/:type/down-syndrome-followUp%'
==========================================================================
update "Menu"
set "EncounterKey"='Syndrome'
where "Url" ilike '%/app/pediatric-encounter/:id/:type/syndromes%'
=======================================================================
update "Menu"
set "EncounterKey"='ClinicalExamination'
where "Url" ilike '%app/pediatric-encounter/:id/:type/clinical-examination%'
====================================================================
update "Menu"
set "EncounterKey"='HighRiskIntial'
where "Url" ilike '%/app/pediatric-encounter/:id/:type/highriskinitial%'
===========================================================================
update "Menu"
set "EncounterKey"='OrdersPrescription'
where "Url" ilike '%/app/pediatric-encounter/:id/:type/order-prescription%'
========================================================================
update "Menu"
set "EncounterKey"='Measurements'
where "Url" ilike '%/app/pediatric-encounter/:id/:type/measurements%'
========================================================================
update "Menu"
set "EncounterKey"='NeoNatal'
where "Url" ilike '/app/pediatric-encounter/:id/:type/neonatal-risk%'
===========================================================================
\ No newline at end of file
-- FUNCTION: public.widget_GetSampleRecievedCount()
-- DROP FUNCTION public."widget_GetSampleRecievedCount"();
CREATE OR REPLACE FUNCTION public."widget_GetSampleRecievedCount"(
"fromDate" date DEFAULT NULL::date)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(*) from "LabBookingTimeLine" lbt
join "LabBookingStatus" lbs on lbs."LabBookingStatusId" = lbt."LabBookingStatusId" where lbs."Status" = 'SampleRecieved'
and lbt."CreatedDate" :: date ="fromDate";
end
$BODY$;
ALTER FUNCTION public."widget_GetSampleRecievedCount"(date)
OWNER TO postgres;
===================================================================================
-- DROP FUNCTION public."widget_GetVerifiedCount"();
CREATE OR REPLACE FUNCTION public."widget_GetVerifiedCount"(
"fromDate" date DEFAULT NULL::date)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select count(*) from "LabBookingTimeLine" lbt
join "LabBookingStatus" lbs on lbs."LabBookingStatusId" = lbt."LabBookingStatusId" where lbs."Status" = 'Verified'
and lbt."CreatedDate" :: date ="fromDate";
end
$BODY$;
ALTER FUNCTION public."widget_GetVerifiedCount"(date)
OWNER TO postgres;
===========================================================================================
-- DROP FUNCTION public."widget_GetTransferCount"();
CREATE OR REPLACE FUNCTION public."widget_GetTransferCount"(
"fromDate" date DEFAULT NULL::date)
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*) from "LabTransferHeader" LT
join "LabTransferDetail" LD on LD."LabTransferHeaderId"=LT."LabTransferHeaderId"
join "Account" A on A."AccountId" = LT."TransferedBy"
where LT."TransferedDate"::date="fromDate";
end
$BODY$;
ALTER FUNCTION public."widget_GetTransferCount"(date)
OWNER TO postgres;
============================================================================================================
-- FUNCTION: public.widget_GetCanceledCount()
-- DROP FUNCTION public."widget_GetCanceledCount"();
CREATE OR REPLACE FUNCTION public."widget_GetCanceledCount"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer )
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*)
from "NewLabBookingHeader" LH
join "NewLabBookingDetail" LD on LD."NewLabBookingHeaderId"=LH."NewLabBookingHeaderId"
join "Provider" pr on pr."ProviderId"= LH."DoctorId"
where LH."CreatedDate"::date="fromDate" and LD."LabBookingStatusId"=2 ;
end
$BODY$;
ALTER FUNCTION public."widget_GetCanceledCount"(date,integer,integer)
OWNER TO postgres;
==============================================================================================
-- FUNCTION: public.widget_GetSampleCount()
-- DROP FUNCTION public."widget_GetSampleCount"();
CREATE OR REPLACE FUNCTION public."widget_GetSampleCount"(
"fromDate" date DEFAULT NULL::date,
"referenceId" integer DEFAULT NULL::integer,
"locationId" integer DEFAULT NULL::integer )
RETURNS TABLE("Count" bigint)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
select COUNT(*) from "LabSampleCollection" LS
join "NewLabBookingDetail" LD on LD."NewLabBookingDetailId"=LS."NewLabBookingDetailId"
join "Account" A on A."AccountId"=LS."SampleCollectedBy"
where LS."CollectionDate"::date="fromDate"
and case when "locationId" is null then 1=1 else LS."LocationId"= "locationId" end;
end;
$BODY$;
ALTER FUNCTION public."widget_GetSampleCount"(date,int,int)
OWNER TO postgres;
\ No newline at end of file
d select COUNT(*) from "LabSampleCollection" LS
join "NewLabBookingDetail" LD on LD."NewLabBookingDetailId"=LS."NewLabBookingDetailId"
join "Account" A on A."AccountId"=LS."SampleCollectedBy"
where LS."CollectionDate"::date="fromDate"
and case when "locationId" is null then 1=1 else LS."LocationId"= "locationId" end for sample collection
============================================================================================
d select COUNT(*) from "LabTransferHeader" LT
join "LabTransferDetail" LD on LD."LabTransferHeaderId"=LT."LabTransferHeaderId"
join "Account" A on A."AccountId" = LT."TransferedBy"
where LT."TransferedDate"::date='2023-06-20':: date for transfer--done
================================================================================================
select COUNT(*) from "NewLabBookingHeader" LH
join "NewLabBookingDetail" LD on LD."NewLabBookingHeaderId"=LH."NewLabBookingHeaderId"
--join "Provider" pr on pr."ProviderId"= LH."DoctorId"
where LH."CreatedDate"::date='26-05-2023' and LH."Active" is true and LD."LabBookingStatusId"=2 for cancel
============================================================================================================
d select count(*) from "LabBookingTimeLine" lbt
join "LabBookingStatus" lbs on lbs."LabBookingStatusId" = lbt."LabBookingStatusId" where lbs."Status" = 'Verified'
and lbt."CreatedDate" :: date ='2023-04-24':: date for verifying reports-done
======================================================================================================================
d select count(*) from "LabBookingTimeLine" lbt
join "LabBookingStatus" lbs on lbs."LabBookingStatusId" = lbt."LabBookingStatusId" where lbs."Status" = 'SampleRecieved'
and lbt."CreatedDate" :: date ='2023-04-24':: date date for recieving -done
====================================================================================================================================
widget_GetSampleCount("fromDate" date, "referenceId" int4, "locationId" int4)
\ No newline at end of file
update "Menu"
set "EncounterKey"='highRiskIntial'
where "Url" ilike '/app/pediatric-encounter/:id/:type/highriskinitial%'
======================================================================
update "Menu"
set "EncounterKey"='clinicalExamination'
where "Url" ilike '/app/pediatric-encounter/:id/:type/clinical-examination'
===================================================================
update "Menu"
set "EncounterKey"='measurements'
where "Url" ilike '/app/pediatric-encounter/:id/:type/measurements'
====================================================================
update "Menu"
set "EncounterKey"='downSyndromeFollowUp'
where "Url" ilike '/app/pediatric-encounter/:id/:type/down-syndrome-followUp'
===========================================================================
update "Menu"
set "EncounterKey"='pediatricRisk'
where "Url" ilike '/app/pediatric-encounter/:id/:type/pediatric-risk'
==================================================================
update "Menu"
set "EncounterKey"='syndrome'
where "Url" ilike '/app/pediatric-encounter/:id/:type/syndromes'
==================================================================
update "Menu"
set "EncounterKey"='neonatalRisk'
where "Url" ilike '/app/pediatric-encounter/:id/:type/neonatal-risk'
===========================================================
update "Menu"
set "EncounterKey"='orderPrescription'
where "Url" ilike '/app/pediatric-encounter/:id/:type/order-prescription'
\ No newline at end of file
ALTER TABLE IF EXISTS public."AppointmentCheckPoints"
ADD COLUMN "IgnoreForQueue" boolean;
\ No newline at end of file
-- Table: public."PaymentResponseLog"
-- DROP TABLE public."PaymentResponseLog";
CREATE SEQUENCE "PaymentResponseLog_PaymentResponseLogId_seq";
CREATE TABLE public."PaymentResponseLog"
(
"PaymentResponseLogId" integer NOT NULL DEFAULT nextval('"PaymentResponseLog_PaymentResponseLogId_seq"'::regclass),
"JsonData" text COLLATE pg_catalog."default" NOT NULL,
"IsSuccess" boolean NOT NULL DEFAULT false,
"Exception" text COLLATE pg_catalog."default",
"CreatedDate" timestamp(6) with time zone NOT NULL,
CONSTRAINT "PaymentResponseLog_pkey" PRIMARY KEY ("PaymentResponseLogId")
)
TABLESPACE pg_default;
ALTER TABLE public."PaymentResponseLog"
OWNER to postgres;
\ No newline at end of file
ALTER TABLE "BookScanAppointment" ADD COLUMN "RequisitionNumber" text;
\ No newline at end of file
ALTER TABLE "OTRoom"
ADD COLUMN "SurgeryId" integer,
ADD CONSTRAINT "FK_OTRoom_Surgery_fkey" FOREIGN KEY ("SurgeryId")
REFERENCES public."Surgery" ("SurgeryId")
\ No newline at end of file
CREATE SEQUENCE IF NOT EXISTS public."AdmissionPayType_AdmissionPayTypeId_seq"
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;
ALTER SEQUENCE public."AdmissionPayType_AdmissionPayTypeId_seq"
OWNER TO postgres;
------------------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."AdmissionPayType"
(
"AdmissionPayTypeId" bigint NOT NULL DEFAULT nextval('"AdmissionPayType_AdmissionPayTypeId_seq"'::regclass) Primary key,
"AdmissionPayTypeName" character varying(255) COLLATE pg_catalog."default",
"Active" boolean DEFAULT true
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."AdmissionPayType"
OWNER to postgres;
-------------------------------------------------------------------------------
INSERT INTO public."AdmissionPayType"(
"AdmissionPayTypeName", "Active")
VALUES ('Cash', TRUE),('Credit',TRUE);
\ No newline at end of file
ALTER TABLE "BookScanAppointment" ADD COLUMN "AppointmentEndTime" timestamp(6) without time zone;
\ No newline at end of file
alter table "Receipt"
add column "IsSalucroAdmissionReceipt" boolean default false;
\ No newline at end of file
alter table "PharmacySaleHeader"
add column "IsSalucroBill" boolean default false;
--------------------------------------------------
alter table "NewLabBookingHeader"
add column "IsSalucroBill" boolean default false;
\ No newline at end of file
alter table "Appointment"
add column "IsSalucroAppointment" boolean default false;
--------------------------------------------------
alter table "BookScanAppointment"
add column "IsSalucroAppointment" boolean default false;
\ No newline at end of file
ALTER TABLE "AuditLog" ADD COLUMN IF NOT EXISTS "LocationId" int REFERENCES "Location"("LocationId");
\ No newline at end of file
alter table "AppointmentTransaction"
add column if not exists "VoucherNumber" character varying(15)
alter table "AppointmentTransaction"
add column if not exists "SendedVia" text;
alter table "AppointmentTransaction"
add column if not exists "ReceivedIn" text;
\ No newline at end of file
-- Table: public."AppointmentCheckPoints"
-- DROP TABLE public."AppointmentCheckPoints";
CREATE SEQUENCE "AppointmentCheckPoints_AppointmentCheckPointsId_seq";
CREATE TABLE public."AppointmentCheckPoints"
(
"AppointmentCheckPointsId" integer NOT NULL DEFAULT nextval('"AppointmentCheckPoints_AppointmentCheckPointsId_seq"'::regclass),
"AppointmentId" integer NOT NULL,
"Action" text COLLATE pg_catalog."default" NOT NULL,
"Date" timestamp(6) with time zone NOT NULL default now(),
"AccountId" integer not null,
"RoleId" integer not null,
CONSTRAINT "AppointmentCheckPoints_pkey" PRIMARY KEY ("AppointmentCheckPointsId"),
CONSTRAINT "AppointmentCheckPoints_AppointmentId_fkey" FOREIGN KEY ("AppointmentId")
REFERENCES public."Appointment" ("AppointmentId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "AppointmentCheckPoints_AccountId_fkey" FOREIGN KEY ("AccountId")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "AppointmentCheckPoints_RoleId_fkey" FOREIGN KEY ("RoleId")
REFERENCES public."Role" ("RoleId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE public."AppointmentCheckPoints"
OWNER to postgres;
\ No newline at end of file
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";
--------------------------------------------------------
\ No newline at end of file
ALTER TABLE "AppointmentCheckPoints"
RENAME COLUMN "AccountId"
TO "CreatedBy";
ALTER TABLE "AppointmentCheckPoints"
ALTER COLUMN "CreatedBy"
DROP NOT NULL;
ALTER TABLE "AppointmentCheckPoints"
DROP COLUMN "RoleId";
ALTER TABLE "AppointmentCheckPoints"
ADD COLUMN "ExternalUserId" integer;
DROP FUNCTION IF EXISTS public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, text, text, text, integer, date, date, integer, integer);
DROP FUNCTION IF EXISTS public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_uiReport_fetch_Appointments_Location"(
locationid integer DEFAULT NULL::integer,
"appointmentNo" text DEFAULT NULL::text,
"departmentId" integer[] DEFAULT NULL::integer[],
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"uMRNo" text DEFAULT NULL::text,
"patientReferredById" integer[] DEFAULT NULL::integer[],
"referredByName" text DEFAULT NULL::text,
mobile text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "FollowUpForAppointmentId" integer, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "Name" character varying, "ReferredByName" character varying, "PatientName" character varying, "PatientAge" smallint, "UMRNo" character varying, "Mobile" character varying, "PatientGender" character, "AppointmentTime" time without time zone, "VisitType" character, "PaymentType" character varying, "PaymentNumber" character varying, "TotalAppointments" bigint, "TotalAmount" bigint, "TotalAmountStr" text, "ReceiptCreatedByName" text, "
ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" text)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (select coalesce(A."DepartmentId"::text,'GrandTotal') "DepartmentId",
A."ProviderId"::text as "ProviderId",
A."AppointmentDate" ,
A."FollowUpForAppointmentId",
A."AppointmentNo",A."PatientId" "PatientId",PRB."Name",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
PT."PayTypeName" as "PaymentType",A."PaymentNumber",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::text as "TotalAmountStr" ,
sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
where A."Status"<>'C' and
case when "departmentId" is null then 1=1 else A."DepartmentId" = any("departmentId") end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END and
case when "patientId" is null then 1=1 else Pa."PatientId" = any("patientId") end and
case when "appointmentNo" is null then 1=1 when "appointmentNo" ='' then 1=1 else A."AppointmentNo" ilike'%'||"appointmentNo" ||'%' end and
case when "providerId" is null then 1=1 else A."ProviderId" = any("providerId") end and
case when "uMRNo" is null then 1=1 when "uMRNo" ='' then 1=1 else Pa."UMRNo" ilike'%'||"uMRNo" ||'%' end and
case when "patientReferredById" is null then 1=1 else Pa."PatientReferredById" = any("patientReferredById") end and
case when "referredByName" is null then 1=1 when "referredByName" ='' then 1=1 else Pa."ReferredByName" ilike'%'||"referredByName" ||'%' end and
case when "mobile" is null then 1=1 when "mobile" ='' then 1=1 else Pa."Mobile" ilike'%'||"mobile" ||'%' end and
case when "payTypeId" is null then 1=1 else A."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."FollowUpForAppointmentId",A."PatientId",PRB."Name"
,Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband"), (A."DepartmentId",A."ProviderId"), ())
order by A."DepartmentId",A."ProviderId",A."AppointmentDate")
select A."DepartmentId",coalesce(D."DepartmentName",'GrandTotal') "DepartmentName",
case when A."AppointmentNo" is null then 'Total' else A."ProviderId" end "ProviderId",
case when A."AppointmentNo" is null then 'Total' else Pr."FullName" end as "ProviderName",
A."FollowUpForAppointmentId",A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else PRB."Name"::varchar end as "Name",
case when A."AppointmentNo" is null then null else Pa."ReferredByName"::varchar end as "ReferredByName",
case when A."AppointmentNo" is null then null else Pa."FullName"::varchar end as "PatientName",
case when A."AppointmentNo" is null then null else Pa."Age" end "PatientAge",
case when A."AppointmentNo" is null then null else Pa."UMRNo" end "UMRNo",
case when A."AppointmentNo" is null then null else Pa."Mobile" end "Mobile",
case when A."AppointmentNo" is null then null else Pa."Gender" end "PatientGender",
A."AppointmentTime",
A."VisitType",A."PaymentType",A."PaymentNumber",A."TotalAppointments",A."TotalAmount",A."TotalAmountStr",
CA."FullName" "ReceiptCreatedByName", R."CreatedDate" "ReceiptDate",R."ReceiptId",
case when A."AppointmentNo" is null then null else Pa."StreetAddress" end "StreetAddress",
case when A."AppointmentNo" is null then null else Pa."City" end "City",
case when A."AppointmentNo" is null then null else Pa."State" end "State",
A."FatherOrHusband"
from cts A
left join "Department" D on A."DepartmentId"=D."DepartmentId"::text
left join "Provider" Pr on Pr."ProviderId"::text=A."ProviderId"
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left Join "Receipt" R on R."AppointmentId"=A."AppointmentId"
Left Join "Account" CA on CA."AccountId"=R."CreatedBy"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
order by A."DepartmentId",A."ProviderId",A."AppointmentDate"
;
END
$BODY$;
--ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location3"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer, integer)
-- OWNER TO postgres;
alter table "Bed"
add column "BedType" character varying(10);
\ No newline at end of file
ALTER TABLE "Patient"
ADD "BloodGroup" character varying(5) Null
\ No newline at end of file
drop table "CaseType"
create sequence "CaseType_CaseTypeId_seq"
CREATE TABLE IF NOT EXISTS public."CaseType"
(
"CaseTypeId" bigint NOT NULL DEFAULT nextval('"CaseType_CaseTypeId_seq"'::regclass),
"CaseTypeName" character varying(255),
"Code" character varying(255),
"Active" boolean DEFAULT true,
"CreatedBy" bigint NOT NULL references "Account" ("AccountId") ,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint references "Account" ("AccountId"),
"ModifiedDate" timestamp without time zone
);
insert into "LogType" ("LogTypeName","Active") values ('CaseType',true);
\ No newline at end of file
create sequence "DoctorUnitMaster_DoctorUnitMasterId_seq";
CREATE TABLE "DoctorUnitMaster"
(
"DoctorUnitMasterId" bigint NOT NULL DEFAULT nextval('"DoctorUnitMaster_DoctorUnitMasterId_seq"'::regclass),
"UnitName" character varying(255) not null ,
"Code" character varying(255) ,
"LocationId" bigint NOT NULL,
"Active" bool default false,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DoctorUnitMaster_pkey" PRIMARY KEY ("DoctorUnitMasterId"),
CONSTRAINT "FK_DoctorUnitMaster_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_DoctorUnitMaster_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_Location_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
-- ----------------------------
-- Table structure for DynamicReport
-- ----------------------------
DROP TABLE IF EXISTS "public"."DynamicReport";
CREATE TABLE "public"."DynamicReport" (
"DynamicReportId" int4 NOT NULL DEFAULT nextval('"DynamicReport_DynamicReportId_seq"'::regclass),
"Name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"Data" text COLLATE "pg_catalog"."default" NOT NULL,
"CreatedBy" int4 NOT NULL,
"CreatedDate" timestamptz(6) NOT NULL,
"ModifiedBy" int4,
"ModifiedDate" timestamptz(6),
"Active" bool NOT NULL DEFAULT true
)
;
-- ----------------------------
-- Primary Key structure for table DynamicReport
-- ----------------------------
ALTER TABLE "public"."DynamicReport" ADD CONSTRAINT "DynamicReport_pkey" PRIMARY KEY ("DynamicReportId");
-- ----------------------------
-- Foreign Keys structure for table DynamicReport
-- ----------------------------
ALTER TABLE "public"."DynamicReport" ADD CONSTRAINT "FK_DynamicReport_CreatedBy" FOREIGN KEY ("CreatedBy") REFERENCES "public"."Account" ("AccountId") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."DynamicReport" ADD CONSTRAINT "FK_DynamicReport_ModifiedBy" FOREIGN KEY ("ModifiedBy") REFERENCES "public"."Account" ("AccountId") ON DELETE CASCADE ON UPDATE NO ACTION;
create table "DynamicTemplate"(
"DynamicTemplateId" serial not null,
"TemplateName" CHARACTER varying,
"Value" text,
"Active" boolean DEFAULT true,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
"ModifiedBy" integer,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "DynamicTemplate_pkey" PRIMARY KEY ("DynamicTemplateId"),
CONSTRAINT "DynamicTemplate_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION,
CONSTRAINT "DynamicTemplate_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION);
insert into "LogType"("LogTypeId","LogTypeName","Active")VALUES(59,'DynamicTemplate',true)
\ No newline at end of file
CREATE TABLE IF NOT EXISTS public."EmployeeShift"
(
"EmployeeShiftId" bigserial NOT NULL,
"EmployeeShiftName" character varying(250) NOT NULL,
"StartTime" time without time zone NOT NULL,
"EndTime" time without time zone NOT NULL,
"Note" character varying(500),
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
"LocationId" integer NOT NULL,
CONSTRAINT "PK_EmployeeShift_EmployeeShiftId" PRIMARY KEY ("EmployeeShiftId"),
CONSTRAINT "FK_EmployeeShift_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "FK_EmployeeShift_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "FK_EmployeeShift_LocationId" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
);
\ No newline at end of file
-- FUNCTION: public.udf_uiReport_fetch_Appointments_Location(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, integer, integer)
-- DROP FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_uiReport_fetch_Appointments_Location"(
locationid integer DEFAULT NULL::integer,
"appointmentNo" text DEFAULT NULL::text,
"departmentId" integer[] DEFAULT NULL::integer[],
"providerId" integer[] DEFAULT NULL::integer[],
"patientId" integer[] DEFAULT NULL::integer[],
"uMRNo" text DEFAULT NULL::text,
"patientReferredById" integer[] DEFAULT NULL::integer[],
"referredByName" text DEFAULT NULL::text,
mobile text DEFAULT NULL::text,
"payTypeId" integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date,
"appointmentTypeId" integer[] DEFAULT NULL::integer[],
"paymentStatus" boolean DEFAULT NULL::boolean,
"pageIndex" integer DEFAULT 0,
"pageSize" integer DEFAULT 10)
RETURNS TABLE("DepartmentId" text, "DepartmentName" character varying, "ProviderId" text, "ProviderName" character varying, "AppointmentTypeName" character varying, "AppointmentDate" date, "AppointmentNo" character varying, "PatientId" integer, "Name" character varying, "ReferredByName" character varying, "PatientName" character varying, "PatientAge" smallint, "UMRNo" character varying, "Mobile" character varying, "PatientGender" character, "AppointmentTime" time without time zone, "VisitType" character, "PaymentType" character varying, "PaymentNumber" character varying, "TotalAppointments" bigint, "TotalAmount" bigint, "TotalAmountStr" text, "ReceiptCreatedByName" text, "ReceiptDate" timestamp without time zone, "ReceiptId" integer, "StreetAdress" character varying, "City" character varying, "State" character varying, "FatherOrHusband" text, "PaymentStatus" boolean, "EncounterType" encountertype_elements)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
with cts as (select coalesce(A."DepartmentId"::text,'GrandTotal') "DepartmentId",
A."ProviderId"::text as "ProviderId",
A."AppointmentDate",A."AppointmentTypeId",
ATN."Name" "AppointmentTypeName",
A."AppointmentNo",A."PatientId" "PatientId",PRB."Name",Pa."ReferredByName",
Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentTime",A."VisitType",
case when ATN."Name"='Follow Up' and sum(A."Total")=0 then 'Free Follow Up'
else PT."PayTypeName" end
as "PaymentType"
,A."PaymentNumber",
A."AppointmentId",
A."Status",COUNT(A."AppointmentNo") as "TotalAppointments" ,sum(A."Total")::text as "TotalAmountStr" ,
sum(A."Total")::bigint as "TotalAmount" ,
Pa."FatherOrHusband",
A."PaymentStatus",
A."EncounterType"
from "Appointment" A
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left join "PayType" PT on PT."PayTypeId"=A."PayTypeId"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on A."AppointmentTypeId"=ATN."AppointmentTypeId"
where A."Status"<>'C' and
case when "departmentId" is null then 1=1 else A."DepartmentId" = any("departmentId") end and
CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE A."LocationId"=locationId END and
case when "patientId" is null then 1=1 else Pa."PatientId" = any("patientId") end and
case when "appointmentNo" is null then 1=1 when "appointmentNo" ='' then 1=1 else A."AppointmentNo" ilike'%'||"appointmentNo" ||'%' end and
case when "providerId" is null then 1=1 else A."ProviderId" = any("providerId") end and
case when "uMRNo" is null then 1=1 when "uMRNo" ='' then 1=1 else Pa."UMRNo" ilike'%'||"uMRNo" ||'%' end and
case when "patientReferredById" is null then 1=1 else Pa."PatientReferredById" = any("patientReferredById") end and
case when "appointmentTypeId" is null then 1=1 else ATN."AppointmentTypeId" = any("appointmentTypeId") end and
case when "referredByName" is null then 1=1 when "referredByName" ='' then 1=1 else Pa."ReferredByName" ilike'%'||"referredByName" ||'%' end and
case when "mobile" is null then 1=1 when "mobile" ='' then 1=1 else Pa."Mobile" ilike'%'||"mobile" ||'%' end and
case when "payTypeId" is null then 1=1 else A."PayTypeId" ="payTypeId" end and
case when "fromDate" is null then 1=1 else "fromDate" <=A."AppointmentDate" and A."AppointmentDate" <="toDate" end and
case when "paymentStatus" is null then 1=1 else A."PaymentStatus" ="paymentStatus" end
GROUP BY GROUPING SETS((A."DepartmentId",A."ProviderId",A."PatientId",PRB."Name",
Pa."ReferredByName",Pa."FullName",Pa."UMRNo",Pa."Mobile",A."AppointmentDate",A."AppointmentTime",
A."AppointmentNo",A."AppointmentTypeId",
ATN."Name" ,
A."VisitType",
PT."PayTypeName",A."PaymentNumber",
A."AppointmentId",
A."Status",Pa."FatherOrHusband",A."PaymentStatus",A."EncounterType"), (A."DepartmentId",A."ProviderId"), ())
order by A."AppointmentId")
select A."DepartmentId",coalesce(D."DepartmentName",'GrandTotal') "DepartmentName",
case when A."AppointmentNo" is null then 'Total' else A."ProviderId" end "ProviderId",
case when A."AppointmentNo" is null then 'Total' else Pr."FullName" end as "ProviderName",
ATN."Name" "AppointmentTypeName",
A."AppointmentDate",
A."AppointmentNo",A."PatientId",
case when A."AppointmentNo" is null then null else PRB."Name"::varchar end as "Name",
case when A."AppointmentNo" is null then null else Pa."ReferredByName"::varchar end as "ReferredByName",
case when A."AppointmentNo" is null then null else Pa."FullName"::varchar end as "PatientName",
case when A."AppointmentNo" is null then null else Pa."Age" end "PatientAge",
case when A."AppointmentNo" is null then null else Pa."UMRNo" end "UMRNo",
case when A."AppointmentNo" is null then null else Pa."Mobile" end "Mobile",
case when A."AppointmentNo" is null then null else Pa."Gender" end "PatientGender",
A."AppointmentTime",
A."VisitType",A."PaymentType",A."PaymentNumber",A."TotalAppointments",A."TotalAmount",A."TotalAmountStr",
CA."FullName" "ReceiptCreatedByName", R."CreatedDate" "ReceiptDate",R."ReceiptId",
case when A."AppointmentNo" is null then null else Pa."StreetAddress" end "StreetAddress",
case when A."AppointmentNo" is null then null else Pa."City" end "City",
case when A."AppointmentNo" is null then null else Pa."State" end "State",
A."FatherOrHusband",
A."PaymentStatus",A."EncounterType"
from cts A
left join "Department" D on A."DepartmentId"=D."DepartmentId"::text
left join "Provider" Pr on Pr."ProviderId"::text=A."ProviderId"
left join "Patient" Pa on Pa."PatientId"::text=A."PatientId"::text
left Join "Receipt" R on R."AppointmentId"=A."AppointmentId"
Left Join "Account" CA on CA."AccountId"=R."CreatedBy"
left join "PatientReferredBy" PRB on PRB."PatientReferredById"::text=Pa."PatientReferredById"::text
left join "AppointmentType" ATN on ATN."AppointmentTypeId"=A."AppointmentTypeId"
order by A."AppointmentId"
;
END
$BODY$;
ALTER FUNCTION public."udf_uiReport_fetch_Appointments_Location"(integer, text, integer[], integer[], integer[], text, integer[], text, text, integer, date, date, integer[], boolean, integer, integer)
OWNER TO postgres;
-- Table: public.Encounter
-- DROP TABLE public."Encounter";
CREATE TABLE public."GynEncounter"
(
"GynEncounterId" bigserial NOT NULL ,
"AppointmentId" integer,
"EncounterDate" timestamp(6) without time zone NOT NULL,
"Abdomen" text COLLATE pg_catalog."default",
"AdditionalLabs" text COLLATE pg_catalog."default",
"BirthControl" text COLLATE pg_catalog."default",
"Breast" text COLLATE pg_catalog."default",
"BreastScreening" text COLLATE pg_catalog."default",
"CancerHistory" text COLLATE pg_catalog."default",
"Cardiovascular" text COLLATE pg_catalog."default",
"GynHistory" text COLLATE pg_catalog."default",
"GynLabs" text COLLATE pg_catalog."default",
"GynUltraSound" text COLLATE pg_catalog."default",
"Heent" text COLLATE pg_catalog."default",
"LastBreastUltraSound" text COLLATE pg_catalog."default",
"LastDexaScan" text COLLATE pg_catalog."default",
"LastMammogram" text COLLATE pg_catalog."default",
"LastPelvicUltraSound" text COLLATE pg_catalog."default",
"Lymphatic" text COLLATE pg_catalog."default",
"MenopausalHistory" text COLLATE pg_catalog."default",
"MensutralHistory" text COLLATE pg_catalog."default",
"MusculoSkeletal" text COLLATE pg_catalog."default",
"PatientDeferred" text COLLATE pg_catalog."default",
"Pelvic" text COLLATE pg_catalog."default",
"PhysicalExam" text COLLATE pg_catalog."default",
"Respiratory" text COLLATE pg_catalog."default",
"Skin" text COLLATE pg_catalog."default",
"Vitals" text COLLATE pg_catalog."default",
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"AdmissionId" integer,
CONSTRAINT "GynEncounter_pkey" PRIMARY KEY ("GynEncounterId"),
CONSTRAINT "UQ_GynEncounter" UNIQUE ("AppointmentId")
);
ALTER TYPE encountertype_elements ADD VALUE 'GynEncounter';
\ No newline at end of file
CREATE SEQUENCE public."PayCategory_PayCategoryId_seq";
CREATE TABLE IF NOT EXISTS public."PayCategory"
(
"PayCategoryId" integer NOT NULL DEFAULT nextval('"PayCategory_PayCategoryId_seq"'::regclass),
"PayCategoryName" 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 "PayCategory_pkey" PRIMARY KEY ("PayCategoryId"),
CONSTRAINT "UQ_PayCategory_PayCategoryName" UNIQUE ("PayCategoryName")
)
INSERT INTO "LogType"("LogTypeId","LogTypeName", "Active")
VALUES (60,'Masters', true);
\ No newline at end of file
INSERT INTO public."ModulesMaster"(
"ModulesMasterId", "ModuleName", "ModuleIcon", "ModuleDescription", "CreatedBy", "CreatedDate")
VALUES (3, 'OT','mdi mdi-cart-plus','This is for OT module' , 6776, '2023-02-22 16:45:22.221864') ;
\ No newline at end of file
DROP FUNCTION public."udf_InventoryPurchase_Report"(integer, text, text, integer, date, integer, timestamp without time zone, timestamp without time zone, boolean);
CREATE OR REPLACE FUNCTION public."udf_InventoryPurchase_Report"(
"supplierId" integer DEFAULT NULL::integer,
"purchaseBillNo" text DEFAULT NULL::text,
"billType" text DEFAULT NULL::text,
"wareHouseId" integer DEFAULT NULL::integer,
"dueDate" date DEFAULT NULL::date,
"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,
"pharmacyBillType" boolean DEFAULT NULL::boolean,
"locationId" integer DEFAULT NULL::integer)
RETURNS TABLE("BillDate" timestamp without time zone, "WareHouseName" text, "PurchaseBillNo" character varying, "SupplierName" text, "DueDate" date, "BillAmount" numeric, "Discount" numeric, "Taxes" numeric, "NetAmount" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
Select final."BillDate",final."WareHouseName",final."BillNumber" as "PurchaseBillNo",final."SupplierName",
final."DueDate",final."BillAmount",final."Discount",final."Taxes",final."NetAmount" from
(select PH."CreatedDate" "BillDate" ,IH."Name" as "WareHouseName",
PH."BillNumber",MP."Name" "SupplierName",PH."DueDate"::date as "DueDate",
PH."BillAmount" "BillAmount",PH."Discount" "Discount" ,PH."Taxes" "Taxes",PH."NetAmount" "NetAmount",
true "PharmacyBillType"
from "InventoryPurchaseHeader" PH
INNER JOIN "Supplier" MP on MP."SupplierId"=PH."SupplierId"
left join "InventoryWareHouse" IH on IH."InventoryWareHouseId"=PH."InventoryWareHouseId"
where case when "purchaseBillNo" is not null then PH."BillNumber" ilike '%'||"purchaseBillNo" ||'%' else 1=1 end
and case when "supplierId" is null then 1=1 else MP."SupplierId"="supplierId" end
and case when "billType" is null then 1=1 else PH."BillType" ilike '%' ||"billType"||'%' end
and case when "wareHouseId" is null then 1=1 else PH."InventoryWareHouseId"="wareHouseId" end
and case when "locationId" is null then 1=1 else PH."LocationId"="locationId" end
and case when "createdBy" is null then 1=1 else PH."CreatedBy"="createdBy" end
and case when "dueDate" is null then 1=1 else PH."DueDate"="dueDate" end and
case when "fromDate" is null then 1=1 else "fromDate" <=PH."CreatedDate" and PH."CreatedDate"<="toDate" end
group by PH."CreatedDate" ,PH."BillNumber",IH."Name",MP."Name", PH."BillAmount",PH."Discount",PH."Taxes", PH."NetAmount",PH."DueDate"::date
union
select srh."ReturnDate" "BillDate",''::text as "WareHouseName", srh."BillNumber",MP."Name" "SupplierName",null::date as "DueDate",srh."ReturnAmount" "BillAmount",
srh."Discount" "Discount" ,srh."Taxes" "Taxes", -srh."NetAmount" "TotalAmount",false "PharmacyBillType"
from "InventoryPurchaseReturnHeader" srh
--Join "InventoryPurchaseHeader" ph on ph."InventoryPurchaseHeaderId"= srh."InventoryPurchaseHeaderId"
inner JOIN "Supplier" MP on MP."SupplierId"=srh."SupplierId"
where case when "purchaseBillNo" is not null then srh."BillNumber" ilike '%'||"purchaseBillNo" ||'%' else 1=1 end
and case when "supplierId" is null then 1=1 else MP."SupplierId"="supplierId" end and
-- case when "billType" is null then 1=1 else srh."BillType" ilike '%' ||"billType"||'%' end
case when "fromDate" is null then 1=1 else "fromDate" <= srh."CreatedDate" and srh."CreatedDate"
<="toDate" end
group by srh."ReturnDate" ,srh."BillNumber",MP."Name", srh."ReturnAmount",srh."Discount"
,srh."Taxes" ,srh."NetAmount" ) final
where case when "pharmacyBillType" is null then 1=1
when "pharmacyBillType" = true then "PharmacyBillType" = true
when "pharmacyBillType" = false then "PharmacyBillType" = false
end and final."WareHouseName"!=''
order by final."BillDate" desc;
END
$BODY$;
alter table "ModulesMaster"
add column "IsDoctorChargeCategoryApplicable" boolean DEFAULT false;
\ No newline at end of file
------------------------------------
---------------------------------
-----inside package labs - For Received------
-----------------------------
ALTER TABLE "LabBookingPackageDetail"
ADD "CollectedSampleReceivedBy" integer Null;
ALTER TABLE "LabBookingPackageDetail"
ADD CONSTRAINT "FK_LabBookingPackageDetail_CollectedSampleReceivedBy" FOREIGN KEY ("CollectedSampleReceivedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
------------------
ALTER TABLE "LabBookingPackageDetail"
ADD "SampleReceivedDate" timestamp without time zone;
\ No newline at end of file
alter table "LabBookingDetail"
add column if not exists "Barcode" text
-------------------
alter table "LabBookingPackageDetail"
add column if not exists "Barcode" text
ALTER TABLE "LabBookingDetail"
ADD "CollectedSampleReceivedBy" integer Null;
ALTER TABLE "LabBookingDetail"
ADD CONSTRAINT "FK_LabBookingDetail_CollectedSampleReceivedBy" FOREIGN KEY ("CollectedSampleReceivedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
------------------
ALTER TABLE "LabBookingDetail"
ADD "SampleReceivedDate" timestamp without time zone;
------------------------------------
---------------------------------
-----inside package labs -------
ALTER TABLE "LabBookingPackageDetail"
ADD "SampleCollectedBy" integer Null;
ALTER TABLE "LabBookingPackageDetail"
ADD CONSTRAINT "FK_LabBookingPackageDetail_SampleCollectedBy" FOREIGN KEY ("SampleCollectedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
\ No newline at end of file
alter table "BookScanAppointment" add column "Amount" numeric;
alter table "BookScanAppointment" add column "ChargeCategoryId" integer;
alter table "BookScanAppointment" add CONSTRAINT "BookScanAppointment_ChargeCategoryId_fkey" FOREIGN KEY ("ChargeCategoryId")
REFERENCES public."ChargeCategory" ("ChargeCategoryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
INSERT INTO public."PaymentModule"(
"PaymentModuleId", "Name", "Active")
VALUES (5, 'ScanAppointment', true);
\ No newline at end of file
alter table "ProviderAvailability" add
CONSTRAINT "ProviderAvailability_ConsultationTypeId_fkey" FOREIGN KEY ("ConsultationTypeId")
REFERENCES public."ConsultationType" ("ConsultationTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
-------
alter table "ProviderAvailability" add
CONSTRAINT "ProviderAvailability_SpecializationId_fkey" FOREIGN KEY ("SpecializationId")
REFERENCES public."Specialization" ("SpecializationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
\ No newline at end of file
alter table "Admission" add column "ReferralDoctorId" int references "ReferralDoctor"("ReferralDoctorId");
\ No newline at end of file
alter table "ObEncounter"
Add if not exists "Complaints" text;
alter table "ObEncounter"
Add if not exists "ObstetricExamination" text;
ALTER TABLE public."ObEncounter" ADD COLUMN if not exists "ANCCardGeneration" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter" ADD COLUMN if not exists "VaginalExamination" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter" ADD COLUMN if not exists "BreastExamination" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter" ADD COLUMN if not exists "PlanOfManagement" text COLLATE pg_catalog."default";
alter table "ProviderAvailability" add column "NoOfNewPatient" integer
\ No newline at end of file
alter table "Appointment" add column "ProviderAvailabilityChargeTypeId" integer;
alter table "Appointment" Add CONSTRAINT "FK_Appointment_ProviderAvailabilityChargeTypeId" FOREIGN KEY ("ProviderAvailabilityChargeTypeId")
REFERENCES public."ProviderAvailabilityChargeType" ("ProviderAvailabilityChargeTypeId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;
\ No newline at end of file
ALTER TABLE "ProviderAvailability"
ADD COLUMN "NewPatientSlots" integer,
ADD COLUMN "OfflineSlots" integer,
ADD COLUMN "GeneralSlots" integer,
ADD COLUMN "TotalSlots" integer,
ADD COLUMN "SpecializationDuration" integer;
\ No newline at end of file
alter table "OTRoom"
drop column "ChargeCategoryId"
\ No newline at end of file
ALTER TABLE "ObEncounter" ADD COLUMN "GeneticScreening" text ;
ALTER TABLE "ObEncounter" ADD COLUMN "InfectionHistory" text ;
\ No newline at end of file
ALTER TABLE "Department"
ADD if not exists "DeptType" character varying(255);
UPDATE "Department"
SET "DeptType"='Provider'
WHERE "DepartmentId" in (44, 42, 54, 50, 51, 49,47,66,43,52,35,65,45,6,62,48);
UPDATE "Department"
SET "DeptType"='other'
WHERE "DepartmentId" in (68, 67,63,59,61,58,57,46);
\ No newline at end of file
--delete from "OTRoom"
ALTER TABLE "OTRoom"
ADD COLUMN "ChargeCategoryId" integer,
ADD CONSTRAINT "FK_OTRoom_ChargeCategory_fkey" FOREIGN KEY ("ChargeCategoryId")
REFERENCES public."ChargeCategory" ("ChargeCategoryId")
alter table "Surgery"
add column "LocationId" integer,
add constraint "FK_Surgery_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId")
\ No newline at end of file
alter table "Admission" add column "CaseTypeId" integer REFERENCES "CaseType"("CaseTypeId");
alter table "Admission" add column "InsuranceCompanyId" integer REFERENCES "InsuranceCompany"("InsuranceCompanyId");
alter table "Admission" add column "AdmissionPayTypeId" integer REFERENCES "AdmissionPayType"("AdmissionPayTypeId");
\ No newline at end of file
ALTER TABLE public."ObEncounter"
ADD COLUMN "VTERisk" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "ProcedureForm" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "SGAScanning" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "Surgeries" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "MenstrualHistory" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "OtherDetail" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "BirthHistory" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "DrugHistory" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "OrderPrescription" text COLLATE pg_catalog."default";
ALTER TABLE public."ObEncounter"
ADD COLUMN "AntinantalRisk" text COLLATE pg_catalog."default";
\ No newline at end of file
alter table "Patient" add column "IsNewPatient" boolean;
alter table "Patient" add column "IdProofValue" character varying;
alter table "Patient" add column "IdProofId" int references "IdProof"("IdProofId");
\ No newline at end of file
Alter table "Patient" add "AppointmentId" int;
\ No newline at end of file
ALTER TABLE "ScanMachineAvailability" ADD COLUMN "ToDate" timestamp(6) without time zone;
ALTER TABLE "ScanMachineAvailability" ADD COLUMN "FromDate" timestamp(6) without time zone;
ALTER TABLE "IdProof" DROP COLUMN "Description";
ALter table "PatientReferredBy" drop column "LocationId";
ALter table "IdProof" drop column "LocationId";
\ No newline at end of file
ALTER TABLE "PracticeLocation"
ADD COLUMN "CityId" integer,
ADD CONSTRAINT "FK_PracticeLocation_CityId_fkey" FOREIGN KEY ("CityId")
REFERENCES public."City" ("CityId")
ALTER TABLE "PracticeLocation"
ADD COLUMN "StateId" integer,
ADD CONSTRAINT "FK_PracticeLocation_StateId_fkey" FOREIGN KEY ("StateId")
REFERENCES public."State" ("StateId")
"FirebaseDatabase": "https://careaxes-24ee0-default-rtdb.asia-southeast1.firebasedatabase.app/",
"FirebaseAuthKey": "XdOwEENPainIlnQMsgUam7Zksphgi8O2SsjBh7ZN"
add these 2 keys under "ApplicationConfiguration"
\ No newline at end of file
alter table "AppointmentLog"
add column "PatientRegistrationCharges" numeric(10,2);
alter table "AppointmentTransaction"
add column "StatusCheckInProgress" boolean default false;
\ No newline at end of file
alter table "Patient" add column "BloodGroup" character varying(5)
\ No newline at end of file
-- FUNCTION: public.UDF_TEST1(integer, integer, integer, text, integer, integer)
-- DROP FUNCTION IF EXISTS public."UDF_TEST1"(integer, integer, integer, text, integer, integer);
CREATE OR REPLACE FUNCTION public."UDF_TEST1"(
providerid integer,
specializationid integer,
locationid integer,
appointmentdate text,
chargetypesid integer,
consultationtypeid integer)
RETURNS TABLE("ProviderAvailabilityChargeTypeId" integer, "ChargeTypesId" integer, "ChargeName" character varying, "Charge" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
IF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."SpecializationId" = specializationid and PA."LocationId" = locationid
AND PA."StartDate"::DATE <= appointmentdate::DATE and PA."EndDate"::DATE >= appointmentdate::DATE
AND PA."ChargeTypesId" = chargetypesid And PA."ConsultationTypeId" = consultationtypeid
--END IF; 1
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."SpecializationId" = specializationId and PA."LocationId" = locationId
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."SpecializationId" = specializationId and PA."LocationId" = locationId and PA."ProviderId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."SpecializationId" = specializationId and PA."LocationId" = locationId and PA."ProviderId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
--END IF; 2
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName",PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."LocationId" = locationId and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."ProviderId" = providerid and PA."LocationId" = locationId and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
--END IF; 3
ELSEIF EXISTS (select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName",PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."LocationId" = locationId and PA."ProviderId" is null and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId
) THEN return query select PA."ProviderAvailabilityChargeTypeId", PA."ChargeTypesId", CT."ChargeName", PA."Charge"
FROM "ProviderAvailabilityChargeType" PA
JOIN "ChargeTypes" CT ON CT."ChargeTypesId" = PA."ChargeTypesId"
where PA."LocationId" = locationId and PA."ProviderId" is null and PA."SpecializationId" is null
AND PA."StartDate"::DATE <= appointmentDate::DATE and PA."EndDate"::DATE >= appointmentDate::DATE
AND PA."ChargeTypesId" = chargeTypesId And PA."ConsultationTypeId" = consultationTypeId;
END IF; -- 1
end
$BODY$;
ALTER FUNCTION public."UDF_TEST1"(integer, integer, integer, text, integer, integer)
OWNER TO postgres;
CREATE SEQUENCE public."RoomCharge_RoomChargeId_seq";
----------
CREATE TABLE IF NOT EXISTS public."RoomCharge"
(
"RoomChargeId" integer NOT NULL DEFAULT nextval('"RoomCharge_RoomChargeId_seq"'::regclass),
"LocationId" integer,
"ChargeCategoryId" integer,
"Cost" numeric(10,2) NOT NULL,
"CreatedBy" integer,
"CreatedDate" timestamp without time zone,
CONSTRAINT "RoomCharge_pkey" PRIMARY KEY ("RoomChargeId"),
CONSTRAINT "RoomChargeId_CreatedBy_fkey" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "RoomCharge_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION ,
CONSTRAINT "RoomCharge_ChargeCategoryId_fkey" FOREIGN KEY ("ChargeCategoryId")
REFERENCES public."ChargeCategory" ("ChargeCategoryId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
------------------------
ALTER TABLE "Room"
ADD COLUMN "ChargeCategoryId" integer
ALTER TABLE "Room"
ADD CONSTRAINT "FK_Room_ChargeCategoryId" FOREIGN KEY ("ChargeCategoryId")
REFERENCES public."ChargeCategory" ("ChargeCategoryId")
------------------------------------------
ALTER TABLE "ChargeCategory"
Drop COLUMN "LocationId"
\ No newline at end of file
ALTER TABLE "ChargeCategory"
ADD COLUMN "Default" BOOLEAN NOT NULL DEFAULT FALSE;
\ No newline at end of file
ALTER TABLE "Cubicle" ADD COLUMN "LocationId" integer;
\ No newline at end of file
-- FUNCTION: public.udf_fetchProviderAvailabilityDatesNew(integer, integer, integer, text, text)
-- DROP FUNCTION IF EXISTS public."udf_fetchProviderAvailabilityDatesNew"(integer, integer, integer, text, text);
CREATE OR REPLACE FUNCTION public."udf_fetchProviderAvailabilityDatesNew"(
providerid integer,
locationid integer,
specializationid integer,
startdate text,
enddate text)
RETURNS TABLE("Date" date, "DateNumber" integer, "DayName" character varying, "Status" character)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with TotalDates as (
SELECT DISTINCT generate_series( startDate::date,endDate::date, '1 day')::date "Dates" ,
--generate_series(timestamp '2022-10-31', '2023-03-16', '1 day')::date AS "Dates",
--generate_series(timestamp A."StartDate", A."EndDate", '1 day')::date AS "Dates",
A."ProviderId",A."ProviderAvailabilityId",A."LocationId", A."StartDate", A."EndDate", A."LocationId", S."SpecializationId"
from "ProviderAvailability" A
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Provider" PR on A."ProviderId" = PR."ProviderId" AND PR."Active" = TRUE
JOIN "Specialization" S on S."SpecializationId" = ANY(PR."Specializations") AND S."Active" IS TRUE
--JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."LocationId" = locationId And S."SpecializationId" = specializationId And A."Active" IS TRUE
)
,Availability as (
select A."FreeFollowUpDays", A."AvailableDay", A."ProviderAvailabilityId"
--A."ProviderId"
--,A."ProviderLocationId"
,A."LocationId", A."StartDate", A."EndDate", S."SpecializationId"
--,json_array_elements(case when (A."Availability" is null or A."Availability"='') then '[]' else (A."Availability"::json)end) "Availability"
from "ProviderAvailability" A
--left join "ProviderAvailabilitySlot" PAS on PAS."ProviderAvailabilityId" = A."ProviderAvailabilityId"
JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
JOIN "Provider" PR on A."ProviderId" = PR."ProviderId" AND PR."Active" = TRUE
JOIN "Specialization" S on S."SpecializationId" = ANY(PR."Specializations") AND S."Active" IS TRUE
--JOIN "Location" PL ON A."LocationId" = PL."LocationId" AND PL."Active" = TRUE
--JOIN "Practice" P ON P."PracticeId" = PL."PracticeId" AND P."Active" = TRUE
where A."ProviderId"=providerid AND A."LocationId" = locationId And S."SpecializationId" = specializationId And A."Active" IS TRUE
--and case when providerLocationId is null then 1=1 else A."ProviderLocationId"=providerLocationId end
)
,Avail as (
SELECT unnest(string_to_array(A."AvailableDay", ',')) AS "Day", A."ProviderAvailabilityId",A."LocationId", A."StartDate", A."EndDate", A."SpecializationId"
from Availability A
)
, LeaveAvailability as (
select A."ProviderId",A."LeaveDate",coalesce(A."ProviderAvailabilityId"::text,
(
select string_agg(D."ProviderAvailabilityId"::text,',') "ProviderAvailabilityId" from "ProviderAvailability" D where D."ProviderId"= providerid and D."LocationId" = locationId
))
"ProviderAvailabilityId" from "ProviderLeave" A where A."ProviderId"=providerid and A."LocationId" = locationId
)
,LeaveData as (
select A."ProviderId",A."LeaveDate",regexp_split_to_table(A."ProviderAvailabilityId",',') ::int "ProviderAvailabilityId"
from LeaveAvailability A
)
,FinalData as (
select DISTINCT C."LeaveDate", A."Dates" "Date", A."ProviderId",A."ProviderAvailabilityId",A."StartDate",A."EndDate"
--,A."LocationId"
,extract(ISODOW from "Dates")"DateNo", CASE
WHEN extract(ISODOW from "Dates") =1 THEN 'Monday'
WHEN extract(ISODOW from "Dates") =2 THEN 'Tuesday'
WHEN extract(ISODOW from "Dates")=3 THEN 'Wednesday'
WHEN extract(ISODOW from "Dates")=4 THEN 'Thursday'
WHEN extract(ISODOW from "Dates")=5 THEN 'Friday'
WHEN extract(ISODOW from "Dates")=6 THEN 'Saturday'
WHEN extract(ISODOW from "Dates")=7 THEN 'Sunday' end "Day" ,
case when C."LeaveDate" is not null then 'L' when B."Day" is not null then 'A' else '' end "Status"
from TotalDates A
left join Avail B on B."Day"::text::int = extract(ISODOW from A."Dates") and A."ProviderId"=A."ProviderId" and A."ProviderAvailabilityId"=B."ProviderAvailabilityId"
--and A."LocationId"=B."LocationId"
left join LeaveData C on C."LeaveDate"::date =A."Dates" and A."ProviderAvailabilityId"=C."ProviderAvailabilityId"
)
select DISTINCT A."Date",A."DateNo"::int,A."Day"::text::character varying(10),A."Status"::char
from FinalData A
where
--A."Date" >= A."StartDate"::Date or
A."Date" <= A."EndDate"::Date
order by A."Date";
end
$BODY$;
ALTER FUNCTION public."udf_fetchProviderAvailabilityDatesNew"(integer, integer, integer, text, text)
OWNER TO postgres;
delete from "PatientEmergency";
delete from "InsuranceApproval";
delete from "PatientInsurance";
\ No newline at end of file
-- FUNCTION: public.udf_FetchDoctor_With_Availability_Specialization(character varying, integer, integer)
-- DROP FUNCTION IF EXISTS public."udf_FetchDoctor_With_Availability_Specialization"(character varying, integer, integer);
CREATE OR REPLACE FUNCTION public."udf_FetchDoctor_With_Availability_Specialization"(
filter character varying DEFAULT NULL::text,
"locationId" integer DEFAULT NULL::integer,
"consultationTypeId" integer DEFAULT NULL::integer)
RETURNS TABLE("ProviderAvailabilityId" integer, "FullName" character varying, "DepartmentName" character varying, "DepartmentId" integer, "ProviderId" integer, "SpecializationId" integer, "SpecializationName" character varying, "LocationId" integer, "ConsultationTypeId" integer)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
BEGIN
return query
SELECT DISTINCT on (pr2."ProviderId", s."SpecializationId") prl."ProviderAvailabilityId" ,pr2."FullName"
, d."DepartmentName" , d."DepartmentId"
,pr2."ProviderId"
, s. "SpecializationId", s."SpecializationName"
, prl."LocationId", prl."ConsultationTypeId"
FROM "ProviderAvailability" prl
JOIN "Provider" pr2 on pr2."ProviderId" = prl."ProviderId" and pr2."Active" is true
join "Account" pa on pa."ReferenceId" = pr2."ProviderId" and pa."Active" is true and pa."RoleId" = 3
JOin "LocationAccountMap" LAM on LAM."AccountId" = pa."AccountId"
join "Specialization" s on s."SpecializationId" = ANY (pr2."Specializations")
JOIN "Location" pral on pral."LocationId" = prl."LocationId" AND pral."Active" IS TRUE
JOIN "Practice" pra on pra."PracticeId" = pral."PracticeId" AND pra."Active" IS TRUE
JOIN "Department" d on d."DepartmentId" = pr2."DepartmentId"
where pr2."Active" is true and LAM."LocationId" = "locationId" and s."Active" = true
and case when "filter" is null then 1=1 else TRIM(UPPER(pr2."FullName")) ilike'%'|| "filter"||'%' OR TRIM(UPPER(s."SpecializationName")) ilike'%'|| "filter"||'%' end
and case when "consultationTypeId" is null then 1=1 else prl."ConsultationTypeId" = "consultationTypeId" end
--and case when "locationId" is null then 1=1 else LAM."LocationId" = "LocationId" end
--order by "FullName" asc
;
END
$BODY$;
ALTER FUNCTION public."udf_FetchDoctor_With_Availability_Specialization"(character varying, integer, integer)
OWNER TO postgres;
-- FUNCTION: public.udf_emloyee_new_revenue(integer, integer, integer, date, date)
-- DROP FUNCTION IF EXISTS public.udf_emloyee_new_revenue(integer, integer, integer, date, date);
CREATE OR REPLACE FUNCTION public.udf_emloyee_new_revenue(
accountid integer DEFAULT NULL::integer,
locationid integer DEFAULT NULL::integer,
roleid integer DEFAULT NULL::integer,
"fromDate" date DEFAULT NULL::date,
"toDate" date DEFAULT NULL::date)
RETURNS TABLE("AccountId" integer, "EmployeeName" text, "RoleName" character varying, "RegistrationCashTotal" numeric, "RegistrationCardTotal" numeric, "RegistrationUPITotal" numeric, "RegistrationOnlineTotal" numeric, "RegistrationChequeTotal" numeric, "RegistrationPaytmTotal" numeric,
"RegistrationNotPaidTotal" numeric, "RegistrationOtherTotal" numeric, "RegistrationCardSwipeTotal" numeric, "RegistrationCardStandAloneTotal" numeric,
"RegistrationCardUPITotal" numeric,"RegistrationCardGpayTotal" numeric,"RegistrationCashDrawerTotal" numeric,"RegistrationCashChequeTotal" numeric,
"RegistrationCashDDTotal" numeric,"RegistrationWalletPaytmOfflineTotal" numeric,"RegistrationWalletPhonePeOfflineTotal" numeric,"RegistrationCashRemoteDepositTotal" numeric,
"RegistrationWalletPaytmDQRTotal" numeric, registrationamount numeric,
"AppointmentCashTotal" numeric, "AppointmentCardTotal" numeric, "AppointmentUPITotal" numeric, "AppointmentOnlineTotal" numeric, "AppointmentChequeTotal" numeric, "AppointmentPaytmTotal" numeric,
"AppointmentNotPaidTotal" numeric, "AppointmentOtherTotal" numeric, "AppointmentCardSwipeTotal" numeric, "AppointmentCardStandAloneTotal" numeric,
"AppointmentCardUPITotal" numeric,"AppointmentCardGpayTotal" numeric,"AppointmentCashDrawerTotal" numeric,"AppointmentCashChequeTotal" numeric,
"AppointmentCashDDTotal" numeric,"AppointmentWalletPaytmOfflineTotal" numeric,"AppointmentWalletPhonePeOfflineTotal" numeric,"AppointmentCashRemoteDepositTotal" numeric,
"AppointmentWalletPaytmDQRTotal" numeric,
"AppointmentAmount" numeric,
"AdmissionCashTotal" numeric, "AdmissionCardTotal" numeric, "AdmissionUPITotal" numeric, "AdmissionOnlineTotal" numeric, "AdmissionChequeTotal" numeric, "AdmissionPaytmTotal" numeric,
"AdmissionNotPaidTotal" numeric, "AdmissionOtherTotal" numeric, "AdmissionCardSwipeTotal" numeric, "AdmissionCardStandAloneTotal" numeric,
"AdmissionCardUPITotal" numeric,"AdmissionCardGpayTotal" numeric,"AdmissionCashDrawerTotal" numeric,"AdmissionCashChequeTotal" numeric,
"AdmissionCashDDTotal" numeric,"AdmissionWalletPaytmOfflineTotal" numeric,"AdmissionWalletPhonePeOfflineTotal" numeric,"AdmissionCashRemoteDepositTotal" numeric,
"AdmissionWalletPaytmDQRTotal" numeric,
"AdmissionAmount" numeric,
"LabCash" numeric, "LabCard" numeric, "LabUPI" numeric, "LabOnline" numeric, "LabCheque" numeric, "LabPaytm" numeric,
"LabNotPaidTotal" numeric, "LabOtherTotal" numeric, "LabCardSwipeTotal" numeric, "LabCardStandAloneTotal" numeric,
"LabCardUPITotal" numeric,"LabCardGpayTotal" numeric,"LabCashDrawerTotal" numeric,"LabCashChequeTotal" numeric,
"LabCashDDTotal" numeric,"LabWalletPaytmOfflineTotal" numeric,"LabWalletPhonePeOfflineTotal" numeric,"LabCashRemoteDepositTotal" numeric,
"LabWalletPaytmDQRTotal" numeric,
"LabAmount" numeric,
"PharmacySaleCash" numeric, "PharmacySaleCard" numeric, "PharmacySaleUPI" numeric, "PharmacySaleOnline" numeric, "PharmacySaleCheque" numeric, "PharmacySalePaytm" numeric,
"PharmacySaleNotPaidTotal" numeric, "PharmacySaleOtherTotal" numeric, "PharmacySaleCardSwipeTotal" numeric, "PharmacySaleCardStandAloneTotal" numeric,
"PharmacySaleCardUPITotal" numeric,"PharmacySaleCardGpayTotal" numeric,"PharmacySaleCashDrawerTotal" numeric,"PharmacySaleCashChequeTotal" numeric,
"PharmacySaleCashDDTotal" numeric,"PharmacySaleWalletPaytmOfflineTotal" numeric,"PharmacySaleWalletPhonePeOfflineTotal" numeric,"PharmacySaleCashRemoteDepositTotal" numeric,
"PharmacySaleWalletPaytmDQRTotal" numeric,
"PharmacyAmount" numeric,
"TotalCash" numeric, "TotalCard" numeric, "TotalUPI" numeric, "TotalOnline" numeric, "TotalCheque" numeric, "TotalPaytm" numeric,
"NotPaidTotal" numeric, "OtherTotal" numeric, "CardSwipeTotal" numeric, "CardStandAloneTotal" numeric,
"CardUPITotal" numeric,"CardGpayTotal" numeric,"CashDrawerTotal" numeric,"CashChequeTotal" numeric,
"CashDDTotal" numeric,"WalletPaytmOfflineTotal" numeric,"WalletPhonePeOfflineTotal" numeric,"CashRemoteDepositTotal" numeric,
"WalletPaytmDQRTotal" numeric,
"Total" numeric)
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query
with accountdata as (
select a."AccountId",a."FullName" "EmployeeName",rol."RoleName"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
join "Role" rol on rol."RoleId" = a."RoleId" --and lower(rol."RoleName") <> lower('Patient')
where a."RoleId"<>4
and case when accountid is null then 1=1 else a."AccountId"=accountid end
and case when roleid is null then 1=1 else a."RoleId"=roleid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
)
,patientRegistrationamount as(
select a."AccountId",
sum(A."CashTotal") "RegistrationCashTotal"
,sum(A."CardTotal") "RegistrationCardTotal",
sum(A."UPITotal") "RegistrationUPITotal",
sum(A."OnlineTotal") "RegistrationOnlineTotal",
sum(A."ChequeTotal") "RegistrationChequeTotal",
sum(A."PaytmTotal") "RegistrationPaytmTotal",
sum(A."NotPaidTotal") "RegistrationNotPaidTotal",
sum(A."OtherTotal") "RegistrationOtherTotal",
sum(A."CardSwipeTotal") "RegistrationCardSwipeTotal",
sum(A."CardStandAloneTotal") "RegistrationCardStandAloneTotal",
sum(A."CardUPITotal") "RegistrationCardUPITotal",
sum(A."CardGpayTotal") "RegistrationCardGpayTotal",
sum(A."CashDrawerTotal") "RegistrationCashDrawerTotal",
sum(A."CashChequeTotal") "RegistrationCashChequeTotal",
sum(A."CashDDTotal") "RegistrationCashDDTotal",
sum(A."WalletPaytmOfflineTotal") "RegistrationWalletPaytmOfflineTotal",
sum(A."WalletPhonePeOfflineTotal") "RegistrationWalletPhonePeOfflineTotal",
sum(A."CashRemoteDepositTotal") "RegistrationCashRemoteDepositTotal",
sum(A."WalletPaytmDQRTotal") "RegistrationWalletPaytmDQRTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal")
+sum(A."OtherTotal")+sum(A."CardSwipeTotal")
+sum(A."CardStandAloneTotal")+sum(A."CardUPITotal")+sum(A."CardGpayTotal")+sum(A."CashDrawerTotal")+sum(A."CashChequeTotal")+sum(A."NotPaidTotal")+
sum(A."CashDDTotal")+sum(A."WalletPaytmOfflineTotal")+sum(A."WalletPhonePeOfflineTotal")+sum(A."CashRemoteDepositTotal")+sum(A."WalletPaytmDQRTotal")
registrationamount
from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal",
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal",
case when A."PayTypeId"=7 then coalesce(A."Cost",0) else 0 end "NotPaidTotal",
case when A."PayTypeId"=8 then coalesce(A."Cost",0) else 0 end "OtherTotal",
case when A."PayTypeId"=9 then coalesce(A."Cost",0) else 0 end "CardSwipeTotal",
case when A."PayTypeId"=10 then coalesce(A."Cost",0) else 0 end "CardStandAloneTotal",
case when A."PayTypeId"=11 then coalesce(A."Cost",0) else 0 end "CardUPITotal",
case when A."PayTypeId"=12 then coalesce(A."Cost",0) else 0 end "CardGpayTotal",
case when A."PayTypeId"=13 then coalesce(A."Cost",0) else 0 end "CashDrawerTotal",
case when A."PayTypeId"=14 then coalesce(A."Cost",0) else 0 end "CashChequeTotal",
case when A."PayTypeId"=15 then coalesce(A."Cost",0) else 0 end "CashDDTotal",
case when A."PayTypeId"=16 then coalesce(A."Cost",0) else 0 end "WalletPaytmOfflineTotal",
case when A."PayTypeId"=17 then coalesce(A."Cost",0) else 0 end "WalletPhonePeOfflineTotal",
case when A."PayTypeId"=18 then coalesce(A."Cost",0) else 0 end "CashRemoteDepositTotal",
case when A."PayTypeId"=19 then coalesce(A."Cost",0) else 0 end "WalletPaytmDQRTotal"
from "Receipt" A
join "Patient" p on p."PatientId" =A."RespectiveId"
where A."ReceiptTypeId"=1 and p."Active" <> false and A."Active"<>false and A."RespectiveId" is not null
and case when accountid is null then 1=1 else a."CreatedBy"=accountid end
and case when (locationId IS NULL OR locationId=0) THEN 1=1 ELSE p."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
) a group by a."AccountId"
)
,actappointmentamount as (
select a."AccountId",
sum(A."CashTotal") "AppointmentCashTotal",
sum(A."CardTotal") "AppointmentCardTotal",
sum(A."UPITotal") "AppointmentUPITotal",
sum(A."OnlineTotal") "AppointmentOnlineTotal",
sum(A."ChequeTotal") "AppointmentChequeTotal",
sum(A."PaytmTotal") "AppointmentPaytmTotal",
sum(A."NotPaidTotal") "AppointmentNotPaidTotal",
sum(A."OtherTotal") "AppointmentOtherTotal",
sum(A."CardSwipeTotal") "AppointmentCardSwipeTotal",
sum(A."CardStandAloneTotal") "AppointmentCardStandAloneTotal",
sum(A."CardUPITotal") "AppointmentCardUPITotal",
sum(A."CardGpayTotal") "AppointmentCardGpayTotal",
sum(A."CashDrawerTotal") "AppointmentCashDrawerTotal",
sum(A."CashChequeTotal") "AppointmentCashChequeTotal",
sum(A."CashDDTotal") "AppointmentCashDDTotal",
sum(A."WalletPaytmOfflineTotal") "AppointmentWalletPaytmOfflineTotal",
sum(A."WalletPhonePeOfflineTotal") "AppointmentWalletPhonePeOfflineTotal",
sum(A."CashRemoteDepositTotal") "AppointmentCashRemoteDepositTotal",
sum(A."WalletPaytmDQRTotal") "AppointmentWalletPaytmDQRTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal")
+sum(A."OtherTotal")+sum(A."CardSwipeTotal")
+sum(A."CardStandAloneTotal")+sum(A."CardUPITotal")+sum(A."CardGpayTotal")+sum(A."CashDrawerTotal")+sum(A."CashChequeTotal")+sum(A."NotPaidTotal")+
sum(A."CashDDTotal")+sum(A."WalletPaytmOfflineTotal")+sum(A."WalletPhonePeOfflineTotal")+sum(A."CashRemoteDepositTotal")+sum(A."WalletPaytmDQRTotal")
appointmentamount
from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal",
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal",
case when A."PayTypeId"=7 then coalesce(A."Cost",0) else 0 end "NotPaidTotal",
case when A."PayTypeId"=8 then coalesce(A."Cost",0) else 0 end "OtherTotal",
case when A."PayTypeId"=9 then coalesce(A."Cost",0) else 0 end "CardSwipeTotal",
case when A."PayTypeId"=10 then coalesce(A."Cost",0) else 0 end "CardStandAloneTotal",
case when A."PayTypeId"=11 then coalesce(A."Cost",0) else 0 end "CardUPITotal",
case when A."PayTypeId"=12 then coalesce(A."Cost",0) else 0 end "CardGpayTotal",
case when A."PayTypeId"=13 then coalesce(A."Cost",0) else 0 end "CashDrawerTotal",
case when A."PayTypeId"=14 then coalesce(A."Cost",0) else 0 end "CashChequeTotal",
case when A."PayTypeId"=15 then coalesce(A."Cost",0) else 0 end "CashDDTotal",
case when A."PayTypeId"=16 then coalesce(A."Cost",0) else 0 end "WalletPaytmOfflineTotal",
case when A."PayTypeId"=17 then coalesce(A."Cost",0) else 0 end "WalletPhonePeOfflineTotal",
case when A."PayTypeId"=18 then coalesce(A."Cost",0) else 0 end "CashRemoteDepositTotal",
case when A."PayTypeId"=19 then coalesce(A."Cost",0) else 0 end "WalletPaytmDQRTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."RespectiveId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end and A."ReceiptTypeId"=1
and A."Active"<>false and A."RespectiveId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) <>true and ap."Status" <> 'C' and
case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
)a
group by a."AccountId"
)
,refundappointmentamount as (
select a."AccountId" ,
sum(A."CashTotal") "AppointmentRefCashTotal",
sum(A."CardTotal") "AppointmentRefCardTotal",
sum(A."UPITotal") "AppointmentRefUPITotal",
sum(A."OnlineTotal") "AppointmentRefOnlineTotal",
sum(A."ChequeTotal") "AppointmentRefChequeTotal",
sum(A."PaytmTotal") "AppointmentRefPaytmTotal",
sum(A."NotPaidTotal") "AppointmentRefNotPaidTotal",
sum(A."OtherTotal") "AppointmentRefOtherTotal",
sum(A."CardSwipeTotal") "AppointmentRefCardSwipeTotal",
sum(A."CardStandAloneTotal") "AppointmentRefCardStandAloneTotal",
sum(A."CardUPITotal") "AppointmentRefCardUPITotal",
sum(A."CardGpayTotal") "AppointmentRefCardGpayTotal",
sum(A."CashDrawerTotal") "AppointmentRefCashDrawerTotal",
sum(A."CashChequeTotal") "AppointmentRefCashChequeTotal",
sum(A."CashDDTotal") "AppointmentRefCashDDTotal",
sum(A."WalletPaytmOfflineTotal") "AppointmentRefWalletPaytmOfflineTotal",
sum(A."WalletPhonePeOfflineTotal") "AppointmentRefWalletPhonePeOfflineTotal",
sum(A."CashRemoteDepositTotal") "AppointmentRefCashRemoteDepositTotal",
sum(A."WalletPaytmDQRTotal") "AppointmentRefWalletPaytmDQRTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal")
+sum(A."OtherTotal")+sum(A."CardSwipeTotal")+sum(A."CardStandAloneTotal")+sum(A."CardUPITotal")+sum(A."CardGpayTotal")+sum(A."CashDrawerTotal")+sum(A."CashChequeTotal")+sum(A."NotPaidTotal")+
sum(A."CashDDTotal")+sum(A."WalletPaytmOfflineTotal")+sum(A."WalletPhonePeOfflineTotal")+sum(A."CashRemoteDepositTotal")+sum(A."WalletPaytmDQRTotal")
refappointmentamount
from (
select a."CreatedBy" "AccountId",
case when A."PayTypeId"=1 then coalesce(A."Cost",0) else 0 end "CashTotal" ,
case when A."PayTypeId"=2 then coalesce(A."Cost",0) else 0 end "CardTotal" ,
case when A."PayTypeId"=3 then coalesce(A."Cost",0) else 0 end "UPITotal" ,
case when A."PayTypeId"=4 then coalesce(A."Cost",0) else 0 end "OnlineTotal",
case when A."PayTypeId"=5 then coalesce(A."Cost",0) else 0 end "ChequeTotal" ,
case when A."PayTypeId"=6 then coalesce(A."Cost",0) else 0 end "PaytmTotal",
case when A."PayTypeId"=7 then coalesce(A."Cost",0) else 0 end "NotPaidTotal",
case when A."PayTypeId"=8 then coalesce(A."Cost",0) else 0 end "OtherTotal",
case when A."PayTypeId"=9 then coalesce(A."Cost",0) else 0 end "CardSwipeTotal",
case when A."PayTypeId"=10 then coalesce(A."Cost",0) else 0 end "CardStandAloneTotal",
case when A."PayTypeId"=11 then coalesce(A."Cost",0) else 0 end "CardUPITotal",
case when A."PayTypeId"=12 then coalesce(A."Cost",0) else 0 end "CardGpayTotal",
case when A."PayTypeId"=13 then coalesce(A."Cost",0) else 0 end "CashDrawerTotal",
case when A."PayTypeId"=14 then coalesce(A."Cost",0) else 0 end "CashChequeTotal",
case when A."PayTypeId"=15 then coalesce(A."Cost",0) else 0 end "CashDDTotal",
case when A."PayTypeId"=16 then coalesce(A."Cost",0) else 0 end "WalletPaytmOfflineTotal",
case when A."PayTypeId"=17 then coalesce(A."Cost",0) else 0 end "WalletPhonePeOfflineTotal",
case when A."PayTypeId"=18 then coalesce(A."Cost",0) else 0 end "CashRemoteDepositTotal",
case when A."PayTypeId"=19 then coalesce(A."Cost",0) else 0 end "WalletPaytmDQRTotal"
from "Receipt" A
join "Appointment" ap on ap."AppointmentId" =A."RespectiveId"
join "Provider" pr on pr."ProviderId"= ap."ProviderId"
and ap."Status" <> 'C' and ap."Active" =true
where case when accountid is null then 1=1 else a."CreatedBy"=accountid end
and A."Active"<>false and A."RespectiveId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ap."LocationId"=locationId END
and coalesce(A."IsRefunded",false) = true and
case when "fromDate" is null then 1=1
else (A."CreatedDate"::date >= "fromDate" and A."CreatedDate"::date <= "toDate") end
) a
group by a."AccountId"
)
,appointmentamount as (
select A."AccountId",
coalesce(A."AppointmentCashTotal",0) - coalesce(B."AppointmentRefCashTotal",0) as "AppointmentCashTotal" ,
coalesce(A."AppointmentCardTotal",0) - coalesce(B."AppointmentRefCardTotal",0) as "AppointmentCardTotal" ,
coalesce(A."AppointmentUPITotal",0) - coalesce(B."AppointmentRefUPITotal",0) as "AppointmentUPITotal" ,
coalesce(A."AppointmentOnlineTotal",0) - coalesce(B."AppointmentRefOnlineTotal",0) as "AppointmentOnlineTotal" ,
coalesce(A."AppointmentChequeTotal",0) - coalesce(B."AppointmentRefChequeTotal",0) as "AppointmentChequeTotal" ,
coalesce(A."AppointmentPaytmTotal",0) - coalesce(B."AppointmentRefPaytmTotal",0) as "AppointmentPaytmTotal" ,
coalesce(A."AppointmentNotPaidTotal",0) - coalesce(B."AppointmentRefNotPaidTotal",0) as "AppointmentNotPaidTotal" ,
coalesce(A."AppointmentOtherTotal",0) - coalesce(B."AppointmentRefOtherTotal",0) as "AppointmentOtherTotal" ,
coalesce(A."AppointmentCardSwipeTotal",0) - coalesce(B."AppointmentRefCardSwipeTotal",0) as "AppointmentCardSwipeTotal" ,
coalesce(A."AppointmentCardStandAloneTotal",0) - coalesce(B."AppointmentRefCardStandAloneTotal",0) as "AppointmentCardStandAloneTotal" ,
coalesce(A."AppointmentCardUPITotal",0) - coalesce(B."AppointmentRefCardUPITotal",0) as "AppointmentCardUPITotal" ,
coalesce(A."AppointmentCardGpayTotal",0) - coalesce(B."AppointmentRefCardGpayTotal",0) as "AppointmentCardGpayTotal" ,
coalesce(A."AppointmentCashDrawerTotal",0) - coalesce(B."AppointmentRefCashDrawerTotal",0) as "AppointmentCashDrawerTotal" ,
coalesce(A."AppointmentCashChequeTotal",0) - coalesce(B."AppointmentRefCashChequeTotal",0) as "AppointmentCashChequeTotal" ,
coalesce(A."AppointmentCashDDTotal",0) - coalesce(B."AppointmentRefCashDDTotal",0) as "AppointmentCashDDTotal" ,
coalesce(A."AppointmentWalletPaytmOfflineTotal",0) - coalesce(B."AppointmentRefWalletPaytmOfflineTotal",0) as "AppointmentWalletPaytmOfflineTotal" ,
coalesce(A."AppointmentWalletPhonePeOfflineTotal",0) - coalesce(B."AppointmentRefWalletPhonePeOfflineTotal",0) as "AppointmentWalletPhonePeOfflineTotal" ,
coalesce(A."AppointmentCashRemoteDepositTotal",0) - coalesce(B."AppointmentRefCashRemoteDepositTotal",0) as "AppointmentCashRemoteDepositTotal" ,
coalesce(A."AppointmentWalletPaytmDQRTotal",0) - coalesce(B."AppointmentRefWalletPaytmDQRTotal",0) as "AppointmentWalletPaytmDQRTotal" ,
coalesce(A.appointmentamount,0) - coalesce(B.refappointmentamount,0) as "AppointmentAmount" from actappointmentamount A
left join refundappointmentamount B on A."AccountId"=B."AccountId"
)
,actadmissionamount as (
select a."AccountId" ,
sum(A."CashTotal") "AdmissionCashTotal",
sum(A."CardTotal") "AdmissionCardTotal",
sum(A."UPITotal") "AdmissionUPITotal",
sum(A."OnlineTotal") "AdmissionOnlineTotal",
sum(A."ChequeTotal") "AdmissionChequeTotal",
sum(A."PaytmTotal") "AdmissionPaytmTotal",
sum(A."NotPaidTotal") "AdmissionNotPaidTotal",
sum(A."OtherTotal") "AdmissionOtherTotal",
sum(A."CardSwipeTotal") "AdmissionCardSwipeTotal",
sum(A."CardStandAloneTotal") "AdmissionCardStandAloneTotal",
sum(A."CardUPITotal") "AdmissionCardUPITotal",
sum(A."CardGpayTotal") "AdmissionCardGpayTotal",
sum(A."CashDrawerTotal") "AdmissionCashDrawerTotal",
sum(A."CashChequeTotal") "AdmissionCashChequeTotal",
sum(A."CashDDTotal") "AdmissionCashDDTotal",
sum(A."WalletPaytmOfflineTotal") "AdmissionWalletPaytmOfflineTotal",
sum(A."WalletPhonePeOfflineTotal") "AdmissionWalletPhonePeOfflineTotal",
sum(A."CashRemoteDepositTotal") "AdmissionCashRemoteDepositTotal",
sum(A."WalletPaytmDQRTotal") "AdmissionWalletPaytmDQRTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal")
+sum(A."OtherTotal")+sum(A."CardSwipeTotal")+sum(A."CardStandAloneTotal")+sum(A."CardUPITotal")+sum(A."CardGpayTotal")+sum(A."CashDrawerTotal")+sum(A."CashChequeTotal")+sum(A."NotPaidTotal")+
sum(A."CashDDTotal")+sum(A."WalletPaytmOfflineTotal")+sum(A."WalletPhonePeOfflineTotal")+sum(A."CashRemoteDepositTotal")+sum(A."WalletPaytmDQRTotal")
"AdmissionAmount"
from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal" ,
case when adr."PayTypeId"=3 then coalesce(adr."Cost",0) else 0 end "UPITotal" ,
case when adr."PayTypeId"=4 then coalesce(adr."Cost",0) else 0 end "OnlineTotal" ,
case when adr."PayTypeId"=5 then coalesce(adr."Cost",0) else 0 end "ChequeTotal" ,
case when adr."PayTypeId"=6 then coalesce(adr."Cost",0) else 0 end "PaytmTotal" ,
case when adr."PayTypeId"=7 then coalesce(adr."Cost",0) else 0 end "NotPaidTotal",
case when adr."PayTypeId"=8 then coalesce(adr."Cost",0) else 0 end "OtherTotal",
case when adr."PayTypeId"=9 then coalesce(adr."Cost",0) else 0 end "CardSwipeTotal",
case when adr."PayTypeId"=10 then coalesce(adr."Cost",0) else 0 end "CardStandAloneTotal",
case when adr."PayTypeId"=11 then coalesce(adr."Cost",0) else 0 end "CardUPITotal",
case when adr."PayTypeId"=12 then coalesce(adr."Cost",0) else 0 end "CardGpayTotal",
case when adr."PayTypeId"=13 then coalesce(adr."Cost",0) else 0 end "CashDrawerTotal",
case when adr."PayTypeId"=14 then coalesce(adr."Cost",0) else 0 end "CashChequeTotal",
case when adr."PayTypeId"=15 then coalesce(adr."Cost",0) else 0 end "CashDDTotal",
case when adr."PayTypeId"=16 then coalesce(adr."Cost",0) else 0 end "WalletPaytmOfflineTotal",
case when adr."PayTypeId"=17 then coalesce(adr."Cost",0) else 0 end "WalletPhonePeOfflineTotal",
case when adr."PayTypeId"=18 then coalesce(adr."Cost",0) else 0 end "CashRemoteDepositTotal",
case when adr."PayTypeId"=19 then coalesce(adr."Cost",0) else 0 end "WalletPaytmDQRTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."ReceiptTypeId"=1 and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate"::date >= "fromDate" and adr."CreatedDate"::date <= "toDate") end )a
group by a."AccountId"
)
,refadmissionamount as (
select a."AccountId" ,
sum(A."CashTotal") "AdmissionRefCashTotal",
sum(A."CardTotal") "AdmissionRefCardTotal",
sum(A."UPITotal") "AdmissionRefUPITotal",
sum(A."OnlineTotal") "AdmissionRefOnlineTotal",
sum(A."ChequeTotal") "AdmissionRefChequeTotal",
sum(A."PaytmTotal") "AdmissionRefPaytmTotal",
sum(A."NotPaidTotal") "AdmissionRefNotPaidTotal",
sum(A."OtherTotal") "AdmissionRefOtherTotal",
sum(A."CardSwipeTotal") "AdmissionRefCardSwipeTotal",
sum(A."CardStandAloneTotal") "AdmissionRefCardStandAloneTotal",
sum(A."CardUPITotal") "AdmissionRefCardUPITotal",
sum(A."CardGpayTotal") "AdmissionRefCardGpayTotal",
sum(A."CashDrawerTotal") "AdmissionRefCashDrawerTotal",
sum(A."CashChequeTotal") "AdmissionRefCashChequeTotal",
sum(A."CashDDTotal") "AdmissionRefCashDDTotal",
sum(A."WalletPaytmOfflineTotal") "AdmissionRefWalletPaytmOfflineTotal",
sum(A."WalletPhonePeOfflineTotal") "AdmissionRefWalletPhonePeOfflineTotal",
sum(A."CashRemoteDepositTotal") "AdmissionRefCashRemoteDepositTotal",
sum(A."WalletPaytmDQRTotal") "AdmissionRefWalletPaytmDQRTotal",
sum(A."CashTotal")+ sum(A."CardTotal")+ sum(A."UPITotal")+ sum(A."OnlineTotal")+ sum(A."ChequeTotal")+ sum(A."PaytmTotal")
+sum(A."OtherTotal")+sum(A."CardSwipeTotal")+sum(A."CardStandAloneTotal")+sum(A."CardUPITotal")+sum(A."CardGpayTotal")+sum(A."CashDrawerTotal")+sum(A."CashChequeTotal")+sum(A."NotPaidTotal")+
sum(A."CashDDTotal")+sum(A."WalletPaytmOfflineTotal")+sum(A."WalletPhonePeOfflineTotal")+sum(A."CashRemoteDepositTotal")+sum(A."WalletPaytmDQRTotal")
"AdmissionRefAmount"
from (
select adr."CreatedBy" "AccountId" ,
case when adr."PayTypeId"=1 then coalesce(adr."Cost",0) else 0 end "CashTotal" ,
case when adr."PayTypeId"=2 then coalesce(adr."Cost",0) else 0 end "CardTotal" ,
case when adr."PayTypeId"=3 then coalesce(adr."Cost",0) else 0 end "UPITotal" ,
case when adr."PayTypeId"=4 then coalesce(adr."Cost",0) else 0 end "OnlineTotal" ,
case when adr."PayTypeId"=5 then coalesce(adr."Cost",0) else 0 end "ChequeTotal" ,
case when adr."PayTypeId"=6 then coalesce(adr."Cost",0) else 0 end "PaytmTotal" ,
case when adr."PayTypeId"=7 then coalesce(adr."Cost",0) else 0 end "NotPaidTotal",
case when adr."PayTypeId"=8 then coalesce(adr."Cost",0) else 0 end "OtherTotal",
case when adr."PayTypeId"=9 then coalesce(adr."Cost",0) else 0 end "CardSwipeTotal",
case when adr."PayTypeId"=10 then coalesce(adr."Cost",0) else 0 end "CardStandAloneTotal",
case when adr."PayTypeId"=11 then coalesce(adr."Cost",0) else 0 end "CardUPITotal",
case when adr."PayTypeId"=12 then coalesce(adr."Cost",0) else 0 end "CardGpayTotal",
case when adr."PayTypeId"=13 then coalesce(adr."Cost",0) else 0 end "CashDrawerTotal",
case when adr."PayTypeId"=14 then coalesce(adr."Cost",0) else 0 end "CashChequeTotal",
case when adr."PayTypeId"=15 then coalesce(adr."Cost",0) else 0 end "CashDDTotal",
case when adr."PayTypeId"=16 then coalesce(adr."Cost",0) else 0 end "WalletPaytmOfflineTotal",
case when adr."PayTypeId"=17 then coalesce(adr."Cost",0) else 0 end "WalletPhonePeOfflineTotal",
case when adr."PayTypeId"=18 then coalesce(adr."Cost",0) else 0 end "CashRemoteDepositTotal",
case when adr."PayTypeId"=19 then coalesce(adr."Cost",0) else 0 end "WalletPaytmDQRTotal"
from "Receipt" adr
join "Admission" ad on adr."AdmissionId" = ad."AdmissionId" and ad."Active" <> false
join "Provider" pr on pr."ProviderId"= ad."ProviderId"
where case when accountid is null then 1=1 else adr."CreatedBy"=accountid end
and adr."IsRefunded" = true and adr."Active"<>false and adr."AdmissionId" is not null
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ad."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (adr."CreatedDate"::date >= "fromDate" and adr."CreatedDate"::date <= "toDate") end )a
group by a."AccountId"
)
,admissionamount as (
select A."AccountId" ,
coalesce(A."AdmissionCashTotal",0) - coalesce(B."AdmissionRefCashTotal",0) "AdmissionCashTotal",
coalesce(A."AdmissionCardTotal",0) - coalesce(B."AdmissionRefCardTotal",0) "AdmissionCardTotal",
coalesce(A."AdmissionUPITotal",0) - coalesce(B."AdmissionRefUPITotal",0) "AdmissionUPITotal",
coalesce(A."AdmissionOnlineTotal",0) - coalesce(B."AdmissionRefOnlineTotal",0) "AdmissionOnlineTotal",
coalesce(A."AdmissionChequeTotal",0) - coalesce(B."AdmissionRefChequeTotal",0) "AdmissionChequeTotal",
coalesce(A."AdmissionPaytmTotal",0) - coalesce(B."AdmissionRefPaytmTotal",0) "AdmissionPaytmTotal",
coalesce(A."AdmissionNotPaidTotal",0) - coalesce(B."AdmissionRefNotPaidTotal",0) as "AdmissionNotPaidTotal" ,
coalesce(A."AdmissionOtherTotal",0) - coalesce(B."AdmissionRefOtherTotal",0) as "AdmissionOtherTotal" ,
coalesce(A."AdmissionCardSwipeTotal",0) - coalesce(B."AdmissionRefCardSwipeTotal",0) as "AdmissionCardSwipeTotal" ,
coalesce(A."AdmissionCardStandAloneTotal",0) - coalesce(B."AdmissionRefCardStandAloneTotal",0) as "AdmissionCardStandAloneTotal" ,
coalesce(A."AdmissionCardUPITotal",0) - coalesce(B."AdmissionRefCardUPITotal",0) as "AdmissionCardUPITotal" ,
coalesce(A."AdmissionCardGpayTotal",0) - coalesce(B."AdmissionRefCardGpayTotal",0) as "AdmissionCardGpayTotal" ,
coalesce(A."AdmissionCashDrawerTotal",0) - coalesce(B."AdmissionRefCashDrawerTotal",0) as "AdmissionCashDrawerTotal" ,
coalesce(A."AdmissionCashChequeTotal",0) - coalesce(B."AdmissionRefCashChequeTotal",0) as "AdmissionCashChequeTotal" ,
coalesce(A."AdmissionCashDDTotal",0) - coalesce(B."AdmissionRefCashDDTotal",0) as "AdmissionCashDDTotal" ,
coalesce(A."AdmissionWalletPaytmOfflineTotal",0) - coalesce(B."AdmissionRefWalletPaytmOfflineTotal",0) as "AdmissionWalletPaytmOfflineTotal" ,
coalesce(A."AdmissionWalletPhonePeOfflineTotal",0) - coalesce(B."AdmissionRefWalletPhonePeOfflineTotal",0) as "AdmissionWalletPhonePeOfflineTotal" ,
coalesce(A."AdmissionCashRemoteDepositTotal",0) - coalesce(B."AdmissionRefCashRemoteDepositTotal",0) as "AdmissionCashRemoteDepositTotal" ,
coalesce(A."AdmissionWalletPaytmDQRTotal",0) - coalesce(B."AdmissionRefWalletPaytmDQRTotal",0) as "AdmissionWalletPaytmDQRTotal" ,
coalesce(A."AdmissionAmount",0) - coalesce(B."AdmissionRefAmount",0) "AdmissionAmount"
from actadmissionamount A
left join refadmissionamount B on A."AccountId"=B."AccountId"
)
,LabAmount as (
select a."AccountId",
sum(a."Cash") "LabCash",
sum(a."Card") "LabCard" ,
sum(a."UPI") "LabUPI",
sum(a."Online") "LabOnline" ,
sum(a."Cheque") "LabCheque",
sum(a."Paytm") "LabPaytm" ,
sum(a."NotPaidTotal") "LabNotPaidTotal",
sum(a."OtherTotal") "LabOtherTotal",
sum(a."CardSwipeTotal") "LabCardSwipeTotal",
sum(a."CardStandAloneTotal") "LabCardStandAloneTotal",
sum(a."CardUPITotal") "LabCardUPITotal",
sum(a."CardGpayTotal") "LabCardGpayTotal",
sum(a."CashDrawerTotal") "LabCashDrawerTotal",
sum(a."CashChequeTotal") "LabCashChequeTotal",
sum(a."CashDDTotal") "LabCashDDTotal",
sum(a."WalletPaytmOfflineTotal") "LabWalletPaytmOfflineTotal",
sum(a."WalletPhonePeOfflineTotal") "LabWalletPhonePeOfflineTotal",
sum(a."CashRemoteDepositTotal") "LabCashRemoteDepositTotal",
sum(a."WalletPaytmDQRTotal") "LabWalletPaytmDQRTotal",
sum(a."Cash")+ sum(a."Card")+ sum(a."UPI")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm")
+sum(a."OtherTotal")+sum(a."CardSwipeTotal")+sum(a."CardStandAloneTotal")+sum(a."CardUPITotal")+sum(a."CardGpayTotal")+sum(a."CashDrawerTotal")+sum(a."CashChequeTotal")+sum(a."NotPaidTotal")+
sum(a."CashDDTotal")+sum(a."WalletPaytmOfflineTotal")+sum(a."WalletPhonePeOfflineTotal")+sum(a."CashRemoteDepositTotal")+sum(a."WalletPaytmDQRTotal")
"LabAmount"
from(
select a."AccountId",
case when ar."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when ar."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm",
case when ar."PayTypeId"=7 then coalesce(ar."OverallNetAmount",0) else 0 end "NotPaidTotal",
case when ar."PayTypeId"=8 then coalesce(ar."OverallNetAmount",0) else 0 end "OtherTotal",
case when ar."PayTypeId"=9 then coalesce(ar."OverallNetAmount",0) else 0 end "CardSwipeTotal",
case when ar."PayTypeId"=10 then coalesce(ar."OverallNetAmount",0) else 0 end "CardStandAloneTotal",
case when ar."PayTypeId"=11 then coalesce(ar."OverallNetAmount",0) else 0 end "CardUPITotal",
case when ar."PayTypeId"=12 then coalesce(ar."OverallNetAmount",0) else 0 end "CardGpayTotal",
case when ar."PayTypeId"=13 then coalesce(ar."OverallNetAmount",0) else 0 end "CashDrawerTotal",
case when ar."PayTypeId"=14 then coalesce(ar."OverallNetAmount",0) else 0 end "CashChequeTotal",
case when ar."PayTypeId"=15 then coalesce(ar."OverallNetAmount",0) else 0 end "CashDDTotal",
case when ar."PayTypeId"=16 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPaytmOfflineTotal",
case when ar."PayTypeId"=17 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPhonePeOfflineTotal",
case when ar."PayTypeId"=18 then coalesce(ar."OverallNetAmount",0) else 0 end "CashRemoteDepositTotal",
case when ar."PayTypeId"=19 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPaytmDQRTotal"
from "Account" a
join "NewLabBookingHeader" ar on ar."CreatedBy" = a."AccountId" and ar."Active" <> false
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."CreatedDate"::date >= "fromDate" and ar."CreatedDate"::date <= "toDate") end)a
group by a."AccountId" )
,PharmaSaleAmount as (
select a."AccountId", sum(a."Cash") "PharmaSaleCash",
sum(a."Card") "PharmaSaleCard" ,
sum(a."UPI") "PharmaSaleUPI",
sum(a."Online") "PharmaSaleOnline" ,
sum(a."Cheque") "PharmaSaleCheque",
sum(a."Paytm") "PharmaSalePaytm" ,
sum(a."NotPaidTotal") "PharmaSaleNotPaidTotal",
sum(a."OtherTotal") "PharmaSaleOtherTotal",
sum(a."CardSwipeTotal") "PharmaSaleCardSwipeTotal",
sum(a."CardStandAloneTotal") "PharmaSaleCardStandAloneTotal",
sum(a."CardUPITotal") "PharmaSaleCardUPITotal",
sum(a."CardGpayTotal") "PharmaSaleCardGpayTotal",
sum(a."CashDrawerTotal") "PharmaSaleCashDrawerTotal",
sum(a."CashChequeTotal") "PharmaSaleCashChequeTotal",
sum(a."CashDDTotal") "PharmaSaleCashDDTotal",
sum(a."WalletPaytmOfflineTotal") "PharmaSaleWalletPaytmOfflineTotal",
sum(a."WalletPhonePeOfflineTotal") "PharmaSaleWalletPhonePeOfflineTotal",
sum(a."CashRemoteDepositTotal") "PharmaSaleCashRemoteDepositTotal",
sum(a."WalletPaytmDQRTotal") "PharmaSaleWalletPaytmDQRTotal",
sum(a."Cash")+ sum(a."Card")+ sum(a."UPI")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm")
+sum(a."OtherTotal")+sum(a."CardSwipeTotal")+sum(a."CardStandAloneTotal")+sum(a."CardUPITotal")+sum(a."CardGpayTotal")+sum(a."CashDrawerTotal")+sum(a."CashChequeTotal")+sum(a."NotPaidTotal")+
sum(a."CashDDTotal")+sum(a."WalletPaytmOfflineTotal")+sum(a."WalletPhonePeOfflineTotal")+sum(a."CashRemoteDepositTotal")+sum(a."WalletPaytmDQRTotal")
"PharmaSaleAmount"
from (
select a."AccountId",
case when ar."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when ar."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when ar."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "UPI"
,case when ar."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when ar."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when ar."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm",
case when ar."PayTypeId"=7 then coalesce(ar."OverallNetAmount",0) else 0 end "NotPaidTotal",
case when ar."PayTypeId"=8 then coalesce(ar."OverallNetAmount",0) else 0 end "OtherTotal",
case when ar."PayTypeId"=9 then coalesce(ar."OverallNetAmount",0) else 0 end "CardSwipeTotal",
case when ar."PayTypeId"=10 then coalesce(ar."OverallNetAmount",0) else 0 end "CardStandAloneTotal",
case when ar."PayTypeId"=11 then coalesce(ar."OverallNetAmount",0) else 0 end "CardUPITotal",
case when ar."PayTypeId"=12 then coalesce(ar."OverallNetAmount",0) else 0 end "CardGpayTotal",
case when ar."PayTypeId"=13 then coalesce(ar."OverallNetAmount",0) else 0 end "CashDrawerTotal",
case when ar."PayTypeId"=14 then coalesce(ar."OverallNetAmount",0) else 0 end "CashChequeTotal",
case when ar."PayTypeId"=15 then coalesce(ar."OverallNetAmount",0) else 0 end "CashDDTotal",
case when ar."PayTypeId"=16 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPaytmOfflineTotal",
case when ar."PayTypeId"=17 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPhonePeOfflineTotal",
case when ar."PayTypeId"=18 then coalesce(ar."OverallNetAmount",0) else 0 end "CashRemoteDepositTotal",
case when ar."PayTypeId"=19 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPaytmDQRTotal"
from "Account" a
join "PharmacySaleHeader" ar on ar."CreatedBy" = a."AccountId"
where case when accountid is null then 1=1 else a."AccountId"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE ar."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."SaleDate"::date >= "fromDate" and ar."SaleDate"::date <= "toDate") end
)a
group by a."AccountId"
)
,PharmaReturnAmount as (
select a."AccountId",
sum(a."Cash") "PharmaReturnCash",
sum(a."Card") "PharmaReturnCard" ,
sum(a."UPI") "PharmaReturnUPI",
sum(a."Online") "PharmaReturnOnline" ,
sum(a."Cheque") "PharmaReturnCheque",
sum(a."Paytm") "PharmaReturnPaytm" ,
sum(a."NotPaidTotal") "PharmaReturnNotPaidTotal",
sum(a."OtherTotal") "PharmaReturnOtherTotal",
sum(a."CardSwipeTotal") "PharmaReturnCardSwipeTotal",
sum(a."CardStandAloneTotal") "PharmaReturnCardStandAloneTotal",
sum(a."CardUPITotal") "PharmaReturnCardUPITotal",
sum(a."CardGpayTotal") "PharmaReturnCardGpayTotal",
sum(a."CashDrawerTotal") "PharmaReturnCashDrawerTotal",
sum(a."CashChequeTotal") "PharmaReturnCashChequeTotal",
sum(a."CashDDTotal") "PharmaReturnCashDDTotal",
sum(a."WalletPaytmOfflineTotal") "PharmaReturnWalletPaytmOfflineTotal",
sum(a."WalletPhonePeOfflineTotal") "PharmaReturnWalletPhonePeOfflineTotal",
sum(a."CashRemoteDepositTotal") "PharmaReturnCashRemoteDepositTotal",
sum(a."WalletPaytmDQRTotal") "PharmaReturnWalletPaytmDQRTotal",
sum(a."Cash")+ sum(a."Card")+ sum(a."UPI")+ sum(a."Online")+ sum(a."Cheque")+ sum(a."Paytm")
+sum(a."OtherTotal")+sum(a."CardSwipeTotal")+sum(a."CardStandAloneTotal")+sum(a."CardUPITotal")+sum(a."CardGpayTotal")+sum(a."CashDrawerTotal")+sum(a."CashChequeTotal")+sum(a."NotPaidTotal")+
sum(a."CashDDTotal")+sum(a."WalletPaytmOfflineTotal")+sum(a."WalletPhonePeOfflineTotal")+sum(a."CashRemoteDepositTotal")+sum(a."WalletPaytmDQRTotal")
"PharmaReturnAmount"
from(
select a."AccountId",
case when srh."PayTypeId"=1 then coalesce(ar."OverallNetAmount",0) else 0 end "Cash"
,case when srh."PayTypeId"=2 then coalesce(ar."OverallNetAmount",0) else 0 end "Card"
,case when srh."PayTypeId"=3 then coalesce(ar."OverallNetAmount",0) else 0 end "UPI"
,case when srh."PayTypeId"=4 then coalesce(ar."OverallNetAmount",0) else 0 end "Online"
,case when srh."PayTypeId"=5 then coalesce(ar."OverallNetAmount",0) else 0 end "Cheque"
,case when srh."PayTypeId"=6 then coalesce(ar."OverallNetAmount",0) else 0 end "Paytm",
case when srh."PayTypeId"=7 then coalesce(ar."OverallNetAmount",0) else 0 end "NotPaidTotal",
case when srh."PayTypeId"=8 then coalesce(ar."OverallNetAmount",0) else 0 end "OtherTotal",
case when srh."PayTypeId"=9 then coalesce(ar."OverallNetAmount",0) else 0 end "CardSwipeTotal",
case when srh."PayTypeId"=10 then coalesce(ar."OverallNetAmount",0) else 0 end "CardStandAloneTotal",
case when srh."PayTypeId"=11 then coalesce(ar."OverallNetAmount",0) else 0 end "CardUPITotal",
case when srh."PayTypeId"=12 then coalesce(ar."OverallNetAmount",0) else 0 end "CardGpayTotal",
case when srh."PayTypeId"=13 then coalesce(ar."OverallNetAmount",0) else 0 end "CashDrawerTotal",
case when srh."PayTypeId"=14 then coalesce(ar."OverallNetAmount",0) else 0 end "CashChequeTotal",
case when srh."PayTypeId"=15 then coalesce(ar."OverallNetAmount",0) else 0 end "CashDDTotal",
case when srh."PayTypeId"=16 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPaytmOfflineTotal",
case when srh."PayTypeId"=17 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPhonePeOfflineTotal",
case when srh."PayTypeId"=18 then coalesce(ar."OverallNetAmount",0) else 0 end "CashRemoteDepositTotal",
case when srh."PayTypeId"=19 then coalesce(ar."OverallNetAmount",0) else 0 end "WalletPaytmDQRTotal"
from "Account" a
JOIN "LocationAccountMap" LAM on LAM."AccountId"=a."AccountId"
left join "SaleReturnHeader" ar on ar."CreatedBy" = a."AccountId"
left join "PharmacySaleHeader" srh on srh."PharmacySaleHeaderId" = ar."PharmacySaleHeaderId"
where case when accountid is null then 1=1 else ar."CreatedBy"=accountid end
AND CASE WHEN (locationId IS NULL OR locationId=0) THEN 1=1 ELSE LAM."LocationId"=locationId END
and case when "fromDate" is null then 1=1
else (ar."ReturnDate"::date >= "fromDate" and ar."ReturnDate"::date <= "toDate") end
)a
group by a."AccountId"
)
,PharmaAmount as (
select a."AccountId",
coalesce(a."PharmaSaleCash",0) - coalesce(b."PharmaReturnCash",0) as "PharmaSaleCash" ,
coalesce(a."PharmaSaleCard",0) - coalesce(b."PharmaReturnCard",0) as "PharmaSaleCard" ,
coalesce(a."PharmaSaleUPI",0) - coalesce(b."PharmaReturnUPI",0) as "PharmaSaleUPI" ,
coalesce(a."PharmaSaleOnline",0) - coalesce(b."PharmaReturnOnline",0) as "PharmaSaleOnline" ,
coalesce(a."PharmaSaleCheque",0) - coalesce(b."PharmaReturnCheque",0) as "PharmaSaleCheque" ,
coalesce(a."PharmaSalePaytm",0) - coalesce(b."PharmaReturnPaytm",0) as "PharmaSalePaytm" ,
coalesce(a."PharmaSaleNotPaidTotal",0) - coalesce(b."PharmaReturnNotPaidTotal",0) as "PharmaSaleNotPaidTotal" ,
coalesce(a."PharmaSaleOtherTotal",0) - coalesce(b."PharmaReturnOtherTotal",0) as "PharmaSaleOtherTotal" ,
coalesce(a."PharmaSaleCardSwipeTotal",0) - coalesce(b."PharmaReturnCardSwipeTotal",0) as "PharmaSaleCardSwipeTotal" ,
coalesce(a."PharmaSaleCardStandAloneTotal",0) - coalesce(b."PharmaReturnCardStandAloneTotal",0) as "PharmaSaleCardStandAloneTotal" ,
coalesce(a."PharmaSaleCardUPITotal",0) - coalesce(b."PharmaReturnCardUPITotal",0) as "PharmaSaleCardUPITotal" ,
coalesce(a."PharmaSaleCardGpayTotal",0) - coalesce(b."PharmaReturnCardGpayTotal",0) as "PharmaSaleCardGpayTotal" ,
coalesce(a."PharmaSaleCashDrawerTotal",0) - coalesce(b."PharmaReturnCashDrawerTotal",0) as "PharmaSaleCashDrawerTotal" ,
coalesce(a."PharmaSaleCashDDTotal",0) - coalesce(b."PharmaReturnCashDDTotal",0) as "PharmaSaleCashDDTotal" ,
coalesce(a."PharmaSaleCashChequeTotal",0) - coalesce(b."PharmaReturnCashChequeTotal",0) as "PharmaSaleCashChequeTotal" ,
coalesce(a."PharmaSaleWalletPaytmOfflineTotal",0) - coalesce(b."PharmaReturnWalletPaytmOfflineTotal",0) as "PharmaSaleWalletPaytmOfflineTotal" ,
coalesce(a."PharmaSaleWalletPhonePeOfflineTotal",0) - coalesce(b."PharmaReturnWalletPhonePeOfflineTotal",0) as "PharmaSaleWalletPhonePeOfflineTotal" ,
coalesce(a."PharmaSaleCashRemoteDepositTotal",0) - coalesce(b."PharmaReturnCashRemoteDepositTotal",0) as "PharmaSaleCashRemoteDepositTotal" ,
coalesce(a."PharmaSaleWalletPaytmDQRTotal",0) - coalesce(b."PharmaReturnWalletPaytmDQRTotal",0) as "PharmaSaleWalletPaytmDQRTotal" ,
coalesce(a."PharmaSaleAmount",0) - coalesce(b."PharmaReturnAmount",0) as "PharmaAmount"
from PharmaSaleAmount a
left join PharmaReturnAmount b on a."AccountId"=b."AccountId"
)
select distinct a."AccountId",a."EmployeeName",a."RoleName",
pr."RegistrationCashTotal",pr."RegistrationCardTotal",pr."RegistrationUPITotal",pr."RegistrationOnlineTotal",pr."RegistrationChequeTotal",pr."RegistrationPaytmTotal",
pr. "RegistrationNotPaidTotal" ,pr. "RegistrationOtherTotal" ,pr. "RegistrationCardSwipeTotal" ,pr."RegistrationCardStandAloneTotal" ,
pr. "RegistrationCardUPITotal" ,pr."RegistrationCardGpayTotal" ,pr."RegistrationCashDrawerTotal" ,pr."RegistrationCashChequeTotal" ,
pr. "RegistrationCashDDTotal" ,pr."RegistrationWalletPaytmOfflineTotal" ,pr."RegistrationWalletPhonePeOfflineTotal" ,pr."RegistrationCashRemoteDepositTotal" ,
pr. "RegistrationWalletPaytmDQRTotal" ,
pr."registrationamount",
ap."AppointmentCashTotal",ap."AppointmentCardTotal",ap."AppointmentUPITotal",ap."AppointmentOnlineTotal",ap."AppointmentChequeTotal",ap."AppointmentPaytmTotal",
ap."AppointmentNotPaidTotal" ,ap."AppointmentOtherTotal" ,ap."AppointmentCardSwipeTotal" ,ap."AppointmentCardStandAloneTotal" ,
ap."AppointmentCardUPITotal" ,ap."AppointmentCardGpayTotal" ,ap."AppointmentCashDrawerTotal" ,ap."AppointmentCashChequeTotal" ,
ap."AppointmentCashDDTotal" ,ap."AppointmentWalletPaytmOfflineTotal" ,ap."AppointmentWalletPhonePeOfflineTotal" ,ap."AppointmentCashRemoteDepositTotal" ,
ap."AppointmentWalletPaytmDQRTotal" ,
ap."AppointmentAmount",
ad."AdmissionCashTotal",ad."AdmissionCardTotal",ad."AdmissionUPITotal",ad."AdmissionOnlineTotal",ad."AdmissionChequeTotal",ad."AdmissionPaytmTotal",
ad."AdmissionCardUPITotal" ,ad."AdmissionCardGpayTotal" ,ad."AdmissionCashDrawerTotal" ,ad."AdmissionCashChequeTotal" ,
ad."AdmissionNotPaidTotal" ,ad."AdmissionOtherTotal" ,ad."AdmissionCardSwipeTotal" ,ad."AdmissionCardStandAloneTotal" ,
ad."AdmissionCashDDTotal" ,ad."AdmissionWalletPaytmOfflineTotal" ,ad."AdmissionWalletPhonePeOfflineTotal" ,ad."AdmissionCashRemoteDepositTotal" ,
ad."AdmissionWalletPaytmDQRTotal" ,
ad."AdmissionAmount",
lb."LabCash", lb."LabCard",lb."LabUPI", lb."LabOnline",lb."LabCheque", lb."LabPaytm",
lb."LabNotPaidTotal" , lb."LabOtherTotal" , lb."LabCardSwipeTotal" , lb."LabCardStandAloneTotal" ,
lb."LabCardUPITotal" ,lb."LabCardGpayTotal" ,lb."LabCashDrawerTotal" ,lb."LabCashChequeTotal" ,
lb."LabCashDDTotal" ,lb."LabWalletPaytmOfflineTotal" ,lb."LabWalletPhonePeOfflineTotal" ,lb."LabCashRemoteDepositTotal" ,
lb."LabWalletPaytmDQRTotal"
,lb."LabAmount",
sum(pa."PharmaSaleCash") over(partition by a."AccountId") "PharmacySaleCash",
sum(pa."PharmaSaleCard") over(partition by a."AccountId") "PharmacySaleCard",
sum(pa."PharmaSaleUPI") over(partition by a."AccountId") "PharmacySaleUPI",
sum(pa."PharmaSaleOnline") over(partition by a."AccountId") "PharmacySaleOnline",
sum(pa."PharmaSaleCheque") over(partition by a."AccountId") "PharmacySaleCheque",
sum(pa."PharmaSalePaytm") over(partition by a."AccountId") "PharmacySalePaytm",
sum(pa."PharmaSaleNotPaidTotal") over(partition by a."AccountId") "PharmacySaleNotPaidTotal",
sum(pa."PharmaSaleOtherTotal") over(partition by a."AccountId") "PharmacySaleOtherTotal",
sum(pa."PharmaSaleCardSwipeTotal") over(partition by a."AccountId") "PharmacySaleCardSwipeTotal",
sum(pa."PharmaSaleCardStandAloneTotal") over(partition by a."AccountId") "PharmacySaleCardStandAloneTotal",
sum(pa."PharmaSaleCardUPITotal") over(partition by a."AccountId") "PharmacySaleCardUPITotal",
sum(pa."PharmaSaleCardGpayTotal") over(partition by a."AccountId") "PharmacySaleCardGpayTotal",
sum(pa."PharmaSaleCashDrawerTotal") over(partition by a."AccountId") "PharmacySaleCashDrawerTotal",
sum(pa."PharmaSaleCashChequeTotal") over(partition by a."AccountId") "PharmacySaleCashChequeTotal",
sum(pa."PharmaSaleCashDDTotal") over(partition by a."AccountId") "PharmacySaleCashDDTotal",
sum(pa."PharmaSaleWalletPaytmOfflineTotal") over(partition by a."AccountId") "PharmacySaleWalletPaytmOfflineTotal",
sum(pa."PharmaSaleWalletPhonePeOfflineTotal") over(partition by a."AccountId") "PharmacySaleWalletPhonePeOfflineTotal",
sum(pa."PharmaSaleCashRemoteDepositTotal") over(partition by a."AccountId") "PharmacySaleCashRemoteDepositTotal",
sum(pa."PharmaSaleWalletPaytmDQRTotal") over(partition by a."AccountId") "PharmacySaleWalletPaytmDQRTotal",
sum(pa."PharmaAmount") over(partition by a."AccountId") "PharmacyAmount",
coalesce(pr."RegistrationCashTotal",0)+coalesce(ap."AppointmentCashTotal",0)+coalesce(ad."AdmissionCashTotal",0)+coalesce(lb."LabCash",0)+coalesce(sum(pa."PharmaSaleCash") over(partition by a."AccountId") ,0) "TotalCash",
coalesce(pr."RegistrationCardTotal",0)+ coalesce(ap."AppointmentCardTotal",0)+coalesce(ad."AdmissionCardTotal",0)+coalesce(lb."LabCard",0)+coalesce(sum(pa."PharmaSaleCard") over(partition by a."AccountId"),0) "TotalCard",
coalesce(pr."RegistrationUPITotal",0)+ coalesce(ap."AppointmentUPITotal",0)+coalesce(ad."AdmissionUPITotal",0)+coalesce(lb."LabUPI",0)+coalesce(sum(pa."PharmaSaleUPI") over(partition by a."AccountId") ,0) "TotalUPI",
coalesce(pr."RegistrationOnlineTotal",0)+coalesce(ap."AppointmentOnlineTotal",0)+coalesce(ad."AdmissionOnlineTotal",0)+coalesce(lb."LabOnline",0)+coalesce(sum(pa."PharmaSaleOnline") over(partition by a."AccountId"),0) "TotalOnline",
coalesce(pr."RegistrationChequeTotal",0)+coalesce(ap."AppointmentChequeTotal",0)+ coalesce(ad."AdmissionChequeTotal",0)+coalesce(lb."LabCheque",0)+coalesce(sum(pa."PharmaSaleCheque") over(partition by a."AccountId") ,0) "TotalCheque",
coalesce(pr."RegistrationPaytmTotal",0)+coalesce(ap."AppointmentPaytmTotal",0)+ coalesce(ad."AdmissionPaytmTotal",0)+coalesce(lb."LabPaytm",0)+coalesce(sum(pa."PharmaSalePaytm") over(partition by a."AccountId"),0) "TotalPaytm",
coalesce(pr."RegistrationNotPaidTotal",0)+coalesce(ap."AppointmentPaytmTotal",0)+coalesce(ad."AdmissionNotPaidTotal",0)+coalesce(lb."LabNotPaidTotal",0)+coalesce(sum(pa."PharmaSaleNotPaidTotal") over(partition by a."AccountId"),0) "TotalNotPaid",
coalesce(pr."RegistrationOtherTotal",0)+coalesce(ap."AppointmentOtherTotal",0)+ coalesce(ad."AdmissionOtherTotal",0)+coalesce(lb."LabOtherTotal",0)+coalesce(sum(pa."PharmaSaleOtherTotal") over(partition by a."AccountId"),0) "TotalOther",
coalesce(pr."RegistrationCardSwipeTotal",0)+coalesce(ap."AppointmentCardSwipeTotal",0)+ coalesce(ad."AdmissionCardSwipeTotal",0)+coalesce(lb."LabCardSwipeTotal",0)+coalesce(sum(pa."PharmaSaleCardSwipeTotal") over(partition by a."AccountId"),0) "CardSwipeTotal",
coalesce(pr."RegistrationCardStandAloneTotal",0)+coalesce(ap."AppointmentCardStandAloneTotal",0)+coalesce(ad."AdmissionCardStandAloneTotal",0)+coalesce(lb."LabCardStandAloneTotal",0)+coalesce(sum(pa."PharmaSaleCardStandAloneTotal") over(partition by a."AccountId"),0) "CardStandAloneTotal",
coalesce(pr."RegistrationCardUPITotal",0)+coalesce(ap."AppointmentCardUPITotal",0)+coalesce(ad."AdmissionCardUPITotal",0)+coalesce(lb."LabCardUPITotal",0)+coalesce(sum(pa."PharmaSaleCardUPITotal") over(partition by a."AccountId"),0) "CardUPITotal",
coalesce(pr."RegistrationCardGpayTotal",0)+coalesce(ap."AppointmentCardGpayTotal",0)+coalesce(ad."AdmissionCardGpayTotal",0)+coalesce(lb."LabCardGpayTotal",0)+coalesce(sum(pa."PharmaSaleCardGpayTotal") over(partition by a."AccountId"),0) "CardGpayTotal",
coalesce(pr."RegistrationCashDrawerTotal",0)+coalesce(ap."AppointmentCashDrawerTotal",0)+coalesce(ad."AdmissionCashDrawerTotal",0)+coalesce(lb."LabCashDrawerTotal",0)+coalesce(sum(pa."PharmaSaleCashDrawerTotal") over(partition by a."AccountId"),0) "CashDrawerTotal",
coalesce(pr."RegistrationCashChequeTotal",0)+coalesce(ap."AppointmentCashChequeTotal",0)+coalesce(ad."AdmissionCashChequeTotal",0)+coalesce(lb."LabCashChequeTotal",0)+coalesce(sum(pa."PharmaSaleCashChequeTotal") over(partition by a."AccountId"),0) "CashChequeTotal",
coalesce(pr."RegistrationCashDDTotal",0)+coalesce(ap."AppointmentCashDDTotal",0)+coalesce(ad."AdmissionCashDDTotal",0)+coalesce(lb."LabCashDDTotal",0)+coalesce(sum(pa."PharmaSaleCashDDTotal") over(partition by a."AccountId"),0) "CashDDTotal",
coalesce(pr."RegistrationWalletPaytmOfflineTotal",0)+coalesce(ap."AppointmentWalletPaytmOfflineTotal",0)+coalesce(ad."AdmissionWalletPaytmOfflineTotal",0)+coalesce(lb."LabWalletPaytmOfflineTotal",0)+coalesce(sum(pa."PharmaSaleWalletPaytmOfflineTotal")over(partition by a."AccountId"),0) "WalletPaytmOfflineTotal",
coalesce(ap."AppointmentWalletPhonePeOfflineTotal",0)+coalesce(ap."AppointmentWalletPhonePeOfflineTotal",0)+coalesce(ad."AdmissionWalletPhonePeOfflineTotal",0)+coalesce(lb."LabWalletPhonePeOfflineTotal",0)+coalesce(sum(pa."PharmaSaleWalletPhonePeOfflineTotal") over(partition by a."AccountId"),0) "WalletPhonePeOfflineTotal",
coalesce(pr."RegistrationCashRemoteDepositTotal",0)+coalesce(ap."AppointmentCashRemoteDepositTotal",0)+ coalesce(ad."AdmissionCashRemoteDepositTotal",0)+coalesce(lb."LabCashRemoteDepositTotal",0)+coalesce(sum(pa."PharmaSaleCashRemoteDepositTotal")over(partition by a."AccountId"),0) "CashRemoteDepositTotal",
coalesce(pr."RegistrationWalletPaytmDQRTotal",0)+coalesce(ap."AppointmentWalletPaytmDQRTotal",0)+coalesce(ad."AdmissionWalletPaytmDQRTotal",0)+coalesce(lb."LabWalletPaytmDQRTotal",0)+coalesce(sum(pa."PharmaSaleWalletPaytmDQRTotal") over(partition by a."AccountId"),0) "WalletPaytmDQRTotal",
coalesce(pr."registrationamount",0)+coalesce(ap."AppointmentAmount",0)+coalesce(ad."AdmissionAmount",0)+coalesce(lb."LabAmount",0)
+coalesce(sum(pa."PharmaAmount") over(partition by a."AccountId"),0) "Total"
from accountdata a
left join patientRegistrationamount pr on pr."AccountId"=a."AccountId"
left join appointmentamount ap on ap."AccountId"=a."AccountId"
left join admissionamount ad on ad."AccountId"=a."AccountId"
left join LabAmount lb on lb."AccountId"=a."AccountId"
left join PharmaAmount pa on pa."AccountId"=a."AccountId"
;
end
$BODY$;
ALTER FUNCTION public.udf_emloyee_new_revenue(integer, integer, integer, date, date)
OWNER TO postgres;
--select * from udf_emloyee_new_revenue(6776, 2, integer, date, date)
Select * from "udf_emloyee_new_revenue"( '6776', '2', null, '2023-02-10T00:00'::Date, '2023-02-10T23:59'::Date)
ALTER TABLE "Patient"
ADD "BirthMark1" text COLLATE pg_catalog."default";
ALTER TABLE "Patient"
ADD "BirthMark2" text COLLATE pg_catalog."default";
\ No newline at end of file
CREATE TABLE public."IdProof"
(
"IdProofId" bigserial NOT NULL,
"IdProofName" character varying(255) ,
"LocationId" integer,
"Active" boolean DEFAULT true,
"CreatedBy" bigint NOT NULL,
"CreatedDate" timestamp without time zone NOT NULL,
"ModifiedBy" bigint,
"ModifiedDate" timestamp without time zone,
CONSTRAINT "IdProof_pkey" PRIMARY KEY ("IdProofId"),
CONSTRAINT "FK_IdProof_CreatedBy" FOREIGN KEY ("CreatedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "FK_IdProof_ModifiedBy" FOREIGN KEY ("ModifiedBy")
REFERENCES public."Account" ("AccountId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "IdProof_LocationId_fkey" FOREIGN KEY ("LocationId")
REFERENCES public."Location" ("LocationId") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
-------------------------------------
INSERT INTO "LogType" ("LogTypeId", "LogTypeName", "Active")
VALUES (51, 'IdProof',true);
\ No newline at end of file
INSERT INTO public."AnaesthesiaType"(
"AnaesthesiaTypeId", "Name", "Active", "CreatedBy", "CreatedDate")
VALUES (2, 'spinal',true, 938, '2023-02-22 16:45:22.221864');
\ No newline at end of file
INSERT INTO public."ReceiptAreaTypeId"(
"ReceiptAreaTypeId", "Name")
VALUES (11, 'ScanAppointmentReturn');
\ No newline at end of file
alter table "LookupValue" add column "RowColor" character varying(30);
------
alter table "ScanMachineAvailability" add column "ReferenceBreakId" integer;
alter table "ScanMachineAvailability" add column "ReferenceBlockId" integer;
alter table "ScanMachineAvailability" add CONSTRAINT "FK_ScanMachineAvailability_ReferenceBlockId" FOREIGN KEY ("ReferenceBlockId")
REFERENCES public."LookupValue" ("LookupValueId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
alter table "ScanMachineAvailability" add CONSTRAINT "FK_ScanMachineAvailability_ReferenceBreakId" FOREIGN KEY ("ReferenceBreakId")
REFERENCES public."LookupValue" ("LookupValueId") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
----
INSERT INTO public."Lookup"(
"LookupId", "Name", "Description")
VALUES (21, 'ScanAvailabilityBlock','ScanAvailabilityBlocks' );
----
INSERT INTO public."Lookup"(
"LookupId", "Name", "Description")
VALUES (20, 'ScanAvailabilityBreak','ScanAvailabilityBreaks' );
----
INSERT INTO public."LookupValue"(
"LookupId", "Name")
VALUES (21, 'Temporary Block'),
(21,'Permanant Block'),
(21,'Available'),
(21,'UnAvailable');
----
INSERT INTO public."LookupValue"(
"LookupId", "Name")
VALUES (20, 'Lunch Break'),
(20,'Coffee Break'),
(20,'Tea Break'),
(20,'Available');
------
\ No newline at end of file
create sequence "IvfEncounter_IvfEncounterId_seq";
CREATE TABLE IF NOT EXISTS public."IvfEncounter"
(
"IvfEncounterId" bigint NOT NULL DEFAULT nextval('"IvfEncounter_IvfEncounterId_seq"'::regclass),
"AppointmentId" integer,
"IvfEncounterDate" timestamp(6) without time zone NOT NULL,
"Active" boolean NOT NULL DEFAULT true,
"CreatedBy" integer NOT NULL,
"CreatedDate" timestamp(6) without time zone NOT NULL,
"ModifiedBy" integer,
"ModifiedDate" timestamp(6) without time zone,
"AdmissionId" integer,
CONSTRAINT "IvfEncounter_pkey" PRIMARY KEY ("IvfEncounterId"),
CONSTRAINT "UQ_IvfEncounter" UNIQUE ("IvfEncounterId")
);
alter table "IvfEncounter" add "GynHistory" text;
\ No newline at end of file
insert into "LogType" ("LogTypeId","LogTypeName", "Active") values (74,'Transaction', true),(75,'Receipt', true),(76,'DoctorUnit', true);
1. Keep all your development Queries into "1. QA" folder
2. Person who moved to QA run all the scripts from "1. QA" once done move those scripts to "2. Prod"
3. person who moved to prod run all the scripts from "2. Prod" once done move those scripts to "3. Complete"
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