use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarModuleApiController method answer.
@PUT
@Path("/{intygsTyp}/{fragasvarId}/besvara")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response answer(@PathParam("intygsTyp") String intygsTyp, @PathParam("fragasvarId") final Long frageSvarId, String svarsText) {
abortIfFragaSvarNotActive(intygsTyp);
LOG.debug("Set answer for question {}", frageSvarId);
FragaSvar fragaSvarResponse = fragaSvarService.saveSvar(frageSvarId, svarsText);
return Response.ok(fragaSvarResponse).build();
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarBootstrapBean method addFragaSvar.
private void addFragaSvar(Resource res) {
try {
FragaSvar fragaSvar = new CustomObjectMapper().readValue(res.getInputStream(), FragaSvar.class);
fragaSvarRepository.save(fragaSvar);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testOpenAsUnhandledFromWCWithAnswer.
@Test
public void testOpenAsUnhandledFromWCWithAnswer() {
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar.setFrageStallare(FrageStallare.WEBCERT.getKod());
fragaSvar.setFrageText("Fråga till FK från WC");
fragaSvar.setSvarsText("Med ett svar från FK");
fragaSvar.setStatus(Status.CLOSED);
ArgumentCaptor<FragaSvar> capture = ArgumentCaptor.forClass(FragaSvar.class);
when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
when(fragasvarRepositoryMock.save(capture.capture())).thenReturn(fragaSvar);
service.openQuestionAsUnhandled(1L);
verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_CARE_WITH_ANSWER_UNHANDLED);
verify(fragasvarRepositoryMock).findOne(1L);
verify(fragasvarRepositoryMock).save(any(FragaSvar.class));
assertEquals(Status.ANSWERED, capture.getValue().getStatus());
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testSaveSvarOK.
@Test
public void testSaveSvarOK() {
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
when(webCertUserService.getUser()).thenReturn(createUser());
when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
when(webCertUserService.getUser()).thenReturn(createUser());
when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true);
when(fragasvarRepositoryMock.save(fragaSvar)).thenReturn(fragaSvar);
// mock ws ok response
SendMedicalCertificateAnswerResponseType wsResponse = new SendMedicalCertificateAnswerResponseType();
wsResponse.setResult(ResultOfCallUtil.okResult());
when(sendAnswerToFKClientMock.sendMedicalCertificateAnswer(any(AttributedURIType.class), any(SendMedicalCertificateAnswerType.class))).thenReturn(wsResponse);
FragaSvar result = service.saveSvar(1L, "svarsText");
verify(fragasvarRepositoryMock).findOne(1L);
verify(webCertUserService).getUser();
verify(webCertUserService).isAuthorizedForUnit(anyString(), eq(false));
verify(fragasvarRepositoryMock).save(fragaSvar);
verify(sendAnswerToFKClientMock).sendMedicalCertificateAnswer(any(AttributedURIType.class), any(SendMedicalCertificateAnswerType.class));
verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
verify(monitoringServiceMock).logAnswerSent(anyString(), any(Long.class), anyString(), anyString(), any(Amne.class));
assertEquals("svarsText", result.getSvarsText());
assertEquals(Status.CLOSED, result.getStatus());
assertNotNull(result.getSvarSkickadDatum());
verify(arendeDraftService).delete(INTYG_ID, Long.toString(1L));
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testCloseQuestionFromFKAsHandledOK.
@Test
public void testCloseQuestionFromFKAsHandledOK() {
// This is a question from FK that we have no intention to answer so we close it
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
fragaSvar.setFrageText("Fråga från FK till WC");
fragaSvar.setStatus(Status.PENDING_INTERNAL_ACTION);
ArgumentCaptor<FragaSvar> fsCapture = ArgumentCaptor.forClass(FragaSvar.class);
when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
when(fragasvarRepositoryMock.save(fsCapture.capture())).thenReturn(fragaSvar);
service.closeQuestionAsHandled(1L);
verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_RECIPIENT_HANDLED);
verify(fragasvarRepositoryMock).findOne(1L);
verify(fragasvarRepositoryMock).save(any(FragaSvar.class));
assertEquals(Status.CLOSED, fsCapture.getValue().getStatus());
verify(arendeDraftService).delete(INTYG_ID, Long.toString(1L));
}
Aggregations