Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.98 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. create database VHR
  10. go
  11. use VHR
  12. go
  13.  
  14. create table Patient(
  15. IdPatient char(18) not null unique,
  16. sex char(1) not null,
  17. birthdate date not null,
  18. fname varchar(20) not null,
  19. lname varchar(20) not null,
  20. bloodType varchar(3) not null,
  21. email varchar(30) not null,
  22. telefono varchar(15)
  23. Primary Key (IdPatient),
  24. );
  25.  
  26. create table Allergies(
  27. IdAllergie int IDENTITY(1,1) not null unique,
  28. name varchar(20) not null,
  29. IdPatient char(18)
  30. Primary Key (IdAllergie)
  31. Foreign Key (IdPatient) references Patient(IdPatient)
  32. );
  33.  
  34. create table Doctor(
  35. cedulaProfesional char(7) not null unique,
  36. fname varchar(20) not null,
  37. lname varchar(20) not null,
  38. sex char(1) not null,
  39. speciality varchar(20) null,
  40. Primary Key (cedulaProfesional)
  41. );
  42.  
  43. create table DoctorVisit(
  44. IdDoctorVisit int IDENTITY(1,1) not null unique,
  45. cedulaProfesional char(7) null,
  46. IdPatient char(18) null,
  47. visitDate date not null,
  48. comments text null,
  49. temp int not null,
  50. height decimal(5,2) not null,
  51. weight decimal(5,2) not null,
  52. bloodPressure int not null,
  53. Primary Key (IdDoctorVisit),
  54. Foreign Key (cedulaProfesional) references Doctor(cedulaProfesional),
  55. Foreign Key (IdPatient) references Patient(IdPatient),
  56. );
  57.  
  58. create table Prescription(
  59. IdPrescription int IDENTITY(1,1) not null unique,
  60. IdDoctorVisit int null,
  61. prescriptionDate date not null,
  62. Primary Key (IdPrescription),
  63. Foreign Key (IdDoctorVisit) references DoctorVisit(IdDoctorVisit)
  64. );
  65.  
  66. create table DrugCatalog(
  67. IdDrugCatalog int IDENTITY(1,1) not null unique,
  68. genericName varchar(30) not null,
  69. comments text null,
  70. sideEffects varchar(255) null,
  71. Primary Key (IdDrugCatalog)
  72. );
  73.  
  74. create table PrescriptionDetails(
  75. IdPrescription int not null,
  76. IdDrugCatalog int not null,
  77. instructions text not null,
  78. startDate Date not null,
  79. endDate Date not null,
  80. Foreign Key (IdPrescription) references Prescription (IdPrescription),
  81. Foreign Key (IdDrugCatalog) references DrugCatalog (IdDrugCatalog),
  82. constraint PK_PrescriptionDetails primary key (IdPrescription,IdDrugCatalog)
  83. );
  84.  
  85. create table LabTestCatalog(
  86. IdLabTestCatalog int IDENTITY(1,1) not null unique,
  87. name varchar(30) not null,
  88. Primary Key (name)
  89. );
  90.  
  91. create table LabTest(
  92. IdLabTest int IDENTITY(1,1) not null unique,
  93. labDate date not null,
  94. IdLabTestCatalog int null,
  95. IdPatient char(18) null,
  96. Primary Key(IdLabTest),
  97. Foreign Key(IdLabTestCatalog) references LabTestCatalog(IdLabTestCatalog),
  98. Foreign Key(IdPatient) references Patient(IdPatient),
  99. );
  100.  
  101. create table LabTestIndicatorCatalog(
  102. IdLabTestIndicatorCatalog int IDENTITY(1,1) not null unique,
  103. indicator varchar(20) null,
  104. minLTIC decimal(5,2) not null,
  105. maxLTIC decimal(5,2) not null,
  106. Primary key(IdLabTestIndicatorCatalog)
  107. );
  108.  
  109. create table LabTestResults(
  110. IdLabTestResults int IDENTITY(1,1) not null unique,
  111. value decimal(5,2) null,
  112. isAnormal bit not null,
  113. comment text null,
  114. IdLabTest int null,
  115. IdLabTestIndicatorCatalog int null,
  116. Primary Key(IdLabTestResults),
  117. Foreign Key(IdLabTest) references LabTest(IdLabTest),
  118. Foreign Key(IdLabTestIndicatorCatalog) references LabTestIndicatorCatalog(IdLabTestIndicatorCatalog)
  119. );
  120.  
  121.  
  122.  
  123. INSERT INTO Patient VALUES ('PEBA940625HNLXRD05', 'M', '1994-06-25', 'Adrian', 'Peña', 'O+', 'adrianpena_94@hotmail.com', '83565991')
  124.  
  125. INSERT INTO Patient VALUES ('GASJ971105HHGRNN06', 'M', '1997-11-05', 'Juan', 'García', 'O+', 'juanpablo@hotmail.com', '535345')
  126.  
  127. INSERT INTO Patient VALUES ('OOGB960601HNLRRR06', 'M', '1996-06-01', 'Bernardo', 'Orozco', 'O+', 'berny.orozco@hotmail.com', '4232343')
  128.  
  129. INSERT INTO Patient VALUES ('LOMS950423HNEPDR01', 'M', '1995-04-23', 'Sergio', 'López', 'O+', 'sergio@hotmail.com', '322123432')
  130.  
  131. INSERT INTO Allergies VALUES ('Pimientos', 'LOMS950423HNEPDR01')
  132.  
  133. INSERT INTO Allergies VALUES ('Penicilina', 'OOGB960601HNLRRR06')
  134.  
  135. INSERT INTO Allergies VALUES ('Cacahuate', 'PEBA940625HNLXRD05')
  136.  
  137. INSERT INTO Allergies VALUES ('Cacahuate', 'LOMS950423HNEPDR01')
  138.  
  139. INSERT INTO Allergies VALUES ('Picaduras de insecto', 'GASJ971105HHGRNN06')
  140.  
  141. INSERT INTO Doctor VALUES ('3273546','Miguel Angel', 'Zapata Martinez', 'M', 'cirugia general')
  142.  
  143. INSERT INTO Doctor VALUES ('0026363','Luisa Irene', 'Salinas Pulido', 'F', 'Ginecologia')
  144.  
  145. INSERT INTO Doctor VALUES ('3816929','Gerardo', 'Gonzales Trevino', 'M', 'cirugia general')
  146.  
  147. INSERT INTO Doctor VALUES ('5040228','Eduardo', 'Plancarte Lozano', 'M', 'Ginecologia')
  148.  
  149. INSERT INTO Doctor VALUES ('3861864','Cynthia Marisol', 'Rodríguez Treviño', 'F', 'Cirujano partero')
  150.  
  151. INSERT INTO DrugCatalog VALUES ('ACIDO ACETILSALICILICO','muy recomendado','Prolongacion del tiempo de sangrado, tinnitus, perdida de la audicion, nausea, vomito')
  152.  
  153. INSERT INTO DrugCatalog VALUES ('IBUPROFENO','tomar 3 cada semana como maximo','Epigastralgias, nauseas, mareos, pirosis, sensacion de plenitud en tracto gastrointestinal')
  154.  
  155. INSERT INTO DrugCatalog VALUES ('PARACETAMOL','no tomar todo los dias solo cuando hay dolor','Reacciones de hipersensibilidad: erupcion cutanea, neutropenia, pancitopenia')
  156.  
  157. INSERT INTO DrugCatalog VALUES ('TRAMADOL','no usar tan seguido','Nausea, mareos, bochornos, taquicardia, hipotension arteria')
  158.  
  159. INSERT INTO DrugCatalog VALUES ('FENTANILO','no recetar a embarazadas','Depresion respiratoria, vomito, rigidez muscular, euforia, broncoconstriccion')
  160.  
  161. INSERT INTO DrugCatalog VALUES ('METFORMINA','no comer antes de la comida si no provoca vomito','Diarrea, nausea, dispepsia, flatulencia, vomito, cefalea, hipoglucemia.')
  162.  
  163. INSERT INTO DrugCatalog VALUES ('METADONA','solo si tienen mucho dolor','Mareo, sedacion, nauseas y vomitos. Otros incluyen confusion mental, somnolencia, letargia')
  164.  
  165. INSERT INTO DrugCatalog VALUES ('BUPRENORFINA','comprar generico ya que es mas varato','Sedacion, mareo, cefalea, miosis, nausea, sudoracion y depresion respiratoria')
  166.  
  167. INSERT INTO DrugCatalog VALUES ('NIFEDIPINO','dificil de conseguir','Nausea, mareo, cefalea, rubor, hipotension arterial, estrenimiento y edema.')
  168.  
  169. INSERT INTO DrugCatalog VALUES ('ADENOSINA','minimo 4 tabletas por 2 dias','Disnea, enrojecimiento facial, dolor toracico, hipotension, nausea, ansiedad.')
  170.  
  171. INSERT INTO DoctorVisit VALUES ('3273546','OOGB960601HNLRRR06','2016-07-12','apendicitis',36,77.00,61.00,86)
  172.  
  173. INSERT INTO DoctorVisit VALUES ('3273546','OOGB960601HNLRRR06','2016-07-28','dado de alta de operacion de apendicitis',37,77.00,60.70,75)
  174.  
  175.  
  176. --top 5 allergies
  177. select top(5) name, count(name)
  178. from Allergies
  179. group by (name)
  180. order by count(name) desc
  181.  
  182. --how many patient a doctor has
  183. select d.fname, d.lname, count(DISTINCT p.IdPatient)
  184. from Doctor d join DoctorVisit dv on d.cedulaProfesional=dv.cedulaProfesional
  185. join Patient p on dv.IdPatient = p.IdPatient
  186. group by d.fname, d.lname
  187. order by d.fname
  188.  
  189. --get previous appointments of a pattient
  190. select dv.visitDate, d.fname, d.lname,dv.temp, dv.weight, dv.height, dv.bloodPressure
  191. from Doctor d join DoctorVisit dv on d.cedulaProfesional=dv.cedulaProfesional
  192. join Patient p on dv.IdPatient = p.IdPatient
  193. where p.IdPatient = (select IdPatient from Patient where fname='Bernardo' and lname='Orozco' and birthdate='1996-06-01')
  194.  
  195. --create prescription (template params: date, doctor name, patient name, name of drug)
  196. INSERT INTO Prescription VALUES ((select IdDoctorVisit
  197. from DoctorVisit
  198. where visitDate='2016-07-12'
  199. and cedulaProfesional=(select cedulaProfesional from Doctor where fname='Miguel Angel' and lname='Zapata Martinez')
  200. and IdPatient=(select IdPatient from Patient where fname='Bernardo' and lname='Orozco' and birthdate='1996-06-01')),
  201. '2016-07-12')
  202.  
  203. INSERT INTO PrescriptionDetails VALUES ((select IdPrescription from Prescription
  204. where prescriptionDate='2016-07-12'
  205. and IdDoctorVisit=(select IdDoctorVisit from DoctorVisit
  206. where visitDate='2016-07-12'
  207. and cedulaProfesional=(select cedulaProfesional from Doctor where fname='Miguel Angel' and lname='Zapata Martinez')
  208. and IdPatient=(select IdPatient from Patient where fname='Bernardo' and lname='Orozco' and birthdate='1996-06-01'))),
  209. (select IdDrugCatalog from DrugCatalog where genericName='name of drug'),
  210. 'instructions',
  211. '2016-07-12',
  212. 'enddate')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement