76 lines
3.9 KiB
Plaintext
76 lines
3.9 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.PatientConsultationDto;
|
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
|
import com.healthcare.ohctech.service.impl.PatientConsultationServiceImpl;
|
|
import com.healthcare.ohctech.util.PaginationUtil;
|
|
import jakarta.validation.Valid;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/patient-consultations")
|
|
public class PatientConsultationController {
|
|
|
|
@Autowired
|
|
private PatientConsultationServiceImpl patientConsultationServiceImpl;
|
|
|
|
@Autowired
|
|
private AuthServiceImpl authServiceImpl;
|
|
|
|
@GetMapping("/{consultationId}")
|
|
public ResponseEntity<?> getConsultationById(@PathVariable Long consultationId) {
|
|
PatientConsultationDto consultationDto = patientConsultationServiceImpl.getConsultationWithCombinedDataById(consultationId);
|
|
return new ResponseEntity<>(consultationDto, HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllConsultations(@RequestParam(required = false) Integer page,
|
|
@RequestParam(required = false) Integer size,
|
|
@RequestParam(required = false) String sortBy,
|
|
@RequestParam(required = false) String sortOrder) {
|
|
Pageable pageable = PaginationUtil.getPageableWithDefaults(page, size, sortBy, sortOrder);
|
|
Page<PatientConsultationDto> consultationsPage = patientConsultationServiceImpl.getAllConsultationsWithCombinedData(pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(consultationsPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addConsultation(@Valid @RequestBody PatientConsultationDto consultationDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
Long consultationId = patientConsultationServiceImpl.addConsultation(consultationDto, userId);
|
|
return new ResponseEntity<>(consultationId, HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{consultationId}")
|
|
public ResponseEntity<?> updateConsultation(@Valid @RequestBody PatientConsultationDto consultationDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
Long updatedConsultationId = patientConsultationServiceImpl.updateConsultation(consultationDto, userId);
|
|
return new ResponseEntity<>(updatedConsultationId, HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{consultationId}")
|
|
public ResponseEntity<?> deleteConsultation(@PathVariable Long consultationId) {
|
|
patientConsultationServiceImpl.deleteConsultation(consultationId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping("/employee/{empId}")
|
|
public ResponseEntity<?> getConsultationsByEmpId(@PathVariable Long empId,
|
|
@RequestParam(required = false) Integer page,
|
|
@RequestParam(required = false) Integer size,
|
|
@RequestParam(required = false) String sortBy,
|
|
@RequestParam(required = false) String sortOrder) {
|
|
Pageable pageable = PaginationUtil.getPageableWithDefaults(page, size, sortBy, sortOrder);
|
|
Page<PatientConsultationDto> consultationsPage = patientConsultationServiceImpl.getConsultationsByEmpId(empId, pageable);
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(consultationsPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
}
|