Search in sources :

Example 16 with FragaSvar

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();
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 17 with FragaSvar

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);
    }
}
Also used : CustomObjectMapper(se.inera.intyg.common.util.integration.json.CustomObjectMapper) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) IOException(java.io.IOException)

Example 18 with FragaSvar

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());
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Test(org.junit.Test)

Example 19 with FragaSvar

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));
}
Also used : SendMedicalCertificateAnswerResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SendMedicalCertificateAnswerType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Amne(se.inera.intyg.webcert.persistence.fragasvar.model.Amne) Test(org.junit.Test)

Example 20 with FragaSvar

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));
}
Also used : FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) Test(org.junit.Test)

Aggregations

FragaSvar (se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)71 Test (org.junit.Test)42 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 IntygsReferens (se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens)11 Vardperson (se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson)11 Produces (javax.ws.rs.Produces)7 AttributedURIType (org.w3.wsaddressing10.AttributedURIType)7 Path (javax.ws.rs.Path)6 Filter (se.inera.intyg.webcert.persistence.model.Filter)6 LocalDateTime (java.time.LocalDateTime)5 Consumes (javax.ws.rs.Consumes)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)5 ArendeListItem (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem)5 ArrayList (java.util.ArrayList)4 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)4 SendMedicalCertificateAnswerResponseType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerResponseType)4 SendMedicalCertificateAnswerType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.SendMedicalCertificateAnswerType)4 SendMedicalCertificateQuestionType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType)4 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 Amne (se.inera.intyg.webcert.persistence.fragasvar.model.Amne)4