Skip to content

Commit

Permalink
arreglos
Browse files Browse the repository at this point in the history
  • Loading branch information
An7h0ny1 committed Sep 5, 2024
1 parent e2311d6 commit 19f759d
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

public record InvoiceDto(
LocalDate invoiceDate,
BigDecimal totalCost
BigDecimal totalCost,
String veterinarianName,
String ownerName,
String petName
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

import java.math.BigDecimal;
import java.time.LocalDate;

public record RequestCreateSurgery(
Expand Down Expand Up @@ -38,7 +39,7 @@ public record RequestCreateSurgery(
String surgeryProcedure,
String observations,
String postSurgeryRecommendations,
Double surgeryCost
BigDecimal surgeryCost
//Long consultationId


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

import java.math.BigDecimal;
import java.time.LocalDate;

public record RequestEditSurgery(
Expand All @@ -29,6 +30,6 @@ public record RequestEditSurgery(

@NotNull(message = "surgeryCost cannot be null")
@Positive(message = "surgeryCost must be a positive number")
Double surgeryCost
BigDecimal surgeryCost
) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.surgery;

import java.math.BigDecimal;
import java.time.LocalDate;

public record ResponseSurgery(
Expand All @@ -10,7 +11,7 @@ public record ResponseSurgery(
String surgeryProcedure,
String observations,
String postSurgeryRecommendations,
Double surgeryCost
BigDecimal surgeryCost
// Long consultationId // Solo se usa para asociar la cirugía a una consulta existente
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class ConsultationEntity{
private EnumState state;
private BigDecimal costConsultation;


@ManyToOne(fetch = FetchType.LAZY, targetEntity = Veterinarian.class)
@JoinColumn(name = "veterinarian_id")
private Veterinarian veterinarian;

@ManyToOne(fetch = FetchType.LAZY,targetEntity = Pet.class)
@JoinColumn(name = "pet_id")
private Pet pet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public class InvoiceEntity {

private BigDecimal totalCost;

private String veterinarianName;
private String ownerName;
private String petName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
@Entity
Expand All @@ -24,7 +25,7 @@ public class Surgery {
private String surgeryProcedure;
private String observations;
private String postSurgeryRecommendations;
private Double surgeryCost;
private BigDecimal surgeryCost;


/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public InvoiceEntity toEntity(InvoiceDto invoiceDto) {

public InvoiceDto toDto(InvoiceEntity invoiceEntity) {
return new InvoiceDto(invoiceEntity.getInvoiceDate(),
invoiceEntity.getTotalCost());
invoiceEntity.getTotalCost(),
invoiceEntity.getVeterinarianName(),
invoiceEntity.getOwnerName(),
invoiceEntity.getPetName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.Consultation.ConsultationDto;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.invoice.InvoiceDto;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.ConsultationEntity;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.DiagnosticEntity;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.InvoiceEntity;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.Treatment;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.*;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.study.ComplementaryStudy;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Mapper.InvoiceMapper;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Repository.ConsultationRepository;
Expand Down Expand Up @@ -36,43 +33,55 @@ public InvoiceDto addInvoice(Long consultationId) {

BigDecimal total = consultationEntity.getCostConsultation();

// Acumular costos de los diagnósticos
for (DiagnosticEntity diagnostic : consultationEntity.getDiagnostics()) {

// Acumula el costo de las cirugías del diagnóstico
/*total = total.add(diagnostic.getSurgery().stream()
.map(Surgery::getCost)
.reduce(BigDecimal.ZERO, BigDecimal::add));*/
total = total.add(diagnostic.getSurgerys().stream()
.map(Surgery::getSurgeryCost)
.reduce(BigDecimal.ZERO, BigDecimal::add));

// Acumula el costo de los tratamientos del diagnóstico
for (Treatment treatment : diagnostic.getTreatments()) {
total = total.add(treatment.getTreatmentCost());

// Acumula el costo de las hospitalizaciones del tratamiento
/*for (Hospitalization hospitalization : treatment.getHospitalizations()) {
total = total.add(hospitalization.getCost());
// Verifica si el tratamiento está asociado a una hospitalización
if (treatment.getHospitalization() != null) {
Hospitalization hospitalization = treatment.getHospitalization();

// Acumula el costo base de la hospitalización
total = total.add(hospitalization.getHospitalizationCost());

// Acumula el costo de los tratamientos de la hospitalización
total = total.add(hospitalization.getTreatments().stream()
.map(Treatment::getTreatmentCost)
.reduce(BigDecimal.ZERO, BigDecimal::add));

// Acumula el costo de los estudios complementarios de la hospitalización
total = total.add(hospitalization.getComplementaryStudies().stream()
.map(ComplementaryStudy::getCost)
.map(ComplementaryStudy::getStudyCost)
.reduce(BigDecimal.ZERO, BigDecimal::add));
}*/
}
}

// Acumula el costo de los estudios complementarios del diagnóstico
/* total = total.add(diagnostic.getComplementaryStudies().stream()
total = total.add(diagnostic.getComplementaryStudies().stream()
.map(ComplementaryStudy::getStudyCost)
.reduce(BigDecimal.ZERO, BigDecimal::add));*/
.reduce(BigDecimal.ZERO, BigDecimal::add));
}

// Acumula el costo de los estudios complementarios fuera de los diagnósticos
/*total = total.add(consultationEntity.getComplementaryStudies().stream()
total = total.add(consultationEntity.getComplementaryStudies().stream()
.map(ComplementaryStudy::getStudyCost)
.reduce(BigDecimal.ZERO, BigDecimal::add));*/
.reduce(BigDecimal.ZERO, BigDecimal::add));

InvoiceEntity invoiceEntity = new InvoiceEntity();
invoiceEntity.setConsultation(consultationEntity);
invoiceEntity.setTotalCost(total);
invoiceEntity.setInvoiceDate(LocalDate.now());
invoiceEntity.setVeterinarianName(consultationEntity.getVeterinarian().getUsername());
invoiceEntity.setPetName(consultationEntity.getPet().getName());
invoiceEntity.setOwnerName(consultationEntity.getPet().getOwner().getName());

InvoiceEntity savedInvoice = invoiceRepository.save(invoiceEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void main(String[] args) {
@Override
public void run(String... args) throws Exception {

/*jdbcTemplate.update("INSERT INTO permissions (id, name) VALUES (?, ?) ON CONFLICT (id) DO NOTHING", 1, "CREATE");
jdbcTemplate.update("INSERT INTO permissions (id, name) VALUES (?, ?) ON CONFLICT (id) DO NOTHING", 1, "CREATE");
jdbcTemplate.update("INSERT INTO permissions (id, name) VALUES (?, ?) ON CONFLICT (id) DO NOTHING", 2, "READ");
jdbcTemplate.update("INSERT INTO permissions (id, name) VALUES (?, ?) ON CONFLICT (id) DO NOTHING", 3, "WRITE");
jdbcTemplate.update("INSERT INTO permissions (id, name) VALUES (?, ?) ON CONFLICT (id) DO NOTHING", 4, "DELETE");
Expand All @@ -40,14 +40,28 @@ public void run(String... args) throws Exception {
jdbcTemplate.update("INSERT INTO role_permission (role_id, permission_id) VALUES (?, ?) ON CONFLICT DO NOTHING", 2, 2);

// Insertar usuario administrador
jdbcTemplate.update("INSERT INTO users (id, username, password, email, is_enabled, account_no_expired, account_no_locked, credentials_no_expired) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (id) DO NOTHING",
100000, "admin", "$2a$10$Dxnp0wJeF8L9Ftd8./ExcuaJ62jKKVezB3gvBLcgo1qNOjAnR6QJi", "admin@example.com", true, true, true, true);
/*jdbcTemplate.update("INSERT INTO users (id, username, password, email, is_enabled, account_no_expired, account_no_locked, credentials_no_expired) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (id) DO NOTHING",
100000, "admin", "$2a$10$Dxnp0wJeF8L9Ftd8./ExcuaJ62jKKVezB3gvBLcgo1qNOjAnR6QJi", "admin@example.com", true, true, true, true);*/

Veterinarian veterinarian = new Veterinarian();
veterinarian.setUsername("admin");
veterinarian.setPassword("$2a$10$Dxnp0wJeF8L9Ftd8./ExcuaJ62jKKVezB3gvBLcgo1qNOjAnR6QJi");
veterinarian.setEmail("admin@example.com");
veterinarian.setEnabled(true);
veterinarian.setAccountNoExpired(true);
veterinarian.setAccountNoLocked(true);
veterinarian.setCredentialsNoExpired(true);
veterinarian.setLastName("admin");
veterinarian.setSpecialty("admin");
veterinarian.setProfessionalLicenceNumber("12345");

Veterinarian savedVeterinarian = veterinarianRepository.save(veterinarian);
Long veterinarianId = savedVeterinarian.getId();
// Relacionar el usuario administrador con el rol ADMIN
jdbcTemplate.update("INSERT INTO users_roles (user_id, role_id) VALUES (?, ?) ON CONFLICT DO NOTHING", 100000, 1);*/
jdbcTemplate.update("INSERT INTO users_roles (user_id, role_id) VALUES (?, ?) ON CONFLICT DO NOTHING", veterinarianId, 1);


// Insertar permisos
/*// Insertar permisos
jdbcTemplate.update("INSERT IGNORE INTO permissions (id, name) VALUES (?, ?)", 1, "CREATE");
jdbcTemplate.update("INSERT IGNORE INTO permissions (id, name) VALUES (?, ?)", 2, "READ");
jdbcTemplate.update("INSERT IGNORE INTO permissions (id, name) VALUES (?, ?)", 3, "WRITE");
Expand All @@ -68,7 +82,7 @@ public void run(String... args) throws Exception {
/*jdbcTemplate.update("INSERT IGNORE INTO veterinarians (id, username, password, email, is_enabled, account_no_expired, account_no_locked, credentials_no_expired, last_name, specialty, professional_licence_number) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
100000, "admin", "$2a$10$Dxnp0wJeF8L9Ftd8./ExcuaJ62jKKVezB3gvBLcgo1qNOjAnR6QJi", "admin@example.com", true, true, true, true, "admin", "admin", "12345");*/

Veterinarian veterinarian = new Veterinarian();
/*Veterinarian veterinarian = new Veterinarian();
veterinarian.setUsername("admin");
veterinarian.setPassword("$2a$10$Dxnp0wJeF8L9Ftd8./ExcuaJ62jKKVezB3gvBLcgo1qNOjAnR6QJi");
veterinarian.setEmail("admin@example.com");
Expand All @@ -83,6 +97,6 @@ public void run(String... args) throws Exception {
Veterinarian savedVeterinarian = veterinarianRepository.save(veterinarian);
Long veterinarianId = savedVeterinarian.getId();
// Relacionar el usuario administrador con el rol ADMIN
jdbcTemplate.update("INSERT IGNORE INTO users_roles (user_id, role_id) VALUES (?, ?)", veterinarianId, 1);
jdbcTemplate.update("INSERT IGNORE INTO users_roles (user_id, role_id) VALUES (?, ?)", veterinarianId, 1);*/
}
}
41 changes: 20 additions & 21 deletions Backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,32 @@ spring.application.name=VeterinaryHospitalManager


## DATABASE POSTGRESQL
#
#spring.datasource.initialization-mode=always
#
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true
#
#spring.datasource.url=jdbc:postgresql://dpg-crb14pjtq21c73ceivo0-a.oregon-postgres.render.com/vet_db_b64t
#spring.datasource.username=vet_db_b64t_user
#spring.datasource.password=vHhYD7upNXyc3WhTxvYgsJbUham3Vqea
#spring.datasource.driver-class-name=org.postgresql.Driver
#
#
## JPA/Hibernate
#spring.jpa.hibernate.ddl-auto=update
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

spring.datasource.initialization-mode=always

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

spring.datasource.url=jdbc:mysql://localhost:3306/vet
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:postgresql://dpg-crb14pjtq21c73ceivo0-a.oregon-postgres.render.com/vet_db_b64t
spring.datasource.username=vet_db_b64t_user
spring.datasource.password=vHhYD7upNXyc3WhTxvYgsJbUham3Vqea
spring.datasource.driver-class-name=org.postgresql.Driver


# JPA/Hibernate
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

#
#spring.datasource.url=jdbc:mysql://localhost:3306/vet
#spring.datasource.username=root
#spring.datasource.password=
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#
#
## JPA/Hibernate
#spring.jpa.hibernate.ddl-auto=create-drop
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect



Expand Down

0 comments on commit 19f759d

Please sign in to comment.