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

Blood manager source file. More...

Go to the source code of this file.

Functions

isValidBloodGroup

Check if blood group is valid

This function checks if the given blood group id is valid by checking the size of the availableBloodGroups array.

Parameters
[in]idBlood group id
Returns
True if blood group is valid, False otherwise
Postcondition
If the id is within the range of the availableBloodGroups array, the function returns true. Otherwise, it returns false.
bool isValidBloodGroup (uint32_t id)
 
addBloodGroup

Add blood group

This function adds a new blood group to the bloodHead linkedlist.

Parameters
[in]idBlood group id
[in]bloodGroupBlood group name
[in]priceBlood group price
[in]quantityBlood group quantity
Returns
True if blood group is added, False otherwise
Precondition
id is valid
bloodGroup is not empty
Postcondition
Updates the blood stock in the bloodHead linkedlist.
Exceptions
Ifthe bloodGroup is empty, an error message is displayed.
Ifthe id is not valid, an error message is displayed.
malloc()- If the memory allocation for the new blood group fails, an error message is displayed.
bool addBloodGroup (uint32_t id, const char *bloodGroup, float price, uint32_t quantity)
 
initializeBloodGroups

Initialize blood groups

This function helps to initialize the default blood groups to the bloodHead linkedlist.

Postcondition
The blood groups are added to the bloodHead linkedlist.
Exceptions
Ifadding blood group fails, an error message is displayed.
void initializeBloodGroups (void)
 
saveBloodGroups

Save blood groups to file

This function saves the linkedlist data from bloodHead to the file resources/db/blood_data.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 linkedlist data is saved to the file.
Exceptions
fopen()- If the file cannot be opened, an error message is displayed.
void saveBloodGroups (void)
 
updateBloodQuantity

Update blood quantity

This function updates the blood quantity of the given blood group id by traversing the bloodHead linkedlist.

Parameters
[in]idBlood group id
[in]newQuantityNew quantity
Returns
True if blood quantity is updated, False otherwise
Postcondition
If the id is found in the bloodHead linkedlist, the function updates the blood quantity and saves the updated linkedlist.
Exceptions
Ifthe id is not found in the `bloodHead` linkedlist, an error message is displayed.
bool updateBloodQuantity (uint32_t id, uint32_t newQuantity)
 
updateBloodPrice

Update blood price

This function updates the blood price of the given blood group id by traversing the bloodHead linkedlist.

Parameters
[in]idBlood group id
[in]newPriceNew price
Returns
True if blood price is updated, False otherwise
Postcondition
If the id is found in the bloodHead linkedlist, the function updates the blood price and saves the updated linkedlist.
Exceptions
Ifthe id is not found in the `bloodHead` linkedlist, an error message is displayed.
bool updateBloodPrice (uint32_t id, float newPrice)
 
loadBloodGroups

Load blood groups from file

This function loads the blood groups from the file resources/db/blood_data.txt to the bloodHead 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
The blood groups are loaded to the bloodHead linkedlist.
Exceptions
fopen()- If the file cannot be opened, an error message is displayed.
malloc()- If the memory allocation for the new blood group fails, an error message is displayed.
void loadBloodGroups (void)
 
isBloodAvailable

Check if blood is available for a specific transaction type

This function checks if blood is available for a specific transaction type by traversing the bloodHead linkedlist.

Parameters
[in]idBlood group id, null if to check for any blood
[in]typeTransaction type
Returns
True if blood is available, False otherwise
Precondition
id is null or valid
type is BUY or SELL
Postcondition
If the id is found in the bloodHead linkedlist, the function returns true. Otherwise, it returns false.
Exceptions
Ifthe type is not BUY or SELL, an error message is displayed.
Ifthe id is not null and is not valid, an error message is displayed.
bool isBloodAvailable (uint32_t *id, TransactionType type)
 
displayBloodGroups

Display all blood groups

This function displays all the blood groups in the availableBloodGroups array.

Postcondition
The available blood groups are displayed.
void displayBloodGroups (void)
 
displayBloodStocks

Display all blood stocks

This function displays all the blood stocks in the bloodHead linkedlist.

Note
If Price or Quantity is not available, it is displayed as N/A.
Postcondition
The blood stocks are displayed.
void displayBloodStocks (void)
 
getBloodGroupById

Get blood group by id

This function returns the blood group name by the given id.

Parameters
[in]idBlood group id
Returns
Blood group name or NULL if not found
Postcondition
If the id is valid, the function returns the blood group name.
Exceptions
Ifthe id is not valid, an error message is displayed.
char * getBloodGroupById (uint32_t id)
 
freeBloodList

Free blood list

This function frees the bloodHead linkedlist.

Postcondition
The bloodHead linkedlist is freed.
void freeBloodList (void)
 

Variables

BloodStockbloodHead = NULL
 Blood stock head pointer.
 
char * availableBloodGroups [8] = { "A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-" }
 Blood groups.
 

Detailed Description

Blood manager source file.

This file contains the implementation of the functions for the blood 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 blood_manager.c.

Function Documentation

◆ addBloodGroup()

bool addBloodGroup ( uint32_t id,
const char * bloodGroup,
float price,
uint32_t quantity )

Definition at line 83 of file blood_manager.c.

◆ displayBloodGroups()

void displayBloodGroups ( void )

Definition at line 359 of file blood_manager.c.

◆ displayBloodStocks()

void displayBloodStocks ( void )

Definition at line 374 of file blood_manager.c.

◆ freeBloodList()

void freeBloodList ( void )

Definition at line 420 of file blood_manager.c.

◆ getBloodGroupById()

char * getBloodGroupById ( uint32_t id)

Definition at line 404 of file blood_manager.c.

◆ initializeBloodGroups()

void initializeBloodGroups ( void )

Definition at line 128 of file blood_manager.c.

◆ isBloodAvailable()

bool isBloodAvailable ( uint32_t * id,
TransactionType type )

Definition at line 313 of file blood_manager.c.

◆ isValidBloodGroup()

bool isValidBloodGroup ( uint32_t id)

Definition at line 59 of file blood_manager.c.

◆ loadBloodGroups()

void loadBloodGroups ( void )

Definition at line 249 of file blood_manager.c.

◆ saveBloodGroups()

void saveBloodGroups ( void )

Definition at line 149 of file blood_manager.c.

◆ updateBloodPrice()

bool updateBloodPrice ( uint32_t id,
float newPrice )

Definition at line 217 of file blood_manager.c.

◆ updateBloodQuantity()

bool updateBloodQuantity ( uint32_t id,
uint32_t newQuantity )

Definition at line 183 of file blood_manager.c.

Variable Documentation

◆ availableBloodGroups

char* availableBloodGroups[8] = { "A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-" }

Blood groups.

This array contains the available blood groups.

Definition at line 44 of file blood_manager.c.

◆ bloodHead

BloodStock* bloodHead = NULL

Blood stock head pointer.

Globally exposed blood stock head pointer.

This pointer is used to track blood stock linkedlist on runtime.

Definition at line 38 of file blood_manager.c.