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;