Search in sources :

Example 21 with ListIntygEntry

use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.

the class IntygDraftsConverterTest method testConvertUtkastToListIntygEntryResolvesSignedByNameFromSkapadAv.

@Test
public void testConvertUtkastToListIntygEntryResolvesSignedByNameFromSkapadAv() {
    Signatur signatur = mock(Signatur.class);
    final String skapadAvName = "Bengt Bengtsson";
    final String skapadAvHsaId = "BengtsHsaId";
    Utkast utkast = createUtkast();
    utkast.setStatus(UtkastStatus.SIGNED);
    utkast.getSkapadAv().setNamn(skapadAvName);
    utkast.setSignatur(signatur);
    when(signatur.getSigneradAv()).thenReturn(skapadAvHsaId);
    ListIntygEntry res = IntygDraftsConverter.convertUtkastToListIntygEntry(utkast);
    assertNotNull(res);
    assertEquals(skapadAvHsaId, res.getUpdatedSignedBy());
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) Test(org.junit.Test)

Example 22 with ListIntygEntry

use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.

the class IntygDraftsConverterTest method testConvertUtkastToListIntygEntrySetsStatusReceivedIfApplicable.

@Test
public void testConvertUtkastToListIntygEntrySetsStatusReceivedIfApplicable() {
    Signatur signatur = mock(Signatur.class);
    Utkast utkast = createUtkast();
    utkast.setStatus(UtkastStatus.SIGNED);
    utkast.setSignatur(signatur);
    when(signatur.getSigneringsDatum()).thenReturn(LocalDateTime.now());
    ListIntygEntry res = IntygDraftsConverter.convertUtkastToListIntygEntry(utkast);
    assertNotNull(res);
    assertEquals(CertificateState.RECEIVED.name(), res.getStatus());
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) Test(org.junit.Test)

Example 23 with ListIntygEntry

use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.

the class IntygDraftsConverterTest method testConvertUtkastToListIntygEntrySetsStatusCancelledIfApplicable.

@Test
public void testConvertUtkastToListIntygEntrySetsStatusCancelledIfApplicable() {
    Utkast utkast = createUtkast();
    utkast.setStatus(UtkastStatus.SIGNED);
    utkast.setAterkalladDatum(LocalDateTime.now());
    ListIntygEntry res = IntygDraftsConverter.convertUtkastToListIntygEntry(utkast);
    assertNotNull(res);
    assertEquals(CertificateState.CANCELLED.name(), res.getStatus());
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) Test(org.junit.Test)

Example 24 with ListIntygEntry

use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.

the class IntygDraftsConverterTest method testConvertUtkastToListIntygEntrySetsSentBeforeReceived.

@Test
public void testConvertUtkastToListIntygEntrySetsSentBeforeReceived() {
    Signatur signatur = mock(Signatur.class);
    Utkast utkast = createUtkast();
    utkast.setStatus(UtkastStatus.SIGNED);
    utkast.setSignatur(signatur);
    utkast.setSkickadTillMottagareDatum(LocalDateTime.now());
    when(signatur.getSigneringsDatum()).thenReturn(LocalDateTime.now());
    ListIntygEntry res = IntygDraftsConverter.convertUtkastToListIntygEntry(utkast);
    assertNotNull(res);
    assertEquals(CertificateState.SENT.name(), res.getStatus());
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) Test(org.junit.Test)

Example 25 with ListIntygEntry

use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.

the class IntygServiceImpl method listIntyg.

@Override
public Pair<List<ListIntygEntry>, Boolean> listIntyg(List<String> enhetId, Personnummer personnummer) {
    ListCertificatesForCareType request = new ListCertificatesForCareType();
    request.setPersonId(InternalConverterUtil.getPersonId(personnummer));
    SekretessStatus sekretessmarkering = patientDetailsResolver.getSekretessStatus(personnummer);
    for (String id : enhetId) {
        request.getEnhetsId().add(InternalConverterUtil.getHsaId(id));
    }
    try {
        ListCertificatesForCareResponseType response = listCertificateService.listCertificatesForCare(logicalAddress, request);
        List<ListIntygEntry> fullIntygItemList = intygConverter.convertIntygToListIntygEntries(response.getIntygsLista().getIntyg());
        intygRelationHelper.decorateIntygListWithRelations(fullIntygItemList);
        fullIntygItemList = filterByIntygTypeForUser(fullIntygItemList, sekretessmarkering);
        addDraftsToListForIntygNotSavedInIntygstjansten(fullIntygItemList, enhetId, personnummer);
        return Pair.of(fullIntygItemList, Boolean.FALSE);
    } catch (WebServiceException wse) {
        LOG.warn("Error when connecting to intygstjÀnsten: {}", wse.getMessage());
    }
    // If intygstjansten was unavailable, we return whatever certificates we can find and clearly inform
    // the caller that the set of certificates are only those that have been issued by WebCert.
    List<ListIntygEntry> intygItems = buildIntygItemListFromDrafts(enhetId, personnummer);
    for (ListIntygEntry lie : intygItems) {
        lie.setRelations(certificateRelationService.getRelations(lie.getIntygId()));
    }
    return Pair.of(intygItems, Boolean.TRUE);
}
Also used : ListCertificatesForCareType(se.riv.clinicalprocess.healthcond.certificate.listcertificatesforcare.v3.ListCertificatesForCareType) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebServiceException(javax.xml.ws.WebServiceException) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) ListCertificatesForCareResponseType(se.riv.clinicalprocess.healthcond.certificate.listcertificatesforcare.v3.ListCertificatesForCareResponseType)

Aggregations

ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)26 Test (org.junit.Test)16 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)5 List (java.util.List)4 Response (javax.ws.rs.core.Response)3 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)3 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 ListCertificatesForCareType (se.riv.clinicalprocess.healthcond.certificate.listcertificatesforcare.v3.ListCertificatesForCareType)2 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 WebServiceException (javax.xml.ws.WebServiceException)1 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)1 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)1 IntygRelations (se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.IntygRelations)1