Advertisement
Guest User

Untitled

a guest
Mar 12th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.07 KB | None | 0 0
  1. #Table creation syntax for all tables
  2. Create table Reception(
  3. ReceptionId int not null auto_increment primary key ,
  4. AdmissionsId int null,
  5. Shift bit,
  6. HourlyQueSize int,
  7. EntryTime time
  8. );
  9. Create table Admissions(
  10. AdmissionsId int not null auto_increment primary key,
  11. PatientId int null,
  12. ReceptionId int null,
  13. AdmissionTime time,
  14. Patient_Condition nvarchar(100),
  15. ReleaseTime datetime
  16. );
  17. Create table Patient(
  18. PatientId int not null auto_increment primary key,
  19. AdmissionsId int null,
  20. DoctorId int null,
  21. sex bit,
  22. fName nvarchar(15),
  23. lName nvarchar(15),
  24. Age int,
  25. Illness nvarchar(50),
  26. Symptoms nvarchar(150),
  27. Comments nvarchar (200),
  28. Email nvarchar(25),
  29. PhoneNumber int,
  30. Address nvarchar(75)
  31. );
  32. Create table Doctor(
  33. DoctorId int not null auto_increment PRIMARY KEY,
  34. PatientId int null,
  35. StaffId int null,
  36. PagerNumber int not null,
  37. PhoneNumber int,
  38. Email nvarchar(25),
  39. Possition nvarchar(25),
  40. Spesialism nvarchar(25)
  41. );
  42. Create table Nurse(
  43. NurseId int not null auto_increment primary key,
  44. DoctorId int null,
  45. WardId int null,
  46. StaffId int null,
  47. Sex bit,
  48. Age Date,
  49. Qualification nvarchar (25),
  50. NurseSpeciality nvarchar(25)
  51. );
  52. Create table Xray(
  53. XrayId int not null auto_increment primary key,
  54. PatientId int,
  55. DoctorId int,
  56. Result nvarchar(50),
  57. XrayArea nvarchar (25),
  58. XrayTime DateTime
  59. );
  60. Create TABLE BloodTest(
  61. BloodId int not null auto_increment primary key,
  62. PatientId int null,
  63. DoctorId int null,
  64. BloodType nvarchar(15),
  65. Comment_Blood nvarchar(150),
  66. Results nvarchar(100),
  67. Test_Time int
  68. );
  69. Create table MRI(
  70. MRI_ID INT NOT NULL auto_increment PRIMARY KEY,
  71. PatientId int null,
  72. DoctorId int null,
  73. Result nvarchar(100),
  74. MRI_Time int
  75. );
  76. Create table Beds(
  77. BedId int not null auto_increment primary key,
  78. PatientId int null,
  79. WaitingTime int,
  80. BedOccupied bit
  81. );
  82. Create table Ward(
  83. wardId int not null auto_increment primary key,
  84. bedId int null,
  85. No_Beds int,
  86. wardType nvarchar(50),
  87. NurseId int null
  88. );
  89. Create table Staff(
  90. StaffId int not null auto_increment primary key,
  91. fName nvarchar(25),
  92. lName nvarchar(25),
  93. Age int,
  94. Sex bit,
  95. pps nvarchar(10),
  96. ssn nvarchar(15),
  97. Qualification nvarchar(100),
  98. Salary int,
  99. Contract int,
  100. IsOnCall bit
  101. );
  102. Create table Spesialist(
  103. SpesialistId int not null auto_increment primary key,
  104. StaffId int null,
  105. Spesiality nvarchar(50),
  106. Possition nvarchar(40),
  107. Availability nvarchar(25)
  108. );
  109. Create table Medication(
  110. MedicationId int not null auto_increment primary key ,
  111. Quantity int not null,
  112. Medication_Type nvarchar(50),
  113. SideEffects nvarchar(50),
  114. DoctorId int null
  115. );
  116. Create table Treatment(
  117. TreatmentId int not null auto_increment primary key,
  118. MedicationId int null,
  119. TreatmentType nvarchar(50),
  120. Duration nvarchar(25)
  121. );
  122. Create table Patient_Medical(
  123. Patient_MedicalId int not null auto_increment primary key,
  124. PatientId int null,
  125. illness nvarchar(50),
  126. seenToBy nvarchar(50),
  127. DoctorId int null,
  128. Recomendation nvarchar(150),
  129. TreatmentId int null,
  130. MedicationId int null
  131. );
  132. Create table Patient_Insurance(
  133. Patient_InsuranceId int not null auto_increment primary key,
  134. PatientId int null,
  135. InsuranceNo int,
  136. InsuranceDetails nvarchar(150),
  137. paymentType nvarchar(25),
  138. patientCost int
  139. );
  140. Create table Visitor(
  141.  
  142. VistitorId int not null auto_increment primary key,
  143. PatientId int null,
  144. Length_Stayed nvarchar(50),
  145. fName nvarchar(15),
  146. lName nvarchar(15),
  147. Address nvarchar(40)
  148. );
  149. #Alter table commands to add foreign keys in
  150. Alter table reception
  151. add foreign key (AdmissionsId)
  152. references Admissions(AdmissionsId);
  153.  
  154. Alter table Admissions
  155. add foreign key (PatientId)
  156. references Patient(PatientId);
  157.  
  158. alter table admissions
  159. add foreign key (ReceptionId)
  160. references reception(ReceptionId);
  161.  
  162. alter table patient
  163. add foreign key(AdmissionsId)
  164. references admissions(AdmissionsId);
  165. alter table patient
  166. add foreign key(DoctorId)
  167. references Doctor(DoctorId);
  168.  
  169. alter table Doctor
  170. add foreign key(PatientId)
  171. references Patient(PatientId);
  172. alter table Doctor
  173. add foreign key(StaffId)
  174. references Staff(StaffId);
  175.  
  176. alter table nurse
  177. add foreign key(DoctorId)
  178. references Doctor(DoctorId);
  179. alter table nurse
  180. add foreign key(wardId)
  181. references Ward(wardId);
  182. alter table nurse
  183. add foreign key(StaffId)
  184. references Staff (StaffId);
  185.  
  186. alter table Xray
  187. add foreign key (PatientId)
  188. references Patient(PatientId);
  189. alter table Xray
  190. add foreign key (DoctorId)
  191. references Doctor(DoctorId);
  192.  
  193. alter table bloodtest
  194. add foreign key(PatientId)
  195. references Patient(PatientId);
  196. alter table bloodtest
  197. add foreign key(DoctorId)
  198. references Doctor(DoctorId);
  199.  
  200. alter table mri
  201. add foreign key(PatientId)
  202. references Patient(PatientId);
  203. alter table mri
  204. add foreign key (DoctorId)
  205. references Doctor(DoctorId);
  206.  
  207. alter table beds
  208. ADD foreign key (PatientId)
  209. references Patient(PatientId);
  210.  
  211. alter table Ward
  212. add foreign key(BedId)
  213. references Beds(BedId);
  214.  
  215. alter table Spesialist
  216. add foreign key(StaffId)
  217. references Staff(StaffId);
  218.  
  219. Alter table Medication
  220. add foreign key(DoctorId)
  221. references doctor(DoctorId);
  222.  
  223. alter table Treatment
  224. add foreign key (MedicationId)
  225. references medication(MedicationId);
  226.  
  227. alter table patient_medical
  228. add foreign key (PatientId)
  229. references Patient(PatientId);
  230.  
  231. alter table patient_medical
  232. add foreign key (MedicationId)
  233. references Medication(MedicationId);
  234.  
  235. alter table patient_insurance
  236. add foreign key (PatientId)
  237. references Patient(PatientId);
  238.  
  239. alter table visitor
  240. add foreign key (PatientId)
  241. references Patient(PatientId);
  242.  
  243. #Inserting data into tables
  244. SELECT * FROM STAFF;
  245.  
  246. insert into staff (StaffId, fName, lName, Age, Sex, pps, ssn, Qualification, Salary, Contract, IsOnCall)
  247. values
  248. (null,'John','Carroll',41, 'M', '283739V' ,NULL,'Trinity', 120000, 'Full time', 1),
  249. (null,'Paul','Carey' ,32, 'M', '237281V', NULL,'Harvard', 160000, 'Full time', 1),
  250. (null,'Mary','Murphy' ,48, 'F', '564759V', NULL,'St James', 42000, 'Full time', 0),
  251. (null,'Michael','Burn',52, 'M', '243842V', NULL,'University College Dublin', 100000, 'Full time', 0),
  252. (null,'John','Murphy',51, 'M', '298695V', NULL,'University College Dublin', 102340, 'Full time', 0),
  253. (null,'Paula','O,Neill',53, 'F', '182739V',NULL,'St James', 48000, 'Part time', 1);
  254.  
  255.  
  256.  
  257.  
  258. Insert into Nurse(NurseId, DoctorId, WardId, StaffId, Sex, Age, Qualification, NurseSpeciality)
  259. values
  260. (null, 5, 1, 3, 'F', 48, 'St James' , 'General'),
  261. (null, 6, 2, 4, 'F', 53,'St James', 'General');
  262.  
  263. select * from doctor;
  264. select * from staff;
  265. select * from nurse;
  266. select * from spesialist;
  267. set foreign_key_checks = 0;
  268. set foreign_key_checks = 1;
  269.  
  270. Insert into Doctor(DoctorId, PatientId, StaffId, PagerNumber, PhoneNumber, Email, Possition, Spesialism)
  271. values
  272. (null, 1, 1, 19283, 0857463722, 'JohnCarroll@gmail.com', 'Full time', 'Cardiac' ),
  273. (null, 2, 2, 12329, 0867364222, 'PCarey@Hotmail.com', 'Full Time','General');
  274. Insert into spesialist(SpesialistId, StaffId, Spesiality, Possition, Availability)
  275. values
  276. (null,4,'Eye and Ear', 'Full time', '4 week waiting list'),
  277. (null, 5, 'Spineoligist', 'Full time', '5 month waiting list');
  278.  
  279. alter table patient modify column sex nvarchar(1);
  280. insert into Patient(PatientId, AdmissionsId,DoctorId,Sex,fname, lname,Age, illness,symptoms, Comments,Email, PhoneNumber, address)
  281. values
  282. (null,1,2, 'F', 'Mary', 'Connely', 53, 'High blood pressure', 'Restless', 'Needs new treatment', 'mconally@gmail.com', 0856271662,'12 Briot Grove, Waterford' ),
  283. (null,2, 1 , 'M', 'John', 'Purcell', 42, 'knee pain', 'Cant bend knee', 'Needs surgery', 'jPurcell@hotmail.com', 0878273661,'13 Bullock park, Carlow'),
  284. (null, 3, 1, 'M', 'Michael', 'Kearney', 34, 'Sharp stomac pain', 'Cant keep food down', 'High dose of Anti-biotics', 'kearny132@gmail.com',0892633998, 'Kileshin road Carlow');
  285.  
  286. insert into Patient_medical(Patient_MedicalId, PatientId, illness,seenToBy,DoctorId,Recomendation,TreatmentId, MedicationId)
  287. values
  288. (null, 1, 'High blood pressure', 'Dr Carey', 2, 'New treatment plan needed', 1,1),
  289. (null, 2, 'Knee pain', 'Dr Carroll', 1, 'Needs key hole surgery', 2,2),
  290. (null, 3, 'Sharp stomac pain', 'Dr Carey', 2, 'Neutralising diet', 3,3);
  291.  
  292. insert into patient_insurance(patient_insuranceId, PatientId, InsuranceNo, InsuranceDetails,PaymentType, PatientCost)
  293. values
  294. (null, 1, 23726199, 'No health care', 'Credit card', 600),
  295. (null, 2, 27368839, 'Laya Health care', 'Bank Transfer', 15000 ),
  296. (null, 3, 23771622, 'Medcial Card Cover', 'Goverment Payment' ,5000);
  297.  
  298. insert into medication(medicationId, Quantity, Medication_Type, SideEffects, DoctorId)
  299. values
  300. (null, 3, 'High dose of h3hh7', 'May cause headaches', 2),
  301. (null, 2, 'Strong pain killers', 'Can be addictive if abused', 1 ),
  302. (null, 5, 'Neutralising tablets', 'May cause nausia', 2);
  303.  
  304. insert into Treatment(TreatmentId, medicationId, TreatmentType, Duration)
  305. values
  306. (null,1,'New schedule of medication', '6-8 weeks'),
  307. (null, 2, 'Surgery needed', '5-6 hours'),
  308. (null, 3, 'Neutralisation', '1-2 weeks');
  309. ALTER TABLE RECEPTION MODIFY COLUMN SHIFT NVARCHAR(5);
  310. insert into reception(ReceptionId, AdmissionsId,Shift, HourlyQueSize, EntryTime)
  311. values(NULL, 1, 'Day',4, 16.00),
  312. (null, 2, 'Night', 2, 02.30),
  313. (null, 3, 'Day', 8, 19.26);
  314. alter table admissions modify column ReleaseTime time;
  315. insert into Admissions(AdmissionsId, PatientId,ReceptionId, AdmissionTime,Patient_Condition,ReleaseTime)
  316. values(null,1,1,16.30,'Restless', 15.43),
  317. (null, 2, 2, 02.40, 'Cant bend knee', 13.20),
  318. (null, 3, 3,20.12,'Sharp pain', 22.16);
  319.  
  320. insert into visitor(VistitorId, PatientId,Length_Stayed, fname, lname, Address)
  321. values
  322. (null, 1, '20 minutes', 'Hannah', 'Dunne', 'Cois Na Coill, Waterford'),
  323. (null, 2 , '1 hour 20 minutes', 'Rebecca', 'Burke', 'Cannons Quarter, Tullow'),
  324. (null, 1, '22 Minutes', 'Alan', 'Carroll', '12 Bullock Park, Carlow'),
  325. (null, 3, '1 Hour 2 minutes', 'John', 'Moran', 'Old Dublin road, Carlow');
  326. select * from admissions;
  327. select * from reception;
  328.  
  329.  
  330. set foreign_key_checks = 0;
  331. select * from Xray;
  332.  
  333. select * from Mri;
  334.  
  335.  
  336.  
  337.  
  338. select s.fname, s.lname, sp.possition
  339. from staff s
  340. inner join spesialist sp on s.StaffId = sp.staffid;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement