102 lines
4.5 KiB
Plaintext
102 lines
4.5 KiB
Plaintext
package com.healthcare.ohctech.controller;
|
|
|
|
import com.healthcare.ohctech.dto.RuleEquationDto;
|
|
import com.healthcare.ohctech.entity.RuleEquation;
|
|
import com.healthcare.ohctech.service.impl.AuthServiceImpl;
|
|
import com.healthcare.ohctech.service.impl.RuleEquationServiceImpl;
|
|
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("/rule-equations")
|
|
public class RuleEquationController {
|
|
|
|
@Autowired
|
|
private RuleEquationServiceImpl ruleEquationServiceImpl;
|
|
|
|
@Autowired
|
|
private AuthServiceImpl authServiceImpl;
|
|
|
|
@GetMapping("/{ruleEqId}")
|
|
public ResponseEntity<?> getRuleEquationById(@PathVariable Long ruleEqId) {
|
|
RuleEquation ruleEquation = ruleEquationServiceImpl.getRuleEquationById(ruleEqId);
|
|
RuleEquationDto ruleEquationDto = new RuleEquationDto(
|
|
ruleEquation.getId(),
|
|
ruleEquation.getRuleEquation(),
|
|
// ruleEquation.getCheckupFormSection().getId(),
|
|
ruleEquation.getCout(),
|
|
ruleEquation.getRuleGender(),
|
|
ruleEquation.getRuleAgeStart(),
|
|
ruleEquation.getRuleAgeEnd(),
|
|
ruleEquation.getResult(),
|
|
ruleEquation.getResultDisp(),
|
|
ruleEquation.getAbnormality().getId(),
|
|
ruleEquation.getRisks(),
|
|
ruleEquation.getAdvices(),
|
|
ruleEquation.getColor(),
|
|
ruleEquation.getRangeType(),
|
|
ruleEquation.getIsStringRule(),
|
|
ruleEquation.getModifiedBy(),
|
|
ruleEquation.getLastModified()
|
|
);
|
|
return new ResponseEntity<>(ruleEquationDto, HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<?> getAllRuleEquations(@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<RuleEquation> ruleEquationPage = ruleEquationServiceImpl.getAllRuleEquations(pageable);
|
|
Page<RuleEquationDto> ruleEquationDtoPage = ruleEquationPage.map(ruleEquation -> new RuleEquationDto(
|
|
ruleEquation.getId(),
|
|
ruleEquation.getRuleEquation(),
|
|
// ruleEquation.getCheckupFormSection().getId(),
|
|
ruleEquation.getCout(),
|
|
ruleEquation.getRuleGender(),
|
|
ruleEquation.getRuleAgeStart(),
|
|
ruleEquation.getRuleAgeEnd(),
|
|
ruleEquation.getResult(),
|
|
ruleEquation.getResultDisp(),
|
|
ruleEquation.getAbnormality().getId(),
|
|
ruleEquation.getRisks(),
|
|
ruleEquation.getAdvices(),
|
|
ruleEquation.getColor(),
|
|
ruleEquation.getRangeType(),
|
|
ruleEquation.getIsStringRule(),
|
|
ruleEquation.getModifiedBy(),
|
|
ruleEquation.getLastModified()
|
|
));
|
|
Map<String, Object> response = PaginationUtil.getPageResponse(ruleEquationDtoPage);
|
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> addRuleEquation(@Valid @RequestBody RuleEquationDto ruleEquationDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
ruleEquationServiceImpl.addRuleEquation(ruleEquationDto, userId);
|
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
}
|
|
|
|
@PutMapping("/{ruleEqId}")
|
|
public ResponseEntity<?> updateRuleEquation(@Valid @RequestBody RuleEquationDto ruleEquationDto) {
|
|
Long userId = authServiceImpl.getCurrentUserId();
|
|
ruleEquationServiceImpl.updateRuleEquation(ruleEquationDto, userId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
|
|
@DeleteMapping("/{ruleEqId}")
|
|
public ResponseEntity<?> deleteRuleEquation(@PathVariable Long ruleEqId) {
|
|
ruleEquationServiceImpl.deleteRuleEquation(ruleEqId);
|
|
return new ResponseEntity<>(HttpStatus.OK);
|
|
}
|
|
} |