Search in sources :

Example 1 with IntygModule

use of se.inera.intyg.common.support.modules.registry.IntygModule in project webcert by sklintyg.

the class ModuleApiController method getModulesMap.

/**
 * Serving module configuration populating selectors based on user.
 *
 * @return a JSON object
 */
@GET
@Path("/map/{patientId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getModulesMap(@PathParam("patientId") String patientId) {
    try {
        Personnummer personnummer = createPnr(patientId);
        SekretessStatus sekretessmarkering = patientDetailsResolver.getSekretessStatus(personnummer);
        List<IntygModule> intygModules = moduleRegistry.listAllModules();
        // If patient has sekretessmarkering or PU-service didn't respond, filter out ts-intyg using privilege.
        if (sekretessmarkering == SekretessStatus.TRUE || sekretessmarkering == SekretessStatus.UNDEFINED) {
            // INTYG-4086
            intygModules = intygModules.stream().filter(module -> authoritiesValidator.given(getWebCertUserService().getUser(), module.getId()).privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT).isVerified()).collect(Collectors.toList());
        }
        if (patientDetailsResolver.isAvliden(personnummer)) {
            intygModules = intygModules.stream().filter(module -> authoritiesValidator.given(getWebCertUserService().getUser(), module.getId()).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST_AVLIDEN).isVerified()).collect(Collectors.toList());
        }
        return Response.ok(intygModules).build();
    } catch (InvalidPersonNummerException e) {
        LOG.error(e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) InvalidPersonNummerException(se.inera.intyg.schemas.contract.InvalidPersonNummerException) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with IntygModule

use of se.inera.intyg.common.support.modules.registry.IntygModule 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 3 with IntygModule

use of se.inera.intyg.common.support.modules.registry.IntygModule in project webcert by sklintyg.

the class IntygServiceTest method testListCertificatesForCareWithQAVardgivare.

@Test
public void testListCertificatesForCareWithQAVardgivare() throws Exception {
    final String vardgivarId = "vardgivarId";
    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.findDraftsByPatientAndVardgivareAndStatus(eq(PERSON_ID), eq(vardgivarId), 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).setVardgivarId(vardgivarId).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());
}
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 4 with IntygModule

use of se.inera.intyg.common.support.modules.registry.IntygModule in project webcert by sklintyg.

the class ModuleApiControllerTest method testGetActiveModulesOnlyReturnsActiveModules.

@SuppressWarnings("unchecked")
@Test
public void testGetActiveModulesOnlyReturnsActiveModules() {
    when(authoritiesHelper.isFeatureActive(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, MODULE_ID_1)).thenReturn(true);
    when(authoritiesHelper.isFeatureActive(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, MODULE_ID_2)).thenReturn(false);
    when(authoritiesHelper.isFeatureActive(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, MODULE_ID_3)).thenReturn(true);
    Response response = moduleApiController.getActiveModules();
    assertNotNull(response);
    List<IntygModule> res = (List<IntygModule>) response.getEntity();
    assertEquals(2, res.size());
    assertEquals(MODULE_ID_1, res.get(0).getId());
    assertEquals(MODULE_ID_3, res.get(1).getId());
}
Also used : Response(javax.ws.rs.core.Response) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) List(java.util.List) Test(org.junit.Test)

Example 5 with IntygModule

use of se.inera.intyg.common.support.modules.registry.IntygModule in project webcert by sklintyg.

the class ModuleApiControllerTest method testGetModuleMap.

@SuppressWarnings("unchecked")
@Test
public void testGetModuleMap() {
    Response response = moduleApiController.getModulesMap();
    assertNotNull(response);
    List<IntygModule> res = (List<IntygModule>) response.getEntity();
    assertEquals(3, res.size());
    assertEquals(MODULE_ID_1, res.get(0).getId());
    assertEquals(ISSUER_TYPE_ID, res.get(0).getIssuerTypeId());
    assertEquals(MODULE_ID_2, res.get(1).getId());
    assertEquals(MODULE_ID_3, res.get(2).getId());
}
Also used : Response(javax.ws.rs.core.Response) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) List(java.util.List) Test(org.junit.Test)

Aggregations

IntygModule (se.inera.intyg.common.support.modules.registry.IntygModule)11 Test (org.junit.Test)9 List (java.util.List)5 Response (javax.ws.rs.core.Response)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 IntygWithNotificationsResponse (se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse)4 LocalDateTime (java.time.LocalDateTime)3 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)3 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)3 Personnummer (se.inera.intyg.schemas.contract.Personnummer)2 Handelse (se.inera.intyg.webcert.persistence.handelse.model.Handelse)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Before (org.junit.Before)1 InvalidPersonNummerException (se.inera.intyg.schemas.contract.InvalidPersonNummerException)1 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)1