94 lines
4.2 KiB
Java
94 lines
4.2 KiB
Java
package com.voidsoftware.map02.controllers;
|
|
|
|
import com.voidsoftware.map02.config.CurrentUser;
|
|
import com.voidsoftware.map02.entities.AppUser;
|
|
import com.voidsoftware.map02.models.dto.PatientDTO;
|
|
import com.voidsoftware.map02.models.inout.*;
|
|
import com.voidsoftware.map02.services.PatientsService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.UUID;
|
|
|
|
@Tag(name = "Patients", description = "Manage patients and their prescriptions")
|
|
@RestController
|
|
@RequestMapping("/api/patients")
|
|
public class PatientsController {
|
|
|
|
private final PatientsService patientsService;
|
|
|
|
|
|
public PatientsController(PatientsService patientsService) {
|
|
this.patientsService = patientsService;
|
|
|
|
|
|
}
|
|
|
|
@Operation(summary = "Create patient", description = "Registers a new patient under the given professional.")
|
|
@ApiResponses({
|
|
@ApiResponse(responseCode = "201", description = "Patient created"),
|
|
@ApiResponse(responseCode = "400", description = "Validation error"),
|
|
@ApiResponse(responseCode = "404", description = "Professional not found")
|
|
})
|
|
@PostMapping("/create")
|
|
public ResponseEntity<PatientDTO> createPatient(@CurrentUser AppUser sessionUser,
|
|
@Valid @RequestBody CreatePatientRequest request) {
|
|
PatientDTO createdPatient = patientsService.createPatient(sessionUser, request);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(createdPatient);
|
|
}
|
|
|
|
|
|
@Operation(summary = "Update photo patient", description = "")
|
|
@ApiResponses({
|
|
@ApiResponse(responseCode = "201", description = "Patient created"),
|
|
@ApiResponse(responseCode = "400", description = "Validation error"),
|
|
@ApiResponse(responseCode = "404", description = "Professional not found")
|
|
})
|
|
@PostMapping("/update/photo")
|
|
public ResponseEntity<Void> changePatientPhoto(@CurrentUser AppUser sessionUser,
|
|
@Valid @RequestBody ChangeMediaEntityImageRequest request) {
|
|
if (patientsService.updatePatientPhoto(sessionUser, request)) {
|
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
|
}
|
|
return ResponseEntity.badRequest().build();
|
|
}
|
|
|
|
@Operation(summary = "Get patient", description = "Returns a single patient by ID.")
|
|
@ApiResponses({
|
|
@ApiResponse(responseCode = "200", description = "Patient found"),
|
|
@ApiResponse(responseCode = "404", description = "Patient not found")
|
|
})
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<PatientDTO> getPatient(@CurrentUser AppUser sessionUser,
|
|
@PathVariable UUID id) {
|
|
return ResponseEntity.ok(patientsService.getPatientById(sessionUser, id));
|
|
}
|
|
|
|
@Operation(summary = "List patients by professional", description = "Returns all patients assigned to the given professional.")
|
|
@ApiResponses({
|
|
@ApiResponse(responseCode = "200", description = "List returned"),
|
|
@ApiResponse(responseCode = "404", description = "Professional not found")
|
|
})
|
|
@PostMapping("/list")
|
|
public ResponseEntity<ListOfPatientsResponse> listByProfessional(@CurrentUser AppUser sessionUser,
|
|
@Valid @RequestBody ListPatientsRequest request) {
|
|
return ResponseEntity.ok(
|
|
new ListOfPatientsResponse(patientsService.getPatientsListByProfessional(sessionUser, request)));
|
|
}
|
|
|
|
|
|
@Operation(summary = "get patient medication periods", description = "Returns every medication on the database")
|
|
@ApiResponse(responseCode = "200", description = "List returned")
|
|
@GetMapping
|
|
public ResponseEntity<ListOfPatientPeriods> getPatientMedicationDayPeriods(@CurrentUser AppUser sessionUser) {
|
|
return ResponseEntity.ok(this.patientsService.getPatientMedicationDayPeriods(sessionUser));
|
|
}
|
|
}
|