Search in sources :

Example 1 with Fk7263Utlatande

use of se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande in project webcert by sklintyg.

the class RouteIT method init.

@Before
public void init() throws Exception {
    when(fk7263ModuleApi.getIntygFromUtlatande(any())).thenReturn(NotificationTestHelper.createIntyg("fk7263"));
    when(fk7263ModuleApi.getUtlatandeFromJson(anyString())).thenReturn(new Fk7263Utlatande());
    when(mockIntygModuleRegistry.getModuleApi(anyString())).thenReturn(fk7263ModuleApi);
    certificateStatusUpdateForCareResponderStub.reset();
    certificateStatusUpdateForCareResponderV3.reset();
    setupConverter();
}
Also used : Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Before(org.junit.Before)

Example 2 with Fk7263Utlatande

use of se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande in project webcert by sklintyg.

the class RouteTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    MockEndpoint.resetMocks(camelContext);
    when(moduleRegistry.getModuleApi(anyString())).thenReturn(moduleApi);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(new Fk7263Utlatande());
    when(moduleApi.getIntygFromUtlatande(any())).thenReturn(NotificationTestHelper.createIntyg("fk7263"));
    when(mockedPuService.getPerson(any())).thenReturn(new PersonSvar(NotificationTestHelper.buildPerson(false), PersonSvar.Status.FOUND));
}
Also used : Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) Before(org.junit.Before)

Example 3 with Fk7263Utlatande

use of se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande in project webcert by sklintyg.

the class IntygServiceTest method testHandleSignedWithSigneraSkickaDirekt.

@Test
public void testHandleSignedWithSigneraSkickaDirekt() throws Exception {
    final String intygId = "intygId";
    final String intygTyp = "intygTyp";
    final String relationIntygId = "relationIntygId";
    final String recipient = new Fk7263EntryPoint().getDefaultRecipient();
    final Personnummer personnummer = PERSNR;
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    utlatande.setId(intygId);
    utlatande.setTyp(intygTyp);
    utlatande.getGrundData().getPatient().setPersonId(personnummer);
    Utkast utkast = new Utkast();
    utkast.setIntygsId(intygId);
    utkast.setIntygsTyp(intygTyp);
    utkast.setModel(json);
    when(utkastRepository.findOne(intygId)).thenReturn(utkast);
    when(moduleFacade.getUtlatandeFromInternalModel(eq(intygTyp), anyString())).thenReturn(utlatande);
    when(certificateRelationService.getNewestRelationOfType(eq(intygId), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.empty());
    when(moduleRegistry.getModuleEntryPoint(intygTyp)).thenReturn(new Fk7263EntryPoint());
    when(authoritiesHelper.isFeatureActive(AuthoritiesConstants.FEATURE_SIGNERA_SKICKA_DIREKT, intygTyp)).thenReturn(true);
    intygService.handleAfterSigned(utkast);
    verify(certificateSenderService).sendCertificate(eq(intygId), eq(personnummer), anyString(), eq(recipient), eq(true));
    verify(mockMonitoringService).logIntygSent(intygId, recipient);
    verify(logservice).logSendIntygToRecipient(any(LogRequest.class));
    verify(arendeService, never()).closeCompletionsAsHandled(relationIntygId, intygTyp);
    verify(notificationService).sendNotificationForIntygSent(intygId);
    ArgumentCaptor<Utkast> utkastCaptor = ArgumentCaptor.forClass(Utkast.class);
    verify(utkastRepository).save(utkastCaptor.capture());
    assertNotNull(utkastCaptor.getValue().getSkickadTillMottagareDatum());
    assertEquals(recipient, utkastCaptor.getValue().getSkickadTillMottagare());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) Test(org.junit.Test)

Example 4 with Fk7263Utlatande

use of se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande in project webcert by sklintyg.

the class IntygServiceTest method testListCertificatesForCareWithQAOk.

@Test
public void testListCertificatesForCareWithQAOk() throws Exception {
    final List<String> enhetList = Arrays.asList("enhet");
    final String intygType = "intygType";
    final String intygId = "intygId";
    final LocalDateTime localDateTime = LocalDateTime.of(2017, Month.JANUARY, 1, 1, 1);
    Handelse handelse = new Handelse();
    handelse.setTimestamp(localDateTime);
    handelse.setCode(HandelsekodEnum.SKAPAT);
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    ArendeCount sent = new ArendeCount(1, 2, 3, 4);
    ArendeCount received = new ArendeCount(5, 6, 7, 8);
    when(moduleRegistry.listAllModules()).thenReturn(Arrays.asList(new IntygModule(intygType, "", "", "", "", "", "", "", "", false)));
    when(utkastRepository.findDraftsByPatientAndEnhetAndStatus(eq(PERSON_ID), eq(enhetList), eq(Arrays.asList(UtkastStatus.values())), eq(Collections.singleton(intygType)))).thenReturn(Arrays.asList(getDraft(intygId)));
    when(notificationService.getNotifications(eq(intygId))).thenReturn(Arrays.asList(handelse));
    when(moduleRegistry.getModuleApi(any(String.class))).thenReturn(moduleApi);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(fragorOchSvarCreator.createArenden(eq(intygId), anyString())).thenReturn(Pair.of(sent, received));
    List<IntygWithNotificationsResponse> res = intygService.listCertificatesForCareWithQA(new IntygWithNotificationsRequest.Builder().setPersonnummer(PERSNR).setEnhetId(enhetList).build());
    assertNotNull(res);
    assertEquals(1, res.size());
    assertEquals(1, res.get(0).getNotifications().size());
    assertEquals(HandelsekodEnum.SKAPAT, res.get(0).getNotifications().get(0).getCode());
    assertEquals(localDateTime, res.get(0).getNotifications().get(0).getTimestamp());
    assertEquals(1, res.get(0).getSentQuestions().getTotalt());
    assertEquals(2, res.get(0).getSentQuestions().getEjBesvarade());
    assertEquals(3, res.get(0).getSentQuestions().getBesvarade());
    assertEquals(4, res.get(0).getSentQuestions().getHanterade());
    assertEquals(5, res.get(0).getReceivedQuestions().getTotalt());
    assertEquals(6, res.get(0).getReceivedQuestions().getEjBesvarade());
    assertEquals(7, res.get(0).getReceivedQuestions().getBesvarade());
    assertEquals(8, res.get(0).getReceivedQuestions().getHanterade());
    assertEquals(REFERENCE, res.get(0).getRef());
}
Also used : LocalDateTime(java.time.LocalDateTime) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse) Test(org.junit.Test)

Example 5 with Fk7263Utlatande

use of se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande in project webcert by sklintyg.

the class IntygServiceTest method IntygServiceConverter.

@Before
public void IntygServiceConverter() throws Exception {
    when(moduleRegistry.getModuleApi(any(String.class))).thenReturn(moduleApi);
    json = FileUtils.getStringFromFile(new ClassPathResource("IntygServiceTest/utlatande.json").getFile());
    Fk7263Utlatande utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(moduleApi.updateBeforeSave(anyString(), any(Patient.class))).thenAnswer((invocation) -> invocation.getArgument(0));
    // use reflection to set IntygDraftsConverter in IntygService
    Field field = IntygServiceImpl.class.getDeclaredField("intygConverter");
    field.setAccessible(true);
    field.set(intygService, intygConverter);
    when(moduleRegistry.getModuleIdFromExternalId(anyString())).thenAnswer(invocation -> ((String) invocation.getArguments()[0]).toLowerCase());
}
Also used : Field(java.lang.reflect.Field) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Aggregations

Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Test (org.junit.Test)8 Before (org.junit.Before)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Patient (se.inera.intyg.common.support.model.common.internal.Patient)5 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArrayList (java.util.ArrayList)4 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)4 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)4 Status (se.inera.intyg.common.support.model.Status)3 IntygModule (se.inera.intyg.common.support.modules.registry.IntygModule)3 CertificateMetaData (se.inera.intyg.common.support.modules.support.api.dto.CertificateMetaData)3 CertificateResponse (se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse)3 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)3 IntygWithNotificationsResponse (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse)3 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)3 LocalDateTime (java.time.LocalDateTime)2 Fk7263EntryPoint (se.inera.intyg.common.fk7263.support.Fk7263EntryPoint)2 ValidationStatus (se.inera.intyg.common.support.modules.support.api.dto.ValidationStatus)2