CS 1026 B, Winter 2023 Assignment 3 – Creating an Information System for Electronic Medical Records
1) Background
In Canada, we are seeing the need to improve the healthcare system. What many people don’t realise is that our healthcare system still makes use of very primitive information systems like excel sheets, fax machines, and even paper written records. There is a ton of room for improvements that we as Computer Scientists can make.
Image: Health Tech and Interface For example, Electronic Medical Records (EMRs) are becoming increasingly important in the healthcare industry, providing a way for doctors and other healthcare professionals to access a patient's medical history, diagnosis, and treatment plans all in one place. By automating the process of collecting, storing, and analyzing patient data, EMRs help to improve the quality of care, reduce errors, and increase patient safety.
Assignment Intro Video
This video is required to watch as it summarises the assignment.
Brief Video to Introduce the Assignment
Context of Assignment and Future Applications
The following video provides some context on the benefit and impacts of design of software used in hospitals. This video is optional, but recommended to understand the issues in health information systems.
Electronic Health Records: Usability and Unintended Safety Issues
Context Video: Issues with Health Information Systems
Scope and Context
In this programming assignment, you will be creating a Health Information System that uses biomedical signals to produce an electronic medical record for each patient. The system will read patient data from a plain-text file that is separated by commas, allowing new patient information to be added through user input to update the plain-text file..
In programming, the term "backend" refers to the part of a software system or application that is responsible for handling data processing, and other functionality that is not directly visible to the user. This includes database management, and other aspects of a system that do not involve the user interface (UI). The backend is typically responsible for processing requests and delivering data to the frontend (user-facing part of the software) for display to the user. It is often designed to be scalable, flexible, and able to handle large volumes of data efficiently.
Though we will not be focusing on User-Interface design (UXD) in this assignment, your work in this assignment will provide a possible core information system “backend” to help improve a healthcare system.
Assignment Walk-Through Video by Prof
(Required) CS 1026 Assignment 3 Intro
Thank you for your help in improving the healthcare system!
2) Program Features
The program will provide the following features, plus more as described in the function sections below: A function to read patient data from a plaintext file. A function to display various statistics about the patients, such as the average vital signs about the patients or for a specific patient. A function to display patient data for all patients or for a specific patient by ID. A function to add new patient data to the patient list. A function to find patient visits in a certain month or year A function to find patients who need follow-ups depending on their vital statistics A text-based interface to list the patients and allow the user to select which feature they would like to use.
3) Dataset
We will use a text file containing data from patient visits in a file, called “patients.txt”. The file contains one line for every unique visit by any patient to the clinic. Note that it is possible that each patient may visit the clinic multiple times. The file has the following columns, with each data element being separated with a comma and each new record on a new line.
The data in the file will look like the following:
1,2022-06-01,37.2,72,16,120,80,97
1,2022-09-15,37.5,73,18,125,82,96
2,2022-06-10,36.9,69,18,123,80,96
2,2023-01-03,37.1,71,19,124,81,97
3,2022-08-05,37.3,74,20,126,83,95
3,2023-03-01,37.4,75,18,123,79,98
This data will be structured with the delimiter being a comma, and the types of information as follows: Patient ID Integer Date of visit (YYYY-MM-DD) String Body temperature (Celsius) Float Heart rate (beats per minute) Integer Respiratory rate (breaths per minute) Integer Systolic blood pressure (mmHg) Integer Diastolic blood pressure (mmHg) Integer Oxygen saturation (%) Integer
A full sample dataset is available online with the .txt extension. For testing purposes, you are strongly encouraged to create your own datasets following the above convention to test your code more thoroughly.
4) File to Hand In and Provided
Files You are provided a sample main.py file with indications where you’ll put your own implementation. You will submit one file – named “main.py” to Gradescope. Please do not modify the main function in this file.
Links to Provided Files:
main.py (https://1drv.ms/u/s!As0vrM-NsbcQkpYwuuCIP0JbvqxyJQ?e=eAK5SM) This file contains the definitions of the functions you will write, as well as the main program the creates the interface. You will write code to implement these functions as per the specifications at the location indicated by a comment "#Put your code here". patients.txt (https://1drv.ms/t/s!As0vrM-NsbcQkpYvHATJ4v-zz3CIcA?e=LSHQJi) This is one sample dataset containing visits of patients and their medical data. You can use this for testing. We encourage you to modify it and test with different data.
5) Learning Outcomes and Skills Used
Using functions: Consider the use of functions to break down the tasks into smaller, more manageable parts. E.g., implement functions for reading patient data from a file, displaying patient data, adding new patient data, and calculating patient statistics.
Complex data structures: Use complex data structures, such as dictionaries and lists, to store and manipulate patient data.
Text processing: We will use text processing to read and write patient data to and from a text file.
File input and output: We will implement functions to read and write patient data to a text file.
Exceptions in Python: Consider handling exceptions in our code. For example, consider how to handle cases where the data in the text file is not in the correct format, or has an extra blank line at the end.
Using Python modules: We should use Python modules as applicable, to make the code more efficient and readable.
Adhering to specifications by testing programs and developing test cases: Remember to adhere to the specifications given and test the programs using test cases.
6) View of Information System
Interface you will Create
Sample View from User's Perspective
7) General Tips
Break down the tasks into smaller, more manageable parts. This will make the code easier to write and easier to maintain. Use meaningful variable and function names. This will make the code easier to read and understand. Function names are provided.
Use docstrings to document the functions. This will make the code easier to understand and maintain. Docstrings are provided. Write detailed comments in the code. Not only is this part of your grade for the assignment, but it's building a best-practice for when you are doing coding projects with others after this course is over. Test the code using your own test cases. This will help identify and fix bugs in the code. Feel free to make other input files, and plan out your user inputs to see if code works as expected.
8) Starting
To help you get started, we have provided function declarations and docstrings for each of the above features. We have also included tips for each function to help you implement them effectively. Remember to test your code using test cases to make sure it is working as expected. Good luck!
9) Function 1:
readPatientsFromFile() Note the following correction made to Function 1 requirements
Correction summary: number ranges in "Errors to Handle" section made on 2023-03-17 Correction Details: Old Vs New "Errors to Handle" section to make Function 1 be consistent with Function 4
This function reads patient data from a plaintext file and returns a dictionary, returns a dictionary where each key is a unique patient ID and the corresponding values are 2dimensional lists storing information about each visit (where each visit's information is stored in its own inner-list)
def readPatientsFromFile(fileName):
"""
Reads patient data from a plaintext file.
fileName: The name of the file to read patient data from.
Returns a dictionary of patient IDs, where each patient has
The dictionary has the following structure:
{
patientId (int): [
[date (str), temperature (float), heart rate (int),
[date (str), temperature (float), heart rate (int),
...
],
patientId (int): [
[date (str), temperature (float), heart rate (int),
...
],
...
}
"""
a list o
respirat
respirat
respirat
Functionality
Reads patient data from a plaintext file specified by the fileName argument. Returns a dictionary of patient IDs, where each patient has a list of visits. Each visit is a list of 7 values in the order of date, temperature, heart rate, respiratory rate, systolic blood pressure, diastolic blood pressure, and oxygen saturation, in this order.
Performs additional data validation checks to ensure the data is within reasonable ranges (as listed below) If any of the data is invalid or an error occurs (the list of errors is listed below), the function skips the line that contains the error, and continues reading the next line in the file.
Errors to Handle
Changelog: Please note that the ranges in this section were corrected to match the ranges in Function 4 on Mar 17. If the file specified by fileName cannot be found, print the message: "The file '[fileName]' could not be found." and the program exits. You can assume that you will be passed a file name and not a path.
If there is an unexpected error while reading the file, print the message: "An unexpected error occurred while reading the file." And skips to the next line. If the number of fields in a line is not equal to 8, print the message: "Invalid number of fields ([numFields]) in line: [line]" And skips to the next line If the patient ID or any of the other 7 data values are not in the correct format, print the message: "Invalid data type in line: [line]" And skips to the next line If the temperature value is not within the range of 35 to 42, print the message: "Invalid temperature value ([temp]) in line: [line]" And skips to the next line If the heart rate value is not within the range of 30 to 180, print the message: "Invalid heart rate value ([hr]) in line: [line]" And skips to the next line If the respiratory rate value is not within the range of 5 to 40, print the message: "Invalid respiratory rate value ([rr]) in line: [line]" And skips to the next line If the systolic blood pressure value is not within the range of 70 to 200, print the message: "Invalid systolic blood pressure value ([sbp]) in line: [line]" And skips to the next line If the diastolic blood pressure value is not within the range of 40 to 120, print the message: "Invalid diastolic blood pressure value ([dbp]) in line: [line]" If the oxygen saturation value is not within the range of 70 to 100, print the message: "Invalid oxygen saturation value ([spo2]) in line: [line]" And skips to the next line
Exact Output Formatting
Each error message should be printed exactly as specified in the requirements, with the appropriate variable values filled in. if any of the error messages are printed, we do not add this visit to the dictionary at all, and we move on to the next line
What should the dictionary contain? If the input file looked like this:
1,2022-06-01,37.2,72,16,120,80,97 1,2022-09-15,37.5,73,18,125,82,96 2,2022-06-10,36.9,69,18,123,80,96 2,2023-01-03,37.1,71,19,124,81,97 3,2022-08-05,37.3,74,20,126,83,95 3,2023-03-01,37.4,75,18,123,79,98
2) Patient ID is 0
3) Patient ID is positive integer
https://content.techsystems.work/cs-1026-b-winter-2023-assignment-3/
17/28
2023/3/19 15:50
CS 1026 B, Winter 2023 Assignment 3 – Content Host
4) Patient ID is not found in data
12) Function 4: addPatientData() This function adds new patient data to the patients dictionary and appends this same data to the text file. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
def addPatientData(patients, patientId, date, temp, hr, rr, sbp, dbp, sp """ Adds new patient data to the patient list by appending to the dictio
patients: The dictionary of patient IDs, where each patient has a li patientId: The ID of the patient to add data for. date: The date of the patient visit in the format 'yyyy-mm-dd'. temp: The patient's body temperature. hr: The patient's heart rate. rr: The patient's respiratory rate. sbp: The patient's systolic blood pressure. dbp: The patient's diastolic blood pressure. spo2: The patient's oxygen saturation level. fileName: The name of the file to append new data to. """
Requirements Requirements for the implementation of addPatientData() function are: The function should take in a dictionary of patient IDs as patients, where each patient ID has a list of visits. The function should take in the following parameters for adding new patient data: patientId, date, temp, hr, rr, sbp, dbp, and spo2. The function should take in a file name as fileName and append the new data to this file. You can assume that we will use the same text file to write to as was read in using the readPatientsFromFile() function The function should check the inputs and handle erroneous input as below. The function should add the new data to the patient's visit history by appending the visit information to the text file. The function should display an error message if any input value is invalid and return to the main menu without adding the new data. https://content.techsystems.work/cs-1026-b-winter-2023-assignment-3/
18/28
2023/3/19 15:50
CS 1026 B, Winter 2023 Assignment 3 – Content Host
Errors to Handle Edit note - this section updated 2023-03-15 to clarify the errors. If any of the following errors occur, the program should display the exact corresponding message and return to the main menu If the date format is invalid, print “Invalid date format. Please enter date in the format ‘yyyy-mm-dd’.” If the date is cannot exist, e.g., the 35th day of a month or a 14th month, etc, print "Invalid date. Please enter a valid date." If the temperature is invalid, print "Invalid temperature. Please enter a temperature between 35.0 and 42.0 Celsius." If the heart rate is invalid, print "Invalid heart rate. Please enter a heart rate between 30 and 180 bpm." If the respiratory rate is invalid, print "Invalid respiratory rate. Please enter a respiratory rate between 5 and 40 bpm." If the systolic blood pressure is invalid, print "Invalid systolic blood pressure. Please enter a systolic blood pressure between 70 and 200 mmHg." If the diastolic blood pressure is invalid, print "Invalid diastolic blood pressure. Please enter a diastolic blood pressure between 40 and 120 mmHg." If the oxygen saturation level is invalid, print "Invalid oxygen saturation. Please enter an oxygen saturation between 70 and 100%." If an unexpected error occurs (any exception), print "An unexpected error occurred while adding new data."
Exact Output Required
The function should display a success message after adding the new data. If the new data
is successfully added, print "Visit is saved successfully for Patient #
Test Cases 1) Invalid Date 2) Out of range health stat (oxygen saturation) 3) Valid input
13) Function 5: findVisitsByDate() This function finds the visits by date provided and returns a list of tuples. See below.
def findVisitsByDate(patients, year=None, month=None): """ Find visits by year, month, or both.
patients: A dictionary of patient IDs, where each patient has a list year: The year to filter by. month: The month to filter by. return: A list of tuples containing patient ID and visit that match t """
Functionality: The function should take in a dictionary of patient IDs, where each patient has a list of visits, as well as an optional year and/or month to filter the visits by. The function can accept a year only, or both a year and a month. It can't accept a month only: If the year is only provided, the function returns all visits occurred in that year regardless of the month and day. If the month and year are provided, the function returns all visits occurred in that month of the provided year regardless of the day. If no year and/or month is provided, the function should return all visits for all patients. The function should ignore visits in the dataset with incomplete or invalid date information (i.e. dates that are missing year, month, or day).
It rewrites the text file with the updated patient data. Arguments: patients: A dictionary of patient IDs, where each patient has a list of visits. patientId: The ID of the patient to delete data for. filename: The name of the file to save the updated patient data. Returns: None Errors to handle: If patientId is not found in patients, print "No data found for patient with ID {patientId}". Output: If data for the patient with patientId is deleted, print "Data for patient {patientId} has been deleted.". No output if patientId is not found in patients.
File Writing Requirements:
- The function should open the specified file in write mode ('w'). It is important to note that the w mode will overwrite the data currently in the file, but you will need to write all remaining patients and visits back to the file. When testing this function, your code will actually delete the records from the text file. You will need to re-download the text file to “reset” for your next test.
- The function should iterate over the dictionary of patient data and write each remaining visit for each patient to the file in comma-separated format after removing the deleted patients visit(s) . The format for each line in the file should be: ......