Search in sources :

Example 86 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class UtkastServiceImplTest method testSaveUpdatesChangedPatientName.

@Test
public void testSaveUpdatesChangedPatientName() throws Exception {
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.VALID, Collections.emptyList());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(buildPatient(PERSON_ID, "Tolvan", "Tolvansson"));
    when(utlatande.getGrundData()).thenReturn(grunddata);
    utkast.setPatientFornamn("Inte Tolvan");
    utkast.setPatientEfternamn("Inte Tolvansson");
    // Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
    utkast = spy(utkast);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.validateDraft(anyString())).thenReturn(validationResponse);
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(utkast).setPatientFornamn("Tolvan");
    verify(utkast).setPatientEfternamn("Tolvansson");
    verify(utkast).setPatientPersonnummer(any(Personnummer.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 87 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class NotificationMessageFactoryTest method testCreateNotificationMessageForUtkast.

@Test
public void testCreateNotificationMessageForUtkast() {
    Utkast utkast = createUtkast(INTYGS_ID);
    String reference = "ref";
    NotificationMessage msg = notificationMessageFactory.createNotificationMessage(utkast, HandelsekodEnum.SIGNAT, SchemaVersion.VERSION_1, reference, null, null);
    assertNotNull(msg);
    assertNotNull(msg.getHandelse());
    assertEquals(HandelsekodEnum.SIGNAT, msg.getHandelse());
    assertNotNull(msg.getHandelseTid());
    assertEquals(INTYGS_ID, msg.getIntygsId());
    assertEquals(INTYGS_TYP, msg.getIntygsTyp());
    assertEquals("SE12345678-1000", msg.getLogiskAdress());
    assertEquals("{model}", msg.getUtkast());
    assertNotNull(msg.getFragaSvar());
    assertEquals(SchemaVersion.VERSION_1, msg.getVersion());
    assertEquals(reference, msg.getReference());
    assertNotNull(msg.getFragaSvar());
    assertNull(msg.getSkickadeFragor());
    assertNull(msg.getMottagnaFragor());
    assertNull(msg.getAmne());
    assertNull(msg.getSistaSvarsDatum());
    verifyZeroInteractions(mockFragorOchSvarCreator);
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Example 88 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class NotificationMessageFactoryTest method createUtkast.

private Utkast createUtkast(String intygId) {
    VardpersonReferens vardperson = new VardpersonReferens();
    vardperson.setHsaId("SE12345678-0000");
    vardperson.setNamn("Dr Börje Dengroth");
    Utkast utkast = new Utkast();
    utkast.setIntygsId(intygId);
    utkast.setIntygsTyp(INTYGS_TYP);
    utkast.setEnhetsId("SE12345678-1000");
    utkast.setEnhetsNamn("Vårdenhet 1");
    utkast.setPatientPersonnummer(Personnummer.createPersonnummer("19121212-1212").get());
    utkast.setPatientFornamn("Tolvan");
    utkast.setPatientEfternamn("Tolvansson");
    utkast.setStatus(UtkastStatus.DRAFT_INCOMPLETE);
    utkast.setModel("{model}");
    utkast.setSkapadAv(vardperson);
    utkast.setSenastSparadAv(vardperson);
    return utkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)

Example 89 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class NotificationMessageFactoryTest method testCreateNotificationMessageForUsesFragorOchSvarSchemaVersion1.

@Test
public void testCreateNotificationMessageForUsesFragorOchSvarSchemaVersion1() {
    when(mockFragorOchSvarCreator.createFragorOchSvar(INTYGS_ID)).thenReturn(new FragorOchSvar(1, 1, 1, 1));
    Utkast utkast = createUtkast(INTYGS_ID);
    final String reference = "ref";
    NotificationMessage msg = notificationMessageFactory.createNotificationMessage(utkast, HandelsekodEnum.NYFRFM, SchemaVersion.VERSION_1, reference, null, null);
    assertNotNull(msg);
    assertNotNull(msg.getHandelse());
    assertEquals(HandelsekodEnum.NYFRFM, msg.getHandelse());
    assertNotNull(msg.getHandelseTid());
    assertEquals(INTYGS_ID, msg.getIntygsId());
    assertEquals(INTYGS_TYP, msg.getIntygsTyp());
    assertEquals("SE12345678-1000", msg.getLogiskAdress());
    assertEquals("{model}", msg.getUtkast());
    assertEquals(SchemaVersion.VERSION_1, msg.getVersion());
    assertEquals(reference, msg.getReference());
    assertNotNull(msg.getFragaSvar());
    assertEquals(1, msg.getFragaSvar().getAntalFragor());
    assertEquals(1, msg.getFragaSvar().getAntalHanteradeFragor());
    assertEquals(1, msg.getFragaSvar().getAntalHanteradeSvar());
    assertEquals(1, msg.getFragaSvar().getAntalSvar());
    assertNull(msg.getSkickadeFragor());
    assertNull(msg.getMottagnaFragor());
    assertNull(msg.getAmne());
    assertNull(msg.getSistaSvarsDatum());
    verify(mockFragorOchSvarCreator).createFragorOchSvar(INTYGS_ID);
    verifyNoMoreInteractions(mockFragorOchSvarCreator);
}
Also used : FragorOchSvar(se.inera.intyg.common.support.modules.support.api.notification.FragorOchSvar) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Example 90 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class NotificationServiceImplTest method testCreateAndSendNotification.

@Test
public void testCreateAndSendNotification() throws Exception {
    ArgumentCaptor<MessageCreator> messageCreatorCaptor = ArgumentCaptor.forClass(MessageCreator.class);
    when(mockSendNotificationStrategy.decideNotificationForIntyg(any(Utkast.class))).thenReturn(Optional.of(SchemaVersion.VERSION_1));
    NotificationMessage notMsg = createNotificationMessage(HandelsekodEnum.ANDRAT, INTYG_JSON);
    when(mockNotificationMessageFactory.createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.ANDRAT), eq(SchemaVersion.VERSION_1), anyString(), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)))).thenReturn(notMsg);
    Utkast utkast = createUtkast();
    notificationService.createAndSendNotification(utkast, HandelsekodEnum.ANDRAT);
    verify(template, only()).send(messageCreatorCaptor.capture());
    TextMessage textMessage = mock(TextMessage.class);
    Session session = mock(Session.class);
    ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
    when(session.createTextMessage(stringArgumentCaptor.capture())).thenReturn(textMessage);
    MessageCreator messageCreator = messageCreatorCaptor.getValue();
    messageCreator.createMessage(session);
    // get the notfication message as json and transform it back to object
    NotificationMessage captNotMsg = objectMapper.readValue(stringArgumentCaptor.getValue(), NotificationMessage.class);
    // assert that things are still there
    assertNotNull(captNotMsg);
    assertEquals(INTYG_ID, captNotMsg.getIntygsId());
    assertEquals(HandelsekodEnum.ANDRAT, captNotMsg.getHandelse());
    assertEquals(INTYG_JSON, captNotMsg.getUtkast());
    assertEquals(SchemaVersion.VERSION_1, captNotMsg.getVersion());
    assertNull(captNotMsg.getReference());
    // verify call has been made
    verify(mockNotificationMessageFactory).createNotificationMessage(any(Utkast.class), eq(HandelsekodEnum.ANDRAT), eq(SchemaVersion.VERSION_1), anyString(), or(isNull(), any(Amneskod.class)), or(isNull(), any(LocalDate.class)));
    verify(handelseRepository).save(any(Handelse.class));
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageCreator(org.springframework.jms.core.MessageCreator) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)171 Test (org.junit.Test)88 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)34 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 Personnummer (se.inera.intyg.schemas.contract.Personnummer)21 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)21 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)21 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)18 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)17 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)16 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)13 Patient (se.inera.intyg.common.support.model.common.internal.Patient)12 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)12 ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)12 Transactional (org.springframework.transaction.annotation.Transactional)11 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)11 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)10 ArrayList (java.util.ArrayList)9