/covidtrackingfinal

A C# REST Api based system that allows different CRUD functions

Primary LanguageC#MIT LicenseMIT

Covid Patients Tracking System

A C# REST Api based system that allows different CRUD functions

Functionality

This system interacts with a remote MongoDB database.
It allows patient creation, deletion and update.
A nurse can use the different CRUD Endpoints to update the database with new patients that need to be tracked,
add visit routes for infected patients, log encounters that each infected patient had with different people,
make interviews with potential patients that each patient has encountered, get information about those encounters
and get different statistics about healed, infected and isolated people in our system.

Structure

The solution contains 2 projects:
The first is 'covidtracking' - the project containing the system, implemented as a REST API service with different CRUD endpoints.
The second is 'covidtracking.UnitTests' - the test project, containing different unit tests implemented with xUnit that cover the functionality of the system.
The database used in this project is MongoDB and the connection string is hardcoded to ease the usage and testing.

Architecture:

The 'covidtracking' is written as a REST API project.
The project was implemented following the SOLID principles to allow the desired benefits.
It contains divided into layers, kept in several folders, each contains the files used in that particular layer:

Controllers:
The controllers are the layer that handles the different Http requests the API uses.
Each controller handles the appropriate requests related to that area of the project/data:
For example:
LabTestController handles requests related to lab tests creation,
StatisticsController handles statistics fetching from the database etc.
Each controller communicates with the appropriate databases/collections needed for its operations.

Database:
The database layer contains the different database models, each in its own internal folder for order and convenience.
While we used MongoDB as our database in this project, any other DB (SQL SERVER...) can be used by implementing each model's
interface contract. By using the Interfaces we enable our system to be more generic and responsive.
The current concrete (MongoDB) models are injected using Dependency Injection in the Program.cs file.
Each controller may use different DB models but each model only communicates with its single database/collection.
The models contain all the logic our system uses.

Dtos:
We used Dtos (Data transfer objects) to handle Object creation and data transfer in a safe and agreed manner.
Each area has its own Dtos and they are used across the project to create links and provide correct connections.

Entities:
The entities represent each Entity's formal implementation.
The Mongo database knows and stores those entities (while the internal data mostly uses Dtos).

Settings:
The Settings folder contains the MongoDB settings (connection string).

Utilities:
The Utilities folder contains different adapters and extensions used across the project.

Testing

The project contains internal methods and statements to verify correctness of flow and protection in different edge points.
We used conditional statements and REGEX to verify correctness.
Unit Testing
the 'covidtracking.UnitTests' project contains the unit tests for our 'covidtracking' project.
The unit tests, implemented using xUnit cover different endpoints and edge points our system has.
The tests include ActionResult type Assertion, returned value comparison and it has passing/failing expected tests.

Build and Workflow

Build and run

There are 2 ways to run this project: The first option, run the project locally you just need to clone the repository and perform a regular run using VSCode/Visual Studio. The program will run on localhost, Port 7122 (https).
To run the project, you just need to clone the repository and perform a regular run using VSCode/Visual Studio.
The project supports Swagger UI or can be accessed using Postman.
Use "https://localhost:7122/swagger/index.html" for Swagger or just "https://localhost:7122/" for Postman.
We created a Postman workspace containing the different Endpoints the system has at:
https://www.postman.com/lunar-firefly-552571/workspace/covidtracking
The second option in running using docker:
Start any terminal session (cmd, PowerShell, on VsCode, etc..) and write:
docker run -it --rm -p 8080:80 nivrave/covidtrackingfinal:latest
After downloading the image, the project will run on a docker container.
Pay attention that in this method the Protocol will be http (not https) and the Port is 8080 (not 7122).
Use the following address on any communication platform to access the Api:
http://localhost:8080

CI/CD

This GitHub repository has an automatic CI/CD workflow.
It is implemented using 'GitHub Actions' and is activated on each push/pull request to the 'main' branch.
The workflow builds the project and commits 30 unit tests.
If those stages are passed - the Docker image is built (updated) and deployed to the docker
hub repository at nivrave/covidtrackingfinal

Endpoints

Endpoint Description
PUT /patients Add a new patient to be tracked by the system
GET /patients Returns the list of all the patients tracked by the system (only real patients and not potential ones)
PUT /patients/{id}/route Add a location a patient visited during the last 7 days
GET /patients/{id}/route Returns the list of all the locations the patient visited in during the last 7 days
PUT /patients/{id}/encounters Add the details of a person the patient met during the last 7 days
GET /patients/{id}/encounters Return the list of the people the patient met during the last 7 days
GET /patients/{id}/full Returns the person details and whether he is sick or not together with all his/her lab tests
GET /patients/new?since=[VALUE] Will display a list of all sick people who were added after the value of 'since'
GET /patients/potential Returns the list of encounters where the person details were not inserted yet
GET /patients/isolated Returns the list of all the people in the system that are in isolation (person is isolated until he has two negative tests since he encountered an infected person or reported infected)
POST patients/potential/{potentialPatientId} Remove the potential patient and transform him into real patient
POST /labtests Add a lab test result
GET /statistics Returns statistics about the current state – amount of sicks, amount of isolated, how many have healed, and how many sick we have per city