CrimsonCare
CrimsonCare is a C project designed to provide a robust solution for blood management.
 
Loading...
Searching...
No Matches
hospital_manager.c File Reference

Hospital manager source file. More...

Go to the source code of this file.

Functions

loadHospitals

Load hospitals from file

This function loads the hospitals from the file resources/db/hospitals.txt and stores it in the hospitalHead linkedlist.

Note
The file path 'resources/db' is relative to the project root directory. Make sure that the folder exists also to run the program from the root directory.
Postcondition
If the file is not found, the function does nothing. Otherwise, the hospitals are loaded from the file and stored in the hospitalHead linkedlist.
Exceptions
fopen()- If the file cannot be opened, an error message is displayed, also the function frees the hospitalHead linkedlist.
malloc()- If memory allocation fails, an error message is displayed, also the function frees the hospitalHead linkedlist.
void loadHospitals (void)
 
saveHospitals

Save hospitals to file

This function saves the hospitals to the file resources/db/hospitals.txt.

Note
The file path 'resources/db' is relative to the project root directory. Make sure that the folder exists also to run the program from the root directory.
Postcondition
The hospitals from the hospitalHead linkedlist are saved to the file.
Exceptions
fopen()- If the file cannot be opened, an error message is displayed.
void saveHospitals (void)
 
addHospital

Add hospital

This function adds a new hospital to the hospitalHead linkedlist.

Parameters
[in]nameHospital name
[in]locationHospital location
Returns
Hospital code or NULL if hospital is not added
Note
The hospital code is generated by taking the maximum of the first three characters of the hospital name and appending a random number between 0000 and 9999.
Precondition
name is not empty and valid
location is not empty and valid
Postcondition
The hospital is added to the hospitalHead linkedlist.
Exceptions
Ifthe name or location is empty or invalid, an error message is displayed.
malloc()- If the memory allocation for the new hospital fails, an error message is displayed.
char * addHospital (const char *name, const char *location)
 
validateHospitalCode

Validate hospital code

This function validates the given hospital code by traversing the hospitalHead linkedlist.

Parameters
[in]codeHospital code
Returns
True if hospital code is valid, False otherwise
Precondition
code is not empty and valid
Postcondition
If the code is found in the hospitalHead linkedlist, the function returns true. Otherwise, it returns false.
Exceptions
Ifthe code is empty or invalid, an error message is displayed.
bool validateHospitalCode (const char *code)
 
deleteHospital

Delete hospital

This function deletes the hospital with the given code by traversing the hospitalHead linkedlist.

Parameters
[in]codeHospital code
[in]adminUsernameAdmin username
[in]adminPasswordAdmin password
Returns
True if hospital is deleted, False otherwise
Precondition
code is not empty and valid
adminUsername is not empty and valid
adminPassword is not empty
Postcondition
The hospital with the given code is deleted from the hospitalHead linkedlist.
Exceptions
Ifthe code is empty or invalid, an error message is displayed.
Ifthe adminUsername is empty or invalid or adminPassword is empty, an error message is displayed.
Ifthe pair of adminUsername and adminPassword is invalid, an error message is displayed.
Ifthe hospital with the given code is not found, an error message is displayed.
bool deleteHospital (const char *code, const char *adminUsername, const char *adminPassword)
 
getHospitalNameByCode

Get hospital name by code

This function gets the hospital name by the given code by traversing the hospitalHead linkedlist.

Parameters
[in]codeHospital code
Returns
Hospital name or NULL if not found
Precondition
code is not empty and valid
Postcondition
If the code is found in the hospitalHead linkedlist, the function returns the hospital name. Otherwise, it returns NULL.
Exceptions
Ifthe code is empty or invalid, an error message is displayed.
char * getHospitalNameByCode (const char *code)
 
displayHospitals

Display all hospitals

This function displays all the hospitals in the hospitalHead linkedlist by traversing it.

Postcondition
The hospitals in the hospitalHead linkedlist are displayed in a formatted manner.
void displayHospitals (void)
 
freeHospital

Free hospital list from memory

This function frees the hospitalHead linkedlist from memory by traversing it.

Postcondition
The hospitalHead linkedlist is freed from memory.
void freeHospital (void)
 

Variables

HospitalhospitalHead = NULL
 Hospital head pointer.
 

Detailed Description

Hospital manager source file.

This file contains the implementation of the functions for the hospital manager module.

Author
CrimsonCare Team
Date
2025-01-18

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file hospital_manager.c.

Function Documentation

◆ addHospital()

char * addHospital ( const char * name,
const char * location )

Definition at line 149 of file hospital_manager.c.

◆ deleteHospital()

bool deleteHospital ( const char * code,
const char * adminUsername,
const char * adminPassword )

Definition at line 280 of file hospital_manager.c.

◆ displayHospitals()

void displayHospitals ( void )

Definition at line 379 of file hospital_manager.c.

◆ freeHospital()

void freeHospital ( void )

Definition at line 405 of file hospital_manager.c.

◆ getHospitalNameByCode()

char * getHospitalNameByCode ( const char * code)

Definition at line 345 of file hospital_manager.c.

◆ loadHospitals()

void loadHospitals ( void )

Definition at line 57 of file hospital_manager.c.

◆ saveHospitals()

void saveHospitals ( void )

Definition at line 113 of file hospital_manager.c.

◆ validateHospitalCode()

bool validateHospitalCode ( const char * code)

Definition at line 237 of file hospital_manager.c.

Variable Documentation

◆ hospitalHead

Hospital* hospitalHead = NULL

Hospital head pointer.

This pointer is used to track hospital linkedlist on runtime.

Definition at line 38 of file hospital_manager.c.