Search in sources :

Example 1 with CertificateState

use of se.inera.intyg.common.support.model.CertificateState in project webcert by sklintyg.

the class IntygDraftsConverterTest method testFindLatestStatus.

@Test
public void testFindLatestStatus() {
    LocalDateTime defaultTime = LocalDateTime.now();
    CertificateState res;
    List<IntygsStatus> statuses;
    // test with empty list
    statuses = new ArrayList<>();
    res = IntygDraftsConverter.findLatestStatus(statuses);
    assertEquals(CertificateState.UNHANDLED, res);
    // test with just some statuses
    statuses = new ArrayList<>();
    statuses.add(buildIntygsStatus(StatusKod.RECEIV.name(), defaultTime.minusHours(2)));
    statuses.add(buildIntygsStatus(StatusKod.SENTTO.name(), defaultTime.minusHours(1)));
    res = IntygDraftsConverter.findLatestStatus(statuses);
    assertEquals(CertificateState.SENT, res);
    // test with DELETED in the list, which should be removed
    statuses = new ArrayList<>();
    statuses.add(buildIntygsStatus(StatusKod.CANCEL.name(), defaultTime.minusHours(2)));
    statuses.add(buildIntygsStatus(StatusKod.SENTTO.name(), defaultTime.minusHours(3)));
    statuses.add(buildIntygsStatus(StatusKod.DELETE.name(), defaultTime.minusHours(1)));
    statuses.add(buildIntygsStatus(StatusKod.RECEIV.name(), defaultTime.minusHours(4)));
    res = IntygDraftsConverter.findLatestStatus(statuses);
    assertEquals(CertificateState.CANCELLED, res);
    // test with DELETED and RESTORED in the list, which should be removed
    statuses = new ArrayList<>();
    statuses.add(buildIntygsStatus(StatusKod.CANCEL.name(), defaultTime.minusHours(2)));
    statuses.add(buildIntygsStatus(StatusKod.SENTTO.name(), defaultTime.minusHours(3)));
    statuses.add(buildIntygsStatus(StatusKod.RESTOR.name(), defaultTime.minusMinutes(30)));
    statuses.add(buildIntygsStatus(StatusKod.DELETE.name(), defaultTime.minusHours(1)));
    statuses.add(buildIntygsStatus(StatusKod.RECEIV.name(), defaultTime.minusHours(4)));
    res = IntygDraftsConverter.findLatestStatus(statuses);
    assertEquals(CertificateState.CANCELLED, res);
    // test with just DELETED, which will be removed and result in an empty list
    statuses = new ArrayList<>();
    statuses.add(buildIntygsStatus(StatusKod.DELETE.name(), defaultTime.minusHours(1)));
    res = IntygDraftsConverter.findLatestStatus(statuses);
    assertEquals(CertificateState.UNHANDLED, res);
}
Also used : LocalDateTime(java.time.LocalDateTime) CertificateState(se.inera.intyg.common.support.model.CertificateState) IntygsStatus(se.riv.clinicalprocess.healthcond.certificate.v3.IntygsStatus) Test(org.junit.Test)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 Test (org.junit.Test)1 CertificateState (se.inera.intyg.common.support.model.CertificateState)1 IntygsStatus (se.riv.clinicalprocess.healthcond.certificate.v3.IntygsStatus)1