Skip to content
6 changes: 3 additions & 3 deletions src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cors from '@fastify/cors';
import jwt from '@fastify/jwt';
import multipart from '@fastify/multipart';
import { fastifyMultipart } from '@fastify/multipart';
import { fastifyStatic } from '@fastify/static';
import { fastify } from 'fastify';
import fastifyBcrypt from 'fastify-bcrypt';
import { fastifyBcrypt } from 'fastify-bcrypt';
import { resolve } from 'node:path';

import {
Expand All @@ -27,7 +27,7 @@ app.setErrorHandler(errorHandler);
app.register(cors, {
origin: '*',
});
app.register(multipart);
app.register(fastifyMultipart);
app.register(fastifyStatic, {
root: resolve(__dirname, '../uploads'),
prefix: '/uploads',
Expand Down
2 changes: 1 addition & 1 deletion src/app/infra/http/middleware/authenticate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Role, Status } from '@prisma/client';
import { FastifyReply, FastifyRequest } from 'fastify';

import { app } from '@app/app';
import { Status, Role } from '@shared/enums';

interface TokenData {
id: number;
Expand Down
4 changes: 2 additions & 2 deletions src/app/infra/http/middleware/update-last-access.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FastifyReply, FastifyRequest } from 'fastify';

import { app } from '@app/app';
import { UserRepository } from '@shared/repositories/implementations';
import { IUserRepository } from '@shared/repositories/interfaces/user';

export const updateLastAccess = (userRepository: UserRepository) => {
export const updateLastAccess = (userRepository: IUserRepository) => {
return async (req: FastifyRequest, res: FastifyReply) => {
try {
const authorization = req.headers.authorization;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Warnings:

- The `status` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- Changed the type of `role` on the `users` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- CreateEnum
CREATE TYPE "Status" AS ENUM ('ACTIVE', 'INACTIVE');

-- CreateEnum
CREATE TYPE "Role" AS ENUM ('ADMIN', 'EDITOR', 'CLINICAL');

-- CreateEnum
CREATE TYPE "Sex" AS ENUM ('MALE', 'FEMALE', 'OTHER');

-- CreateEnum
CREATE TYPE "MaritalStatus" AS ENUM ('SINGLE', 'MARRIED', 'DIVORCED', 'WIDOWED', 'SEPARATED');

-- CreateEnum
CREATE TYPE "AppointmentStatus" AS ENUM ('COMPLETED', 'CANCELLED', 'PENDING');

-- CreateEnum
CREATE TYPE "AppointmentType" AS ENUM ('QUERY', 'OTHER', 'ACCIDENT', 'FIREARM_INJURY', 'WHITE_WEAPON_INJURY');

-- AlterTable
ALTER TABLE "users" DROP COLUMN "role",
ADD COLUMN "role" "Role" NOT NULL,
DROP COLUMN "status",
ADD COLUMN "status" "Status" NOT NULL DEFAULT 'ACTIVE';
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Warnings:

- The values [OTHER] on the enum `Sex` will be removed. If these variants are still used in the database, this will fail.
- The `appointment_type` column on the `appointments` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The `status` column on the `appointments` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- The `status` column on the `doctors` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- You are about to drop the column `material_status` on the `patients` table. All the data in the column will be lost.
- The `status` column on the `patients` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- Changed the type of `sex` on the `doctors` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `sex` on the `patients` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- AlterEnum
BEGIN;
CREATE TYPE "Sex_new" AS ENUM ('MALE', 'FEMALE');
ALTER TABLE "patients" ALTER COLUMN "sex" TYPE "Sex_new" USING ("sex"::text::"Sex_new");
ALTER TABLE "doctors" ALTER COLUMN "sex" TYPE "Sex_new" USING ("sex"::text::"Sex_new");
ALTER TYPE "Sex" RENAME TO "Sex_old";
ALTER TYPE "Sex_new" RENAME TO "Sex";
DROP TYPE "Sex_old";
COMMIT;

-- AlterTable
ALTER TABLE "appointments" DROP COLUMN "appointment_type",
ADD COLUMN "appointment_type" "AppointmentType" NOT NULL DEFAULT 'QUERY',
DROP COLUMN "status",
ADD COLUMN "status" "AppointmentStatus" NOT NULL DEFAULT 'PENDING';

-- AlterTable
ALTER TABLE "doctors" DROP COLUMN "sex",
ADD COLUMN "sex" "Sex" NOT NULL,
DROP COLUMN "status",
ADD COLUMN "status" "Status" NOT NULL DEFAULT 'ACTIVE';

-- AlterTable
ALTER TABLE "patients" DROP COLUMN "material_status",
ADD COLUMN "marital_status" "MaritalStatus",
DROP COLUMN "sex",
ADD COLUMN "sex" "Sex" NOT NULL,
DROP COLUMN "status",
ADD COLUMN "status" "Status" NOT NULL DEFAULT 'ACTIVE';
72 changes: 55 additions & 17 deletions src/app/infra/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,51 @@ datasource db {
url = env("DATABASE_URL")
}

enum Status {
ACTIVE
INACTIVE
}

enum Role {
ADMIN
EDITOR
CLINICAL
}

enum Sex {
MALE
FEMALE
}

enum MaritalStatus {
SINGLE
MARRIED
DIVORCED
WIDOWED
SEPARATED
}

enum AppointmentStatus {
COMPLETED
CANCELLED
PENDING
}

enum AppointmentType {
QUERY
OTHER
ACCIDENT
FIREARM_INJURY
WHITE_WEAPON_INJURY
}

model User {
id Int @id @default(autoincrement())
name String
email String @unique
role String
role Role
image_url String?
status String @default("ativo")
status Status @default(ACTIVE)
last_access DateTime?
password String
created_at DateTime @default(now())
Expand All @@ -23,41 +61,41 @@ model User {
}

model Patient {
id String @id @default(uuid())
id String @id @default(uuid())
name String
birth_date DateTime
cpf String? @unique
cns String? @unique
sex String
cpf String? @unique
cns String? @unique
sex Sex
address String?
mother_name String?
father_name String?
material_status String?
marital_status MaritalStatus?
occupation String?
email String?
phone String?
contact_emergency String?
name_contact_emergency String?
health_agent String?
status String @default("ativo")
status Status @default(ACTIVE)
height Decimal?
weight Decimal?
created_at DateTime @default(now())
updated_at DateTime @updatedAt
created_at DateTime @default(now())
updated_at DateTime @updatedAt
appointments Appointment[]

@@map("patients")
}

model Appointment {
id Int @id @default(autoincrement())
appointment_type String @default("consulta")
id String @id @default(uuid())
appointment_type AppointmentType @default(QUERY)
examination String?
diagnosis_summary String?
scheduled_date DateTime
status String @default("pendente")
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
status AppointmentStatus @default(PENDING)
created_at DateTime @default(now())
updated_at DateTime @updatedAt()

doctor_id Int
doctor Doctor @relation(fields: [doctor_id], references: [id])
Expand All @@ -70,7 +108,7 @@ model Appointment {
model Doctor {
id Int @id @default(autoincrement())
name String
sex String
sex Sex
crm String @unique
cbo String?
cns String? @unique
Expand All @@ -80,7 +118,7 @@ model Doctor {
avatar_url String?
specialty String
working_days Int[]
status String @default("ativo")
status Status @default(ACTIVE)
appointments Appointment[]
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Expand Down
46 changes: 22 additions & 24 deletions src/app/infra/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { PrismaClient } from '@prisma/client';

import { Role } from '@shared/enums';
import { PrismaClient, Role, Sex } from '@prisma/client';

const prisma = new PrismaClient();

const users = [
{
name: 'Ana Silva',
email: 'ana.silva@hospital.com',
name: 'Admin Tester',
email: 'admin.tester@hospital.com',
password: 'admin123',
role: Role.ADMIN,
},
{
name: 'Carlos Pereira',
email: 'carlos.pereira@hospital.com',
name: 'Editor Tester',
email: 'editor.tester@hospital.com',
password: 'editor123',
role: Role.EDITOR,
},
{
name: 'Fernanda Costa',
email: 'fernanda.costa@hospital.com',
name: 'Clínico Tester',
email: 'clinico.tester@hospital.com',
password: 'clinico123',
role: Role.CLINICAL,
},
Expand All @@ -29,55 +27,55 @@ const pacientes = [
{
name: 'Alice Souza',
birth_date: new Date('1993-05-15'),
sex: 'feminino',
sex: Sex.FEMALE,
},
{
name: 'Bob Oliveira',
birth_date: new Date('1980-11-22'),
sex: 'masculino',
sex: Sex.MALE,
},
{
name: 'Carlos Martins',
birth_date: new Date('1975-01-10'),
sex: 'masculino',
sex: Sex.MALE,
},
{ name: 'Diana Lima', birth_date: new Date('1998-03-05'), sex: 'feminino' },
{ name: 'Diana Lima', birth_date: new Date('1998-03-05'), sex: Sex.FEMALE },
{
name: 'Eduardo Rocha',
birth_date: new Date('1990-09-30'),
sex: 'masculino',
sex: Sex.MALE,
},
{
name: 'Fernanda Gonçalves',
birth_date: new Date('1988-07-12'),
sex: 'feminino',
sex: Sex.FEMALE,
},
{
name: 'Gabriel Santos',
birth_date: new Date('1983-02-18'),
sex: 'masculino',
sex: Sex.MALE,
},
{
name: 'Helena Ferreira',
birth_date: new Date('1992-06-25'),
sex: 'feminino',
sex: Sex.FEMALE,
},
{
name: 'Igor Almeida',
birth_date: new Date('1985-12-15'),
sex: 'masculino',
sex: Sex.MALE,
},
{
name: 'Júlia Ribeiro',
birth_date: new Date('1996-04-20'),
sex: 'feminino',
sex: Sex.FEMALE,
},
];

const doctors = [
{
name: 'Dr. João Martins',
sex: 'masculino',
sex: Sex.MALE,
crm: '123456-SP',
phone: '5511999990001',
email: 'joao.martins@hospital.com',
Expand All @@ -88,7 +86,7 @@ const doctors = [
},
{
name: 'Dra. Maria Souza',
sex: 'feminino',
sex: Sex.FEMALE,
crm: '654321-RJ',
phone: '5511999990002',
email: 'maria.souza@hospital.com',
Expand All @@ -100,7 +98,7 @@ const doctors = [
},
{
name: 'Dr. Ricardo Alves',
sex: 'masculino',
sex: Sex.MALE,
crm: '789012-MG',
phone: '5511999990003',
email: 'ricardo.alves@hospital.com',
Expand All @@ -111,7 +109,7 @@ const doctors = [
},
{
name: 'Dra. Fernanda Oliveira',
sex: 'feminino',
sex: Sex.FEMALE,
crm: '321654-BA',
phone: '5511999990004',
email: 'fernanda.oliveira@hospital.com',
Expand All @@ -123,7 +121,7 @@ const doctors = [
},
{
name: 'Dr. Lucas Lima',
sex: 'masculino',
sex: Sex.MALE,
crm: '987654-RS',
phone: '5511999990005',
email: 'lucas.lima@hospital.com',
Expand Down
Loading
Loading