ohctechv3/.svn/pristine/8e/8e8e2eae57e90e0984ccfc565716957ad3096d25.svn-base
2024-10-28 15:03:36 +05:30

67 lines
3.1 KiB
Plaintext

package com.healthcare.ohctech.controller;
import com.healthcare.ohctech.dto.PatientDietPlanDto;
import com.healthcare.ohctech.entity.PatientDietPlan;
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
import com.healthcare.ohctech.service.impl.PatientDietPlanServiceImpl;
import com.healthcare.ohctech.util.PaginationUtil;
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 jakarta.validation.Valid;
import java.util.*;
@RestController
@RequestMapping("/patient-diet-plans")
public class PatientDietPlanController {
@Autowired
private PatientDietPlanServiceImpl patientDietPlanServiceImpl;
@Autowired
private AuthServiceImpl authServiceImpl;
@GetMapping("/{consultationId}")
public ResponseEntity<?> getPatientDietPlansByConsultationId(@PathVariable Long consultationId) {
List<PatientDietPlanDto> dietPlans = patientDietPlanServiceImpl.getPatientDietPlansByConsultationId(consultationId);
return new ResponseEntity<>(dietPlans, HttpStatus.OK);
}
@GetMapping
public ResponseEntity<?> getAllPatientDietPlans(@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);
List<PatientDietPlanDto> groupedPlans = patientDietPlanServiceImpl.getAllPatientDietPlans();
Page<PatientDietPlanDto> planDtoPage = PaginationUtil.getPageFromList(groupedPlans, pageable);
Map<String, Object> response = PaginationUtil.getPageResponse(planDtoPage);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@PostMapping
public ResponseEntity<?> addPatientDietPlan(@Valid @RequestBody PatientDietPlanDto patientDietPlanDto) {
Long userId = authServiceImpl.getCurrentUserId();
patientDietPlanServiceImpl.addPatientDietPlan(patientDietPlanDto, userId);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping("/{consultationId}")
public ResponseEntity<?> updatePatientDietPlan(@PathVariable Long consultationId,
@Valid @RequestBody PatientDietPlanDto patientDietPlanDto) {
Long userId = authServiceImpl.getCurrentUserId();
patientDietPlanServiceImpl.updatePatientDietPlan(consultationId, patientDietPlanDto, userId);
return new ResponseEntity<>(HttpStatus.OK);
}
@DeleteMapping("/{id}")
public ResponseEntity<?> deletePatientDietPlan(@PathVariable Long id) {
patientDietPlanServiceImpl.deletePatientDietPlan(id);
return new ResponseEntity<>(HttpStatus.OK);
}
}