Patient and Records Management
These instructions will allow you to get a working copy of the project on your local machine for development and testing purposes.
See Deployment for notes on how to deploy the project in production.
- Node.js - JavaScript runtime environment
- Clone the repository:
git clone https://github.com/cesarhenrq/wexer-psi-back-end.git
- Install the dependencies:
npm install
- Create a
.env
file in the root directory of the project and fill in the environment variables:
# Server
PORT= The port where the server will run
# Database
DATABASE_URL= The URL of the database
# Authentication
SECRET_KEY= The secret key for JWT authentication
- Run the application:
npm start
or
npm run dev
To run the tests, run the following command:
npm test
There are 2 types of tests:
- Unit tests
- Integration tests
To deploy the application, run the following command:
npm run build
This command will generate a dist
folder containing the compiled code.
- Node.js - JavaScript runtime environment
- Express - Web application framework
- MongoDB - Database
- Mongoose - MongoDB object modeling for Node.js
- Jest - JavaScript Testing Framework
- Supertest - HTTP assertions
- Bcrypt - Password encryption
- Jsonwebtoken - Authentication
- Multer - File upload
- Dotenv - Environment variables
- Prettier - Code formatter
The "User" entity represents the users of the system.
Name | Type | Required | Unique | Description |
---|---|---|---|---|
name | String | Yes | No | Username |
String | Yes | Yes | User email address | |
password | String | Yes | No | User password (encrypted) |
photo | ObjectId | No | No | Profile picture id |
createdAt | Date | Default | No | Record creation date |
updatedAt | Date | Default | No | Record update date |
{
"_id": "60a2a68c7b4f4d004e9a25d9",
"name": "John Doe",
"email": "jhondoe@example.com",
"photo": "60a2a68c7b4f4d004e9a25e1",
"password": "***********",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
The entity "Patient" represents the patients registered in the system.
Name | Type | Required | Unique | Description |
---|---|---|---|---|
user | ObjectId | Yes | No | Record Owner User ID |
timelines | ObjectId[] | Yes | No | Patient timelines ID's |
name | String | Yes | No | Patient name |
contact | String | Yes | No | Patient contact (Phone/E-mail) |
birthdate | Date | Yes | No | Patient's date of birth |
demands | String | No | No | Patient demands for treatment |
personalAnnotations | String | No | No | Personal notes about the patient |
createdAt | Date | Default | No | Record creation date |
updatedAt | Date | Default | No | Record update date |
{
"_id": "60a2a68c7b4f4d004e9a25d8",
"user": "60a2a68c7b4f4d004e9a25d9",
"timelines": [
"60a2a68c7b4f4d004e9a25d9"
],
"name": "John Doe",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems.",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
The "Timeline" entity represents the timelines related to the patients registered in the system.
Name | Type | Required | Unique | Description |
---|---|---|---|---|
name | String | Yes | No | Timeline name |
occurrences | ObjectId[] | Yes | No | Timeline occurrences ID's |
createdAt | Date | Default | No | Record creation date |
updatedAt | Date | Default | No | Record update date |
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"occurrences": [
"60a2a68c7b4f4d004e9a25d9",
"60a2a68c7b4f4d004e9a25da",
"60a2a68c7b4f4d004e9a25db"
],
"name": "Physiotherapy",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
The entity "Occurrence" represents an occurrence of a therapy session or a relevant fact about a patient. It contains information such as title, content, type and attachment files.
Name | Type | Required | Unique | Description |
---|---|---|---|---|
name | String | Yes | No | Occurrence name |
content | String | Yes | No | Occurrence description |
kind | String | Yes | No | Session or Relevant Fact |
files | ObjectId[] | Yes | No | files ID's |
createdAt | Date | Default | No | Record creation date |
updatedAt | Date | Default | No | Record update date |
{
"name": "Session 1",
"content": "Today we talked about...",
"kind": "session",
"files": [
"61711d13c799a3347f3ec6f3"
],
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
The "File" entity represents the files in the system, being occurrence files or profile picture
Name | Type | Required | Unique | Description |
---|---|---|---|---|
filename | String | Yes | No | File name |
mimetype | String | Yes | No | File extension |
createdAt | Date | Default | No | Record creation date |
updatedAt | Date | Default | No | Record update date |
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"filename": "file.png",
"mimetype": "image/png",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Method | Route | Description |
---|---|---|
POST | /auth | Authenticate a user |
Method | Route | Description |
---|---|---|
POST | /users | Register a new user |
PATCH | /users/:id | Update user informations |
DELETE | /users/:id | Delete a user |
GET | /users/:id/patients | Get all the patients from an user |
Method | Route | Description |
---|---|---|
POST | /patients | Register a new patient |
GET | /patients:id | Get a patient by its id |
PATCH | /patients/:id | Update patient informations |
DELETE | /patients/:id | Delete a patient |
GET | /patients/:id/timelines | Get all the timelines |
Method | Route | Description |
---|---|---|
POST | /timelines:patientId | Register a new timeline |
GET | /timelines/:id | Get a timeline by its id |
PATCH | /timelines/:id | Update timeline informations |
DELETE | /timelines/:id/patients/:patientId | Delete a timeline |
GET | /timelines/:id/occurrences | Get all the occurrences |
Method | Route | Description |
---|---|---|
POST | /occurrences:timelineId | Register a new occurrence |
GET | /occurrences/:id | Get an occurrence by its id |
PATCH | /occurrences/:id | Update occurrence informations |
DELETE | /occurrences/:id/timelines/:timelineId | Delete an occurrence |
- [POST] /auth
- [POST] /users
- [PATCH] /users/:id
- [DELETE] /users/:id
- [GET] /users/:id/patients
- [POST] /patients
- [GET] /patients/:id
- [PATCH] /patients/:id
- [DELETE] /patients/:id
- [GET] /patients/:id/timelines
- [POST] /timelines/:patientId
- [GET] /timelines/:id
- [PATCH] /timelines/:id
- [DELETE] /timelines/:id/patients/:patientId
- [GET] /timelines/:id/occurrences
- [POST] /occurrences/:timelineId
- [GET] /occurrences/:id
- [PATCH] /occurrences/:id
- [DELETE] /occurrences/:id/timelines/:timelineId
Authenticate a user
POST /auth
{
"email": "johndoe@email.com",
"password": "123456"
}
{
"user": {
"_id": "60a2a68c7b4f4d004e9a25d9",
"name": "John Doe",
"email": "johndoe@email.com",
"password": "***********",
"photo": "60a2a68c7b4f4d004e9a25e1",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYwYTI2OGM3YjRmNGQwMDRlOWEyNWQ5IiwiaWF0IjoxNjIwMjQ0NjQ4LCJleHAiOj"
}
Register a new user
POST /users
{
"name": "John Doe",
"email": "johndoe@email.com"
}
{
"_id": "60a2a68c7b4f4d004e9a25d9",
"name": "John Doe",
"email": "johndoe@email.com",
"password": "***********",
"photo": "60a2a68c7b4f4d004e9a25e1",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Update user informations
PATCH /users/60a2a68c7b4f4d004e9a25d9
Authorization Bearer <token>
{
"name": "John Doe 2"
}
{
"_id": "60a2a68c7b4f4d004e9a25d9",
"name": "John Doe 2",
"email": "johndoe@email.com",
"password": "***********",
"photo": "60a2a68c7b4f4d004e9a25e1",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Delete a user
DELETE /users/60a2a68c7b4f4d004e9a25d9
Authorization Bearer <token>
{
"_id": "60a2a68c7b4f4d004e9a25d9",
"name": "John Doe",
"email": "johndoe@email.com",
"password": "***********",
"photo": "60a2a68c7b4f4d004e9a25e1",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Get all the patients from an user
GET /users/60a2a68c7b4f4d004e9a25d9/patients
Authorization Bearer <token>
[
{
"_id": "60a2a68c7b4f4d004e9a25d8",
"user": "60a2a68c7b4f4d004e9a25d9",
"timelines": ["60a2a68c7b4f4d004e9a25d9"],
"name": "John Doe",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems.",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
]
Register a new patient
POST /patients
Authorization Bearer <token>
{
"user": "60a2a68c7b4f4d004e9a25d9",
"name": "John Doe",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems."
}
{
"_id": "60a2a68c7b4f4d004e9a25d8",
"user": "60a2a68c7b4f4d004e9a25d9",
"timelines": [],
"name": "John Doe",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems.",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Get a patient by its id
GET /patients/60a2a68c7b4f4d004e9a25d8
Authorization Bearer <token>
{
"_id": "60a2a68c7b4f4d004e9a25d8",
"user": "60a2a68c7b4f4d004e9a25d9",
"timelines": ["60a2a68c7b4f4d004e9a25d9"],
"name": "John Doe",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems.",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Update patient informations
PATCH /patients/60a2a68c7b4f4d004e9a25d8
Authorization Bearer <token>
{
"name": "John Doe 2"
}
{
"_id": "60a2a68c7b4f4d004e9a25d8",
"user": "60a2a68c7b4f4d004e9a25d9",
"timelines": ["60a2a68c7b4f4d004e9a25d9"],
"name": "John Doe 2",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems.",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Delete a patient
DELETE /patients/60a2a68c7b4f4d004e9a25d8
Authorization Bearer <token>
{
"_id": "60a2a68c7b4f4d004e9a25d8",
"user": "60a2a68c7b4f4d004e9a25d9",
"timelines": ["60a2a68c7b4f4d004e9a25d9"],
"name": "John Doe 2",
"birthdate": "1980-01-01T00:00:00.000Z",
"contact": "(21) 99999-8888",
"demands": "Back pain",
"personalAnnotations": "Patient with a history of back problems.",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Get all the timelines
GET /patients/60a2a68c7b4f4d004e9a25d8/timelines
Authorization Bearer <token>
[
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"occurrences": ["60a2a68c7b4f4d004e9a25d9"],
"name": "Physiotherapy",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
]
Register a new timeline
POST /timelines/60a2a68c7b4f4d004e9a25d8
Authorization Bearer <token>
{
"name": "Physiotherapy"
}
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"occurrences": [],
"name": "Physiotherapy",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Get a timeline by its id
GET /timelines/60a2a68c7b4f4d004e9a25e1
Authorization Bearer <token>
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"occurrences": ["60a2a68c7b4f4d004e9a25d9"],
"name": "Physiotherapy",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Update timeline informations
PATCH /timelines/60a2a68c7b4f4d004e9a25e1
Authorization Bearer <token>
{
"name": "Physiotherapy 2"
}
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"occurrences": ["60a2a68c7b4f4d004e9a25d9"],
"name": "Physiotherapy 2",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Delete a timeline
DELETE /timelines/60a2a68c7b4f4d004e9a25e1/patients/60a2a68c7b4f4d004e9a25d8
Authorization Bearer <token>
{
"_id": "60a2a68c7b4f4d004e9a25e1",
"occurrences": ["60a2a68c7b4f4d004e9a25d9"],
"name": "Physiotherapy 2",
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Get all the occurrences
GET /timelines/60a2a68c7b4f4d004e9a25e1/occurrences
Authorization Bearer <token>
[
{
"name": "Session 1",
"content": "Today we talked about...",
"kind": "session",
"files": ["61711d13c799a3347f3ec6f3"],
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
]
Register a new occurrence
POST /occurrences/60a2a68c7b4f4d004e9a25e1
Authorization Bearer <token>
{
"name": "Session 1",
"content": "Today we talked about...",
"kind": "session",
"files": ["61711d13c799a3347f3ec6f3"]
}
{
"name": "Session 1",
"content": "Today we talked about...",
"kind": "session",
"files": ["61711d13c799a3347f3ec6f3"],
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Get an occurrence by its id
GET /occurrences/60a2a68c7b4f4d004e9a25e1
Authorization Bearer <token>
{
"name": "Session 1",
"content": "Today we talked about...",
"kind": "session",
"files": ["61711d13c799a3347f3ec6f3"],
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Update occurrence informations
PATCH /occurrences/60a2a68c7b4f4d004e9a25e1
Authorization Bearer <token>
{
"name": "Session 2"
}
{
"name": "Session 2",
"content": "Today we talked about...",
"kind": "session",
"files": ["61711d13c799a3347f3ec6f3"],
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
Delete an occurrence
DELETE /occurrences/60a2a68c7b4f4d004e9a25e1/timelines/60a2a68c7b4f4d004e9a25d8
Authorization Bearer <token>
{
"name": "Session 2",
"content": "Today we talked about...",
"kind": "session",
"files": ["61711d13c799a3347f3ec6f3"],
"createdAt": "2021-05-17T18:30:00.000Z",
"updatedAt": "2021-05-17T18:30:00.000Z"
}
- Invalid JSON
- Invalid request body
- Invalid request parameters
- Invalid request query
- Invalid request headers
- Invalid token
- Token not provided
- Resource not found
- Internal server error
- Successful request
- Successful request with resource creation
- Invalid JSON
- Invalid request body
- Invalid request parameters
- Invalid request query
- Invalid request headers
- Invalid token
- Token not provided
- Resource not found
- Internal server error
- Development - César Henrique
- Documentation - César Henrique
This project is under the license MIT