+
diff --git a/Frontend/tailwind.config.js b/Frontend/tailwind.config.js
index 6fa259a..59a171a 100644
--- a/Frontend/tailwind.config.js
+++ b/Frontend/tailwind.config.js
@@ -12,6 +12,30 @@ export default {
],
daisyui: {
themes: [
+ {
+ mytheme: {
+ "primary": "#f7911f",
+ "primary-content": "#e6d9ff",
+ "secondary": "#00c5ff",
+ "secondary-content": "#000e16",
+ "accent": "#00baff",
+ "accent-content": "#000d16",
+ "neutral": "#FFFFFF",
+ "neutral-content": "#cacaca",
+ "base-100": "#e6ffff",
+ "base-200": "#c8dede",
+ "base-300": "#5A3914",
+ "base-content": "#131616",
+ "info": "#009ec3",
+ "info-content": "#00090e",
+ "success": "#00c44b",
+ "success-content": "#000e02",
+ "warning": "#d89600",
+ "warning-content": "#110800",
+ "error": "#ff7a8b",
+ "error-content": "#160507",
+ }
+ },
"light",
"dark",
"cupcake",
From e89dca6ed5ba7b96e52104e4928f220ddaa07ec2 Mon Sep 17 00:00:00 2001
From: Hernan Casasola <67485423+GuidoMaxier@users.noreply.github.com>
Date: Thu, 29 Aug 2024 14:27:17 -0300
Subject: [PATCH 04/10] add: gitignore
para evitar conflicto con node moduls
---
.gitignore | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c59c4d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+### NODE MODULE ###
+node_modules
+Frontend/node_modules
+### VS CODE ###
+.vscode
+### GIT ###
From 8ae1cf9aa7150452d36a6e1518c4f2afcbc20274 Mon Sep 17 00:00:00 2001
From: Hernan Casasola <67485423+GuidoMaxier@users.noreply.github.com>
Date: Thu, 29 Aug 2024 14:42:32 -0300
Subject: [PATCH 05/10] config: auth
---
.gitignore | 8 ++++-
Frontend/src/Auth/Login.jsx | 66 ++++++++++++++++++-------------------
2 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/.gitignore b/.gitignore
index 3c59c4d..db52a62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,10 @@ node_modules
Frontend/node_modules
### VS CODE ###
.vscode
-### GIT ###
+### ENV ###
+.env
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+Frontend/.env
diff --git a/Frontend/src/Auth/Login.jsx b/Frontend/src/Auth/Login.jsx
index 8c6e361..405e1ba 100644
--- a/Frontend/src/Auth/Login.jsx
+++ b/Frontend/src/Auth/Login.jsx
@@ -14,7 +14,7 @@ function Login() {
event.preventDefault();
if (!isLoading) {
setIsLoading(true);
- fetch(`${import.meta.env.VITE_API_BASE_URL}api-auth/`, {
+ fetch(`${import.meta.env.VITE_API_BASE_URL}auth/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -31,38 +31,38 @@ function Login() {
return response.json();
})
.then((responseData) => {
- login(responseData.token);
- if (responseData.token) {
- fetch(
- `${
- import.meta.env.VITE_API_BASE_URL
- }users/profiles/profile_data/`,
- {
- method: "GET",
- headers: {
- Authorization: `Token ${responseData.token}`,
- },
- }
- )
- .then((profileResponse) => {
- if (!profileResponse.ok) {
- throw new Error(
- "Error al obtener id de usuario"
- );
- }
- return profileResponse.json();
- })
- .then((profileData) =>
- login(responseData.token, profileData.user__id)
- )
- .catch((error) => {
- console.error(
- "Error al obtener id de usuario",
- error
- );
- setIsError(true);
- });
- }
+ login(responseData.jwt);
+ // if (responseData.jwt) {
+ // fetch(
+ // `${
+ // import.meta.env.VITE_API_BASE_URL
+ // }users/profiles/profile_data/`,
+ // {
+ // method: "GET",
+ // headers: {
+ // Authorization: `Token ${responseData.jwt}`,
+ // },
+ // }
+ // )
+ // .then((profileResponse) => {
+ // if (!profileResponse.ok) {
+ // throw new Error(
+ // "Error al obtener id de usuario"
+ // );
+ // }
+ // return profileResponse.json();
+ // })
+ // .then((profileData) =>
+ // login(responseData.token, profileData.user__id)
+ // )
+ // .catch((error) => {
+ // console.error(
+ // "Error al obtener id de usuario",
+ // error
+ // );
+ // setIsError(true);
+ // });
+ // }
})
.catch((error) => {
console.error("Error al iniciar sesión", error);
From b25acfe96adc41ca9cd9ca327d57ae2e94d1d3c5 Mon Sep 17 00:00:00 2001
From: Yosmarli Parica <101285117+Yosmarli@users.noreply.github.com>
Date: Mon, 16 Sep 2024 15:50:22 -0300
Subject: [PATCH 06/10] Update README.md
---
README.md | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 134 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 7262e68..680510f 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,134 @@
-# s17-15-t-java-react
-Simulacion No Counrty s17-15-t-java-react
+
💓 Equipo s17-15-t-java-react | No Country 🌎
+
+
+
+
+
+
+
📑 ¿QUÉ ES VET CARE? 🌈
+
+
+
+ Vet Care es un sitio web que trae una solución segura, rápida y sencilla para gestionar la información de tus pacientes, sus propietarios, procesos e historial médico, en tú hospital veterinario.
+
+
+
+
+
+
¿Por qué vet care? 💡
+
+
+
Porque ofrece un flujo completo en el proceso de atención de los pacientes.
+
Porque puedes controlar los registros y acceso de los veterinarios que trabajan en la veterinaria.
+
Porque es sencillo de usar.
+
Porque pudes personalizarla de acuerdo a las necesidades de tu negocio.
+
+
+
+
+
+
🌐 Deploy Frontend 🌟
+
+
+
+
+
+
+
🎨 Diseño 🎨
+
+
+
+
+
+
+
+
✨ Equipo ✨
+
+
+
+
+ Team Leader
+
+
+ Micaela Pequeño
+
+
+ |
+
+
+ QA Tester
+
+
+ Yosmarli Parica
+
+
+ |
+
+
+ Diseño UX/UI
+
+
+ Laura Leyes
+
+
+ |
+
+
+ Diseño UX/UI
+
+
+ Malena Jara
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
🛠️ Tecnologías Utilizadas ⚡
+
+
+
+
+
+
+
+
+
+
+
+
+
From 813ce477f4a02fba12589f7f1b93efa2539b6630 Mon Sep 17 00:00:00 2001
From: Yosmarli Parica <101285117+Yosmarli@users.noreply.github.com>
Date: Mon, 16 Sep 2024 17:24:43 -0300
Subject: [PATCH 07/10] Update README.md
---
README.md | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 109 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 680510f..30f1ddd 100644
--- a/README.md
+++ b/README.md
@@ -3,13 +3,13 @@
-📑 ¿QUÉ ES VET CARE? 🌈
+📑 ¿QUÉ ES VET CARE? 🐶🐱
@@ -19,7 +19,7 @@
-
¿Por qué vet care? 💡
+
¿PORQUÉ VET CARE? 💡
Porque ofrece un flujo completo en el proceso de atención de los pacientes.
@@ -44,6 +44,7 @@
🎨 Diseño 🎨
+
🌈 Diseño en Figma 🖌️
[ Link al Diseño Figma ]
@@ -51,6 +52,18 @@
+
+
🚀Swagger:🔥
+
+
+
+
+
+
+
✨ Equipo ✨
@@ -107,20 +120,109 @@
+
+
+
+
+
+
+
+ Backend
+
+
+ Liza Daneris Medina
+
+
+ |
+
+
+ Backend
+
+
+ Anthony P
+
+
+ |
+
+
+ Backend
+
+
+ Alexis Alejandro Calderon
+
+
+ |
+
+
+ Frontend
+
+
+ Hernán Casasola
+
+
+ |
+
+
+
+
+
🛠️ Tecnologías Utilizadas ⚡
+
+
+
Backend
+
+
+
+![Spring](https://img.shields.io/badge/spring-%236DB33F.svg?style=for-the-badge&logo=spring&logoColor=white)
+![JWT](https://img.shields.io/badge/JWT-black?style=for-the-badge&logo=JSON%20web%20tokens)
+![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)
+![Swagger](https://img.shields.io/badge/-Swagger-%23Clojure?style=for-the-badge&logo=swagger&logoColor=white)
+![Kubernetes](https://img.shields.io/badge/-Kubernetes-%326CE5?style=for-the-badge&logo=kubernetes&logoColor=white)
+![Render](https://img.shields.io/badge/-Render-%326CE5?style=for-the-badge&logo=render&logoColor=white)
+![Spring Boot](https://img.shields.io/badge/-Springboot-%6DB33F?style=for-the-badge&logo=springboot&logoColor=white)
+
+
+
Frontend
+
+
+
+![React](https://img.shields.io/static/v1?style=for-the-badge&message=React&color=222222&logo=React&logoColor=61DAFB&label=)
+![React Router](https://img.shields.io/badge/React_Router-CA4245?style=for-the-badge&logo=react-router&logoColor=white)
+![TailwindCSS](https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white)
+![DaisyUI](https://img.shields.io/badge/DaisyUI-%5A0EF8.svg?style=for-the-badge&logo=DaisyUI&logoColor=white)
-
-
🛠️ Tecnologías Utilizadas ⚡
-
-
+
+
+
+
+
+
+
+
From 06a9976745756e389c2bdc23ad94154933252638 Mon Sep 17 00:00:00 2001
From: Alexis Alejandro Calderon
Date: Wed, 18 Sep 2024 03:19:18 -0300
Subject: [PATCH 08/10] Get hospitalization by id pet
---
.../Controller/HospitalizationController.java | 7 +++
.../HospitalizationDtoResponse.java | 18 +++++++
.../Repository/HospitalizationRepository.java | 8 ++++
.../Service/HospitalizationService.java | 47 +++++++++++++++++++
4 files changed, 80 insertions(+)
create mode 100644 Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Dto/hospitalization/HospitalizationDtoResponse.java
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/HospitalizationController.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/HospitalizationController.java
index 5caf662..b6ff798 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/HospitalizationController.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/HospitalizationController.java
@@ -1,6 +1,7 @@
package com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Controller;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationCreationResponse;
+import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationDtoResponse;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationRequest;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationResponse;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.Hospitalization;
@@ -172,4 +173,10 @@ public ResponseEntity> getHospitalizationByComplem
public ResponseEntity updateHospitalization(@PathVariable Long hospitalizationId, @RequestBody HospitalizationRequest dto) {
return ResponseEntity.ok(hospitalizationService.updateHospitalization(hospitalizationId, dto));
}
+
+ @GetMapping("/by-pet/{petId}")
+ public ResponseEntity> getHospitalizationsByPetId(@PathVariable Long petId) {
+ List hospitalizations = hospitalizationService.getHospitalizationsByPetId(petId);
+ return ResponseEntity.ok(hospitalizations);
+ }
}
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Dto/hospitalization/HospitalizationDtoResponse.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Dto/hospitalization/HospitalizationDtoResponse.java
new file mode 100644
index 0000000..4b67542
--- /dev/null
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Dto/hospitalization/HospitalizationDtoResponse.java
@@ -0,0 +1,18 @@
+package com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.List;
+
+public record HospitalizationDtoResponse(
+
+ Long id,
+ LocalDate startDate,
+ LocalDate endDate,
+ BigDecimal hospitalizationCost,
+ boolean paid,
+ List treatmentIds, // Lista de IDs de tratamientos
+ List complementaryStudies // Lista de IDs de estudios complementario
+
+) {
+}
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/HospitalizationRepository.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/HospitalizationRepository.java
index bf58b79..8bf7a51 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/HospitalizationRepository.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/HospitalizationRepository.java
@@ -2,6 +2,8 @@
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.Hospitalization;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@@ -13,4 +15,10 @@ public interface HospitalizationRepository extends JpaRepository findByTreatments_Id(Long treatmentId);
List findByComplementaryStudies_Id(Long complementaryStudyId);
+
+ @Query("SELECT h FROM Hospitalization h JOIN h.complementaryStudies cs JOIN cs.consultation c WHERE c.pet.id = :petId")
+ List findHospitalizationsByPetId(@Param("petId") Long petId);
+
+ @Query("SELECT h FROM Hospitalization h JOIN h.treatments t JOIN t.diagnosis d JOIN d.consultation c WHERE c.pet.id = :petId")
+ List findHospitalizationsByPetIdTreatment(@Param("petId") Long petId);
}
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/HospitalizationService.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/HospitalizationService.java
index d7eeb9f..34bcd36 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/HospitalizationService.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/HospitalizationService.java
@@ -1,8 +1,10 @@
package com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Service;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationCreationResponse;
+import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationDtoResponse;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationRequest;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Dto.hospitalization.HospitalizationResponse;
+import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.ComplementaryStudy;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.Hospitalization;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.Treatment;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Mapper.HospitalizationMapper;
@@ -16,7 +18,10 @@
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@@ -111,4 +116,46 @@ private BigDecimal calculateCost(LocalDate startDate, LocalDate endDate) {
}
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
}
+
+ // Convertir entidad Hospitalization a DTO
+ private HospitalizationDtoResponse convertToDto(Hospitalization hospitalization) {
+ return new HospitalizationDtoResponse(
+ hospitalization.getId(),
+ hospitalization.getStartDate(),
+ hospitalization.getEnd_date(), // Usar el nombre del atributo en la entidad
+ hospitalization.getHospitalizationCost(),
+ hospitalization.isPaid(),
+ hospitalization.getTreatments().stream()
+ .map(Treatment::getId)
+ .toList(), // Usar Stream.toList()
+ hospitalization.getComplementaryStudies().stream()
+ .map(ComplementaryStudy::getId) // Asegúrate de que `getId()` exista
+ .toList() // Usar Stream.toList()
+ );
+ }
+ // Obtener hospitalizaciones por ID de mascota y devolver como DTO
+ // public List getHospitalizationsByPetId(Long petId) {
+ // List hospitalizations = hospitalizationRepository.findHospitalizationsByPetId(petId);
+ // return hospitalizations.stream()
+ // .map(this::convertToDto)
+ // .collect(Collectors.toList());
+ // }
+
+ public List getHospitalizationsByPetId(Long petId) {
+ // Obtener hospitalizaciones desde ComplementaryStudies
+ List hospitalizationsByStudies = hospitalizationRepository.findHospitalizationsByPetId(petId);
+
+ // Obtener hospitalizaciones desde Treatment y Diagnosis
+ List hospitalizationsByTreatment = hospitalizationRepository.findHospitalizationsByPetIdTreatment(petId);
+
+ // Unir ambas listas y eliminar duplicados
+ Set combinedHospitalizations = new HashSet<>(hospitalizationsByStudies);
+ combinedHospitalizations.addAll(hospitalizationsByTreatment);
+
+ // Convertir a DTO
+ return combinedHospitalizations.stream()
+ .map(this::convertToDto)
+ .collect(Collectors.toList());
+ }
+
}
\ No newline at end of file
From 51b818b6a7eafa8f74fbe6bcca5e6a3ef3cd4a58 Mon Sep 17 00:00:00 2001
From: An7h0ny1 <91570972+An7h0ny1@users.noreply.github.com>
Date: Wed, 18 Sep 2024 13:23:37 -0500
Subject: [PATCH 09/10] merge main
---
.github/workflows/docker-image.yml | 2 +
README.md | 232 ++++++++++++++++++++++++++++-
2 files changed, 232 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
index ef91d9f..5026b52 100644
--- a/.github/workflows/docker-image.yml
+++ b/.github/workflows/docker-image.yml
@@ -4,9 +4,11 @@ on:
push:
branches:
- dev
+ - main
pull_request:
branches:
- dev
+ - main
jobs:
build-and-deploy:
diff --git a/README.md b/README.md
index 7262e68..f4db3ac 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,230 @@
-# s17-15-t-java-react
-Simulacion No Counrty s17-15-t-java-react
+💓 Equipo s17-15-t-java-react | No Country 🌎
+
+
+
+
+
+
+📑 ¿QUÉ ES VET CARE? 🐶🐱
+
+
+
+ Vet Care es un sitio web que trae una solución segura, rápida y sencilla para gestionar la información de tus pacientes, sus propietarios, procesos e historial médico, en tú hospital veterinario.
+
+
+
+
+
+¿PORQUÉ VET CARE? 💡
+
+
+
Porque ofrece un flujo completo en el proceso de atención de los pacientes.
+
Porque puedes controlar los registros y acceso de los veterinarios que trabajan en la veterinaria.
+
Porque es sencillo de usar.
+
Porque pudes personalizarla de acuerdo a las necesidades de tu negocio.
+
+
+
+
+
+
🌐 Deploy Frontend 🌟
+
+
+
+
+
+
+
🎨 Diseño 🎨
+
+
+
+
+
+
+
+
+
🚀Swagger:🔥
+
+
+
+
+
+
+
+
+✨ Equipo ✨
+
+
+
+
+ Team Leader
+
+
+ Micaela Pequeño
+
+
+ |
+
+
+ QA Tester
+
+
+ Yosmarli Parica
+
+
+ |
+
+
+ Diseño UX/UI
+
+
+ Laura Leyes
+
+
+ |
+
+
+ Diseño UX/UI
+
+
+ Malena Jara
+
+
+ |
+
+
+
+
+
+
+
+ Backend
+
+
+ Liza Daneris Medina
+
+
+ |
+
+
+ Backend
+
+
+ Anthony P
+
+
+ |
+
+
+ Backend
+
+
+ Alexis Alejandro Calderon
+
+
+ |
+
+
+ Frontend
+
+
+ Hernán Casasola
+
+
+ |
+
+
+
+
+
+
+
🛠️ Tecnologías Utilizadas ⚡
+
+
+
+
Backend
+
+
+
+
+![Spring](https://img.shields.io/badge/spring-%236DB33F.svg?style=for-the-badge&logo=spring&logoColor=white)
+![JWT](https://img.shields.io/badge/JWT-black?style=for-the-badge&logo=JSON%20web%20tokens)
+![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)
+![Swagger](https://img.shields.io/badge/-Swagger-%23Clojure?style=for-the-badge&logo=swagger&logoColor=white)
+![Kubernetes](https://img.shields.io/badge/-Kubernetes-%326CE5?style=for-the-badge&logo=kubernetes&logoColor=white)
+![Render](https://img.shields.io/badge/-Render-%326CE5?style=for-the-badge&logo=render&logoColor=white)
+![Spring Boot](https://img.shields.io/badge/-Springboot-%6DB33F?style=for-the-badge&logo=springboot&logoColor=white)
+
+
+
+
+
+
+
Frontend
+
+
+
+
+![React](https://img.shields.io/static/v1?style=for-the-badge&message=React&color=222222&logo=React&logoColor=61DAFB&label=)
+![React Router](https://img.shields.io/badge/React_Router-CA4245?style=for-the-badge&logo=react-router&logoColor=white)
+![TailwindCSS](https://img.shields.io/badge/tailwindcss-%2338B2AC.svg?style=for-the-badge&logo=tailwind-css&logoColor=white)
+![DaisyUI](https://img.shields.io/badge/DaisyUI-%5A0EF8.svg?style=for-the-badge&logo=DaisyUI&logoColor=white)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From d26752aa3b36ccec9a184da6e1a40df38a8944b2 Mon Sep 17 00:00:00 2001
From: Alexis Alejandro Calderon
Date: Wed, 18 Sep 2024 22:58:57 -0300
Subject: [PATCH 10/10] fix StudyComplementary get By IDpet
---
.../ComplementaryStudyController.java | 16 ++++++++++++++-
.../Mapper/ComplementaryStudyMapper.java | 20 +++++++++++++++++++
.../ComplementaryStudyRepository.java | 16 +++++++++++++++
.../Service/ComplementaryStudyService.java | 18 ++++++++++++++---
4 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/ComplementaryStudyController.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/ComplementaryStudyController.java
index b6af9ab..8d17437 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/ComplementaryStudyController.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Controller/ComplementaryStudyController.java
@@ -11,6 +11,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -152,9 +153,21 @@ public ResponseEntity getComplementaryStudyById(@PathVariable Lon
}
)
public ResponseEntity> getAllStudiesByPetId(@PathVariable Long petId) {
- return ResponseEntity.ok(complementaryStudyService.getAllStudiesByPetId(petId));
+ try {
+ List studyResponses = complementaryStudyService.getAllStudiesByPetId(petId);
+ return new ResponseEntity<>(studyResponses, HttpStatus.OK);
+ } catch (EntityNotFoundException e) {
+ return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
+ } catch (Exception e) {
+ return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
+ }
}
+ // public ResponseEntity> getAllStudiesByPetId(@PathVariable Long petId) {
+ // List studies = complementaryStudyService.getAllStudiesByPetId(petId);
+ // return ResponseEntity.ok(studies);
+ // }
+
@GetMapping("/owner/{ownerId}")
@Operation(
summary = "Get all the Complementary Studies by owner.",
@@ -203,4 +216,5 @@ public ResponseEntity> getAllStudiesByState(@PathVariable En
List studies = complementaryStudyService.getAllStudiesByState(studyState);
return ResponseEntity.ok(studies);
}
+
}
\ No newline at end of file
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Mapper/ComplementaryStudyMapper.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Mapper/ComplementaryStudyMapper.java
index 09f3bb0..0a7286a 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Mapper/ComplementaryStudyMapper.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Mapper/ComplementaryStudyMapper.java
@@ -88,4 +88,24 @@ public List toDtoList(List studyList){
.collect(Collectors.toList());
}
+ public StudyResponse toDtoResponseByPet(ComplementaryStudy entity) {
+ return new StudyResponse(
+ entity.getId(),
+ entity.getExaminationDate(),
+ entity.getStudyType(),
+ entity.getStudyResult(),
+ entity.getStudyFile(),
+ entity.getStudyState(),
+ entity.getStudyCost(),
+ entity.getConsultation() != null ? entity.getConsultation().getId() : null, // Relación con Consultation
+ null, // No necesitamos Diagnosis aquí
+ entity.getHospitalization() != null ? entity.getHospitalization().getId() : null
+ );
+ }
+
+ public List toDtoListByPet(List studyList) {
+ return studyList.stream()
+ .map(this::toDtoResponseByPet) // Usa el nuevo método para cada estudio
+ .collect(Collectors.toList());
+ }
}
\ No newline at end of file
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/ComplementaryStudyRepository.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/ComplementaryStudyRepository.java
index 3efccb6..c76d3d2 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/ComplementaryStudyRepository.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Repository/ComplementaryStudyRepository.java
@@ -3,10 +3,26 @@
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.ComplementaryStudy;
import com.gestor_clinica_veterinaria.VeterinaryHospitalManager.Entity.Enum.EnumStudyState;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ComplementaryStudyRepository extends JpaRepository {
List findByStudyState(EnumStudyState studyState);
+
+ @Query("SELECT cs FROM ComplementaryStudy cs WHERE cs.consultation.pet.id = :petId")
+ List findAllByPetId(@Param("petId") Long petId);
+ // @Query("SELECT cs FROM ComplementaryStudy cs " +
+ // "JOIN cs.consultation c " +
+ // "JOIN c.pet p " +
+ // "WHERE p.id = :petId")
+ // List findAllByPetId(@Param("petId") Long petId);
+//
+ // @Query("SELECT cs FROM ComplementaryStudy cs " +
+ // "JOIN cs.consultation c " +
+ // "WHERE c.pet.id = :petId")
+ // List findAllByPetId(@Param("petId") Long petId);
+
}
diff --git a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/ComplementaryStudyService.java b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/ComplementaryStudyService.java
index 0a77e91..a4c6edb 100644
--- a/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/ComplementaryStudyService.java
+++ b/Backend/src/main/java/com/gestor_clinica_veterinaria/VeterinaryHospitalManager/Service/ComplementaryStudyService.java
@@ -86,8 +86,17 @@ public StudyResponse getStudyById(Long studyId){
new ComplementaryStudyNotFoundException("El id del estudio complementario ingresao es incorrecto o no existe")));
}
- public List getAllStudiesByPetId(Long petId){
- return complementaryStudyMapper.toDtoList(complementaryStudyRepository.findAllById(Collections.singleton(petId)));
+ // public List getAllStudiesByPetId(Long petId){
+ // return complementaryStudyMapper.toDtoList(complementaryStudyRepository.findAllById(Collections.singleton(petId)));
+ // }
+
+ // public List getAllStudiesByPetId(Long petId) {
+ // List studies = complementaryStudyRepository.findAllByPetId(petId);
+ // return complementaryStudyMapper.toDtoList(studies);
+ // }
+ public List getAllStudiesByPetId(Long petId) {
+ List studies = complementaryStudyRepository.findAllByPetId(petId);
+ return complementaryStudyMapper.toDtoListByPet(studies); // Usar el nuevo método de mapeo
}
public List getAllStudiesByOwnerId(Long ownerId){
return complementaryStudyMapper.toDtoList(complementaryStudyRepository.findAllById(Collections.singleton(ownerId)));
@@ -137,5 +146,8 @@ public StudyResponse updateStudy(Long studyId, StudyRequest dto) {
throw new TreatmentNotFoundException("No se ha podido actualizar el tratamiento porque el id ingresado es incorrecto o no existe: " + studyId);
}
}
-
+ // public List getAllStudiesByPetId2(Long petId) {
+ // List studies = complementaryStudyRepository.findAllByPetId2(petId);
+ // return complementaryStudyMapper.toDtoList(studies);
+ // }
}
\ No newline at end of file