My final project for Harvard's CS50P - Introduction to Programming with Python.
๐น Youtube:
https://www.youtube.com/watch?v=Mxe5N0RC8K4
This is a patient registration system, the database of which is a CSV file. The idea of this program is to model the CRUD
acronym: create
, read
, update
, and delete
from a database.
The program imports: sys
, csv
, and the emoji
library and runs on Python3
.
The program contains 5 functions outside of Main().
- (1) Register patient
- (2) Search patient
- (3) Match blood-type
- (4) Update prognosis
- (5) Delete patient
is a choice menu which takes user input in the range of 1-5 and passes in a function dependent on user choice. If an incorrect integer or string is entered, main will reprompt the user for correct input. However, "Q"
, will exit the program via sys.exit
.
via list of dictionaries, takes user input for keys ["name", "blood-type", "location", "prognosis"]
. 'Name' uses .strip()
and .capitalize()
methods. 'Blood-type' prompts for a correct blood-type and uses the emoji library to add a vampire ๐งโโ๏ธ to the associated blood-type. 'Location' gives the user 3 choices to choose: primary care
, surgery
, or discharged
, and uses the emoji library to add a thermometer ๐ก
, clock ๐
or person surfing ๐โโ๏ธ
to the associated location. 'Prognosis' gives the user 3 choices to choose: good ๐
, poor ๐ค
, critical ๐ค
, and uses the emoji library to add a face with sunglasses, a thermometer, or bandages to the associated prognosis. Lastly, once all input has been received, the program opens a DictWriter and writes the input to the local CSV file and prints user input confirmation.
takes user input for key 'name', opens DictReader to iterate over the CSV file and returns a printed match with the associated input value 'name', or 'no match found' if none was found.
takes user input for key 'blood-type' within ["A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-"]
, uses the emoji library to add an emoji vampire ๐งโ
, then opens DictReader to iterate over the CSV file and returns all matches with the associated input value 'blood-type', or 'no match found' if no matches were found.
takes user input for key 'name', opens DictReader to iterate over the CSV file and find the input. If the input matches a name within the CSV file, the program will prompt the user the 3 choices to choose from: good ๐
, poor ๐ค
, and critical ๐ค
, to update the prognosis. Per user input, the program index's into the key's position and updates the value via csv.writer. If no match is found in the file, the program prints 'no match found' and returns to the choice menu.
takes user input for key 'name', opens DictReader to iterate over the CSV file and find the input. If the input matches a name within the CSV file, the program will prompt the user to confirm deletion via "Y/N". If the user confirms "Y", the program index's into the row and writes a new list without the input row deleting it from the CSV file.
Given more time I would improve the program: I believe the design would be better served creating 'patient' as a class object for its inheritence properties. As I learned more about CSV files, I learned updating and writing to an existing file may not be the best database; I would use a more interactive database like SQL
, MongoDB
, or Mongoose
to store the data. Additionally, I would specify 'name' input using REGEX
or regular expressions, add a patient 'IN'
and 'OUT'
function using 'datetime'
, and add a random
four digit patient ID number to each patient for flexibility with search criteria.
Overall, I'm happy ๐ with what I've built, the program covers corner cases, achieves what I intended, and provides an excellent, easy to follow user experience.