Introduction
Scheduling systems must stop two things happening at once: a doctor seeing two patients in one slot, or a patient booked with two doctors. This project models patients, doctors and appointments and enforces those constraints.
Problem statement
Objectives
- Model related entities with IDs
- Enforce scheduling constraints
- Return descriptive error codes
- Persist a whole database struct
Features
- Patient registration
- Doctor list with specialties
- Booking with doctor and patient clash checks
- Cancellation with history kept
- Daily doctor schedule and patient history
Concepts demonstrated
- Entity relationships
- Constraint checking
- Error codes
- Lookup tables
System architecture
Each module pairs a header (.h, the interface) with a source file (.c, the implementation); main.c contains only the user interface. All data sits in one Hospital struct (arrays of patients, doctors and appointments). book returns an appointment ID or a negative error code that indexes an error-message table in main.c. Saving writes the whole struct with one fwrite.
Folder structure
Complete source code
Makefile
What each file does
- src/hospital.h
- Entity types, limits and the API.
- src/hospital.c
- Registration, lookup, booking rules, cancellation, slot labels and persistence.
- src/main.c
- Menu, schedule and history reports, and default doctors.
- Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
1 Sita 34 F 9876500001 1 Ram 61 M 9876500002 2 3 1 101 1 0 3 2 101 1 0 3 2 102 1 0 3 1 103 1 0 3 2 101 1 2 5 101 1 4 1 6 1 0
Testing
- Diff with
tests/expected-output.txt(one doctor clash and one patient clash are rejected). - Cancel an appointment and book the same slot again.
- Restart and confirm the data is kept.
Common errors
Old hospital.dat makes the program misbehave
The file is a raw struct dump; delete it after changing any struct definition.
Two patients with the same name
Names are not unique; always use the patient ID.
Possible improvements
- Billing and prescriptions
- Search patients by name
- Weekly calendar view
Additional challenges
- 1Find the next free slot for a doctor automatically.
- 2Add a waiting list when a doctor's day is full.
- 3Move storage to a text format readable by other programs.
Built and tested it yourself? Mark it to update your dashboard.