package org.upgrad.upstac.testrequests.consultation;
import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import lombok.ToString; import org.upgrad.upstac.testrequests.TestRequest; import org.upgrad.upstac.users.User;
import javax.persistence.*; import java.time.LocalDate;
@Data @Entity public class Consultation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@OneToOne(fetch = FetchType.LAZY)
@JsonIgnore
@ToString.Exclude
private TestRequest request;
private DoctorSuggestion suggestion;
private String comments;
private LocalDate updatedOn;
@ManyToOne
User doctor;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.upgrad.upstac.config.security.UserLoggedInService; import org.upgrad.upstac.exception.AppException; import org.upgrad.upstac.testrequests.RequestStatus; import org.upgrad.upstac.testrequests.TestRequest; import org.upgrad.upstac.testrequests.TestRequestQueryService; import org.upgrad.upstac.testrequests.TestRequestUpdateService; import org.upgrad.upstac.testrequests.flow.TestRequestFlowService; import org.upgrad.upstac.users.User;
import javax.validation.ConstraintViolationException; import java.util.List;
import static org.upgrad.upstac.exception.UpgradResponseStatusException.asBadRequest; import static org.upgrad.upstac.exception.UpgradResponseStatusException.asConstraintViolation;
@RestController @RequestMapping("/api/labrequests") public class LabRequestController {
Logger log = LoggerFactory.getLogger(LabRequestController.class);
@Autowired
private TestRequestUpdateService testRequestUpdateService;
@Autowired
private TestRequestQueryService testRequestQueryService;
@Autowired
private TestRequestFlowService testRequestFlowService;
@Autowired
private UserLoggedInService userLoggedInService;
// It helps fetching all the Test Requests with Status as INITIATED, in the Tester's bucket
@GetMapping("/to-be-tested")
@PreAuthorize("hasAnyRole('TESTER')")
public List<TestRequest> getForTests() {
return testRequestQueryService.findBy(RequestStatus.INITIATED);
}
// It helps fetching all the assigned Test Requests for the logged-in Tester
@GetMapping
@PreAuthorize("hasAnyRole('TESTER')")
public List<TestRequest> getForTester() {
User tester = userLoggedInService.getLoggedInUser();
return testRequestQueryService.findByTester(tester);
}
// It helps fetching all the assigned Test Requests for the logged-in Tester
@PreAuthorize("hasAnyRole('TESTER')")
@PutMapping("/assign/{id}")
public TestRequest assignForLabTest(@PathVariable Long id) {
User tester = userLoggedInService.getLoggedInUser();
return testRequestUpdateService.assignForLabTest(id,tester);
}
// It helps updating the assigned Test Requests
@PreAuthorize("hasAnyRole('TESTER')")
@