Global Health care Database By Mauro Busso London UK
Video overview: https://youtu.be/gbu0T5bOB6w
In this, perhaps a bit ambitious, final project for CS50 SQL you can see all the code to implement and start a global health database. It will store healthcare records, including patient information, medical history, prescriptions etc.
-
What is the purpose of your database? The purpose of this database is to record patients health details all around the world in order to help understand health care trends and for research purposes.
-
Which people, places, things, etc. are you including in the scope of your database? This DB includes: Patients and their identity informations Country of residence The medical history is divided into: -visits -prescriptions -surgery -and tretments Allergies which includes all the allergiers of the patient Lifestyle in which is a general overview of how a patient conduct his life, health wise.
-
Which people, places, things, etc. are outside the scope of your database? Is not gonna include and extensive list of all the medications and diseases. Is going to assume that a patient is treated is only one country. Not going to have a database of the single clinics in every country Will not comprend a database of the physiscians
-
What should a user be able to do with your database? CRUD operations with patients Been able to standardize data across different country Been able to trace an accurate picture of the medical history of a person.
-
What's beyond the scope of what a user should be able to do with your database? It will not support specialized security features. Wont support different languages which would be important for a global scale project.
Here are the following schema for SQLite tables
The database includes the following entities:
The Patient table contains:
id, which specifies the unique ID for the patient as anINTEGER. This column has thePRIMARY KEYconstraint applied.first_name, specifies the patient's first name asTEXT, givenTEXTis appropriate for name fields.last_name, specifies the patient's last name.TEXTis used for the same reason asfirst_name.address, this specifies the address of the patient.TEXTtype is used.DOB, this is the date of birth of the patient and theDATEtype is used in this occasion.country_idthis is the id of the country the patient is resindent in, it is a foreign key that reference the country table.clinicthis cointaint the name of the clinic in which the patient is registered to.lifestyle_idthis reference the lifestyle table therefore is a foreign keyallergy_idthis is also referencing a table in this case the allergy table that contain all the possible allergies that a patient might have. This too is a foreign key.blood_typethis is a column the contain the blood type of the patient and it has been assign a type ofTEXT. It can be NULL because this info is not always available.deceasedthis will contain a value of either 1 or 0 where a 1 represent patient has passed and a 0 will mean that patient still alive. TypeINTEGER. It has also been setDEFAULTvalue of 0 and a check
Most of the fields have NOT NULL where a foreigh key or primary key constraint are not applied however few column can have a value of null where information are not available such as blood type.
The countrytable includes:
id, this is the unique id for the country and is set asINTEGER. It also Has the primary key.name, this is the name of the country and the data type isTEXTalso it can not be null soNOT NULLhas been applied.
This table rapresent a many to many relatioship and it consist of
idas in the previus tables ,this is the unique id for this table and is set asINTEGER. It also Has the primary key.patient_idwhich is the id of the patient asINTEGERand has theFOREIGN KEYwhit all constraint applied referencing theidcolumn in the patient table. Making sure each medical history belongs to a patient.surgery_idthis is the id of the surgery asINTEGERand again has theFOREIGN KEYwith all the constraints applied referencing theidcolumn in the surgery table.prescriptions_idid of the prescription asINTEGERwithFOREIGN KEYreferencing theidcolumn in the prescription table.visit_idid for the visit asINTEGERwithFOREIGN KEYreferencing theidcolumn in the visit table.treatment_idid of the tratment asINTEGERwithFOREIGN KEYreferencing theidcolumn in the prescription table.
idthis is the unique id for this table and is set asINTEGER. It also has the primary key.namename of the medication prescribed as typeTEXTbrandname of the brand as there are multiple brands selling the same medication sometimes (admitidly not supre important) type affinityTEXTstarted_onwhen the drug was started typeDATETIMErather than justDATEbecause sometime when it comes to drug administration even the hour matter.finished_onwhen the drug was finished typeDATETIMEsame reason as above.reasonthis is the reason why the drug was prescribed. TypeTEXT
idthis is the unique id for this table and is set asINTEGER. It also has the primary key.physicianname of the doctor visiting the patient typeTEXTreasonthis is the reason why the visit was scheduled typeTEXTdatewhen the visit was performedDATEnotethis are the note from the doctor typeTEXT
idthis is the unique id for this table and is set asINTEGER. It also has the primary key.physicianname of the doctor visiting the patient typeTEXTtypethis is the type of procedure had from the patient typeTEXTdatewhen the visit was performedDATEnotethis are the note from the doctor typeTEXT
idthis is the unique id for this table and is set asINTEGER. It also has the primary key.physicianname of the doctor visiting the patient typeTEXTreasonthis is the reason why the visit was scheduled typeTEXTdatewhen the visit was performedDATEnotethis are the note from the doctor typeTEXT
idthis is the unique id for this table and is set asINTEGER. It also has the primary key.patient_idwhich is the id of the patient asINTEGERand has theFOREIGN KEYwhit all constraint applied referencing theidcolumn in the patient table. Making sure each allery belongs to a patient.allergic_tothis is what the patient is allergic to it can obviusly be null as not everyone is allergic to something. typeTEXT
idunique id for this table and is set asINTEGERwith the primary key.patient_idFOREIGN KEYreferencing the id in the patient table this has typeINTEGERhow_much_smoking_per_daythis is the number of cigaret smoked in one day and it is set to beREALnumber to include floating numbers.how_much_drinking_per_weekthis is how much unit of alchol the patient drink in one week and it is set to beREALnumber to include floating numbers.how_much_excercise_per_week_in_hthis is the ammount of hours the patient spen excercising of doing physical activity in one week and again it is set to beREALnumber to include floating numbers.jobthis is the job of the patient of typeTEXT
In this section, you should include your entity-relationship diagram and describe the relationships between the entities in your database.
As shown in the diagram
- A patient can have one and only one country of origin, and a country can have 0 or many patients.
- A patient can have one and only one lifestyle; however, a lifestyle can have multiple patients, as a lifestyle can be shared among multiple patients.
- Patients can have multiple allergies, and allergies can be present in multiple people or not present at all. So in both directions, there is a zero-to-many relationship.
- In the case of medical history, a patient can have one and only one medical history comprising multiple health interventions, and multiple patients can share, even if rarely, the same medical history.
- For the last four tables, surgery, prescription, visit, and treatment, the medical history table can have zero or more for each of these tables, and the same is true in the opposite direction: a surgery, prescription, visit, or treatment can be in multiple patient medical histories. Although if a medical history doesn't have any of the above, it is not really a medical history at all.
- Which optimizations (e.g., indexes, views) did you create? Why?
Some of the typical query that can be run are, looking if a patient is allergic to something. So an index with patient_id in the allergy teble has been created.
Similarly looking for a patient by country or looking for all patient who are not deceased. Therefore indexes on the country table on the id column and on the patient table deceased column have been created.
One common query could be to find the most recent medical intervention by date or by physician name, therefore indexes on the date and physician columns have been made in the treatment, surgery, visit and prescription tables.
One index on medical_history table was made to speed the retrival of the medical history by patient_id.
Regarding views
One has been created to show all the prescription that a patient is currently on. Using a JOIN statement to unite medical_history and prescription on the patient table. But selecting only medication where finished_on IS NULL.
Another one has been crteated to check the name and what are they allergic to using JOIN on the patient table.
One was created to quickly retrieve and display the first_name and last_name of a patient and their country.
A view was created to see a list of lifestyle informations using JOIN on lifestyle to patient table
The last table was made to create a view of all the medical interventions ordered by date and JOIN was used to unite the surgery, visit, treatment and prescription table dates on to the patient table. This will help to organize and track data.
What are the limitations of your design?, What might your database not be able to represent very well?
- This database desgin assume the health care in the country is free.
- To make this database more comprehensive, additional tables could be considered. These might include a table for all the clinics in a country and a table listing all the physicians registered in a country.
- Currently, the database assumes that a patient will always be treated in one country.
- For a more practical real-world application, it might be necessary to include table translations.
- This database does not contain soft deletion system (which it could be beneficial with the appropriate security measures)
- Additionally, the lifestyle data may not always be reliable.
- Most importantly patient details are not anonymized.
