Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lizzmedina committed Sep 19, 2024
2 parents 6f629b3 + 702e537 commit aad0aee
Show file tree
Hide file tree
Showing 43 changed files with 6,608 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main

jobs:
build-and-deploy:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,9 +153,21 @@ public ResponseEntity<StudyResponse> getComplementaryStudyById(@PathVariable Lon
}
)
public ResponseEntity<List<StudyResponse>> getAllStudiesByPetId(@PathVariable Long petId) {
return ResponseEntity.ok(complementaryStudyService.getAllStudiesByPetId(petId));
try {
List<StudyResponse> 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<List<StudyResponse>> getAllStudiesByPetId(@PathVariable Long petId) {
// List<StudyResponse> studies = complementaryStudyService.getAllStudiesByPetId(petId);
// return ResponseEntity.ok(studies);
// }

@GetMapping("/owner/{ownerId}")
@Operation(
summary = "Get all the Complementary Studies by owner.",
Expand Down Expand Up @@ -203,4 +216,5 @@ public ResponseEntity<List<StudyResponse>> getAllStudiesByState(@PathVariable En
List<StudyResponse> studies = complementaryStudyService.getAllStudiesByState(studyState);
return ResponseEntity.ok(studies);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -172,4 +173,10 @@ public ResponseEntity<List<HospitalizationResponse>> getHospitalizationByComplem
public ResponseEntity<HospitalizationResponse> updateHospitalization(@PathVariable Long hospitalizationId, @RequestBody HospitalizationRequest dto) {
return ResponseEntity.ok(hospitalizationService.updateHospitalization(hospitalizationId, dto));
}

@GetMapping("/by-pet/{petId}")
public ResponseEntity<List<HospitalizationDtoResponse>> getHospitalizationsByPetId(@PathVariable Long petId) {
List<HospitalizationDtoResponse> hospitalizations = hospitalizationService.getHospitalizationsByPetId(petId);
return ResponseEntity.ok(hospitalizations);
}
}
Original file line number Diff line number Diff line change
@@ -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<Long> treatmentIds, // Lista de IDs de tratamientos
List<Long> complementaryStudies // Lista de IDs de estudios complementario

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@ public List<StudyResponse> toDtoList(List<ComplementaryStudy> 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<StudyResponse> toDtoListByPet(List<ComplementaryStudy> studyList) {
return studyList.stream()
.map(this::toDtoResponseByPet) // Usa el nuevo método para cada estudio
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComplementaryStudy, Long> {
List<ComplementaryStudy> findByStudyState(EnumStudyState studyState);

@Query("SELECT cs FROM ComplementaryStudy cs WHERE cs.consultation.pet.id = :petId")
List<ComplementaryStudy> findAllByPetId(@Param("petId") Long petId);
// @Query("SELECT cs FROM ComplementaryStudy cs " +
// "JOIN cs.consultation c " +
// "JOIN c.pet p " +
// "WHERE p.id = :petId")
// List<ComplementaryStudy> findAllByPetId(@Param("petId") Long petId);
//
// @Query("SELECT cs FROM ComplementaryStudy cs " +
// "JOIN cs.consultation c " +
// "WHERE c.pet.id = :petId")
// List<ComplementaryStudy> findAllByPetId(@Param("petId") Long petId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,4 +15,10 @@ public interface HospitalizationRepository extends JpaRepository<Hospitalization
List<Hospitalization> findByTreatments_Id(Long treatmentId);

List<Hospitalization> findByComplementaryStudies_Id(Long complementaryStudyId);

@Query("SELECT h FROM Hospitalization h JOIN h.complementaryStudies cs JOIN cs.consultation c WHERE c.pet.id = :petId")
List<Hospitalization> 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<Hospitalization> findHospitalizationsByPetIdTreatment(@Param("petId") Long petId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ public StudyResponse getStudyById(Long studyId){
new ComplementaryStudyNotFoundException("El id del estudio complementario ingresao es incorrecto o no existe")));
}

public List<StudyResponse> getAllStudiesByPetId(Long petId){
return complementaryStudyMapper.toDtoList(complementaryStudyRepository.findAllById(Collections.singleton(petId)));
// public List<StudyResponse> getAllStudiesByPetId(Long petId){
// return complementaryStudyMapper.toDtoList(complementaryStudyRepository.findAllById(Collections.singleton(petId)));
// }

// public List<StudyResponse> getAllStudiesByPetId(Long petId) {
// List<ComplementaryStudy> studies = complementaryStudyRepository.findAllByPetId(petId);
// return complementaryStudyMapper.toDtoList(studies);
// }
public List<StudyResponse> getAllStudiesByPetId(Long petId) {
List<ComplementaryStudy> studies = complementaryStudyRepository.findAllByPetId(petId);
return complementaryStudyMapper.toDtoListByPet(studies); // Usar el nuevo método de mapeo
}
public List<StudyResponse> getAllStudiesByOwnerId(Long ownerId){
return complementaryStudyMapper.toDtoList(complementaryStudyRepository.findAllById(Collections.singleton(ownerId)));
Expand Down Expand Up @@ -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<StudyResponse> getAllStudiesByPetId2(Long petId) {
// List<ComplementaryStudy> studies = complementaryStudyRepository.findAllByPetId2(petId);
// return complementaryStudyMapper.toDtoList(studies);
// }
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<HospitalizationDtoResponse> getHospitalizationsByPetId(Long petId) {
// List<Hospitalization> hospitalizations = hospitalizationRepository.findHospitalizationsByPetId(petId);
// return hospitalizations.stream()
// .map(this::convertToDto)
// .collect(Collectors.toList());
// }

public List<HospitalizationDtoResponse> getHospitalizationsByPetId(Long petId) {
// Obtener hospitalizaciones desde ComplementaryStudies
List<Hospitalization> hospitalizationsByStudies = hospitalizationRepository.findHospitalizationsByPetId(petId);

// Obtener hospitalizaciones desde Treatment y Diagnosis
List<Hospitalization> hospitalizationsByTreatment = hospitalizationRepository.findHospitalizationsByPetIdTreatment(petId);

// Unir ambas listas y eliminar duplicados
Set<Hospitalization> combinedHospitalizations = new HashSet<>(hospitalizationsByStudies);
combinedHospitalizations.addAll(hospitalizationsByTreatment);

// Convertir a DTO
return combinedHospitalizations.stream()
.map(this::convertToDto)
.collect(Collectors.toList());
}

}
34 changes: 34 additions & 0 deletions Frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# .gitignore environment variables
.env.local
.env.development.local
.env.test.local
.env.production.local
.env



8 changes: 8 additions & 0 deletions Frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
1 change: 1 addition & 0 deletions Frontend/env.development.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_BASE_URL = your_api_base_url
38 changes: 38 additions & 0 deletions Frontend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import js from '@eslint/js'
import globals from 'globals'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
13 changes: 13 additions & 0 deletions Frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en" data-theme="mytheme">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading

0 comments on commit aad0aee

Please sign in to comment.