Search in sources :

Example 6 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class ArendeServiceTest method buildUserOfRole.

private WebCertUser buildUserOfRole(Role role) {
    WebCertUser user = new WebCertUser();
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setOrigin(UserOriginType.NORMAL.name());
    user.setHsaId("testuser");
    user.setNamn("test userman");
    Feature feature = new Feature();
    feature.setName(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR);
    feature.setGlobal(true);
    feature.setIntygstyper(ImmutableList.of(INTYG_TYP));
    user.setFeatures(ImmutableMap.of(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR, feature));
    Vardenhet vardenhet = new Vardenhet(ENHET_ID, "enhet");
    Vardgivare vardgivare = new Vardgivare("vardgivare", "Vardgivaren");
    vardgivare.getVardenheter().add(vardenhet);
    user.setVardgivare(Collections.singletonList(vardgivare));
    user.setValdVardenhet(vardenhet);
    return user;
}
Also used : Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 7 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class ArendeServiceTest method answerUpdatesQuestionTest.

@Test
public void answerUpdatesQuestionTest() throws CertificateSenderException {
    final String svarPaMeddelandeId = "svarPaMeddelandeId";
    Arende fraga = buildArende(svarPaMeddelandeId, null);
    fraga.setAmne(ArendeAmne.OVRIGT);
    fraga.setMeddelandeId(svarPaMeddelandeId);
    fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
    fraga.setPatientPersonId(PERSON_ID);
    when(arendeRepository.findOneByMeddelandeId(svarPaMeddelandeId)).thenReturn(fraga);
    when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
    when(webcertUserService.getUser()).thenReturn(new WebCertUser());
    ArendeConversationView result = service.answer(svarPaMeddelandeId, "svarstext");
    assertNotNull(result.getFraga());
    assertNotNull(result.getSvar());
    assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
    verify(monitoringLog).logArendeCreated(anyString(), anyString(), isNull(), any(ArendeAmne.class), anyBoolean());
    verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
    verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
    ArgumentCaptor<Arende> arendeCaptor = ArgumentCaptor.forClass(Arende.class);
    verify(arendeRepository, times(2)).save(arendeCaptor.capture());
    verify(arendeDraftService).delete(INTYG_ID, svarPaMeddelandeId);
    Arende updatedQuestion = arendeCaptor.getAllValues().get(1);
    assertEquals(FIXED_TIME_INSTANT, updatedQuestion.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
    assertEquals(Status.CLOSED, updatedQuestion.getStatus());
}
Also used : ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Matchers.anyString(org.mockito.Matchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 8 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class BaseCreateDraftCertificateTest method buildWebCertUser.

protected WebCertUser buildWebCertUser() {
    WebCertUser user = new WebCertUser();
    user.setAuthorities(new HashMap<>());
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, createPrivilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT));
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, createPrivilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG));
    // TODO
    user.setFeatures(Stream.of(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST, AuthoritiesConstants.FEATURE_TAK_KONTROLL).collect(Collectors.toMap(Function.identity(), s -> {
        Feature feature = new Feature();
        feature.setName(s);
        feature.setGlobal(true);
        feature.setIntygstyper(Arrays.asList(FK7263, TSBAS));
        return feature;
    })));
    user.setOrigin(UserOriginType.DJUPINTEGRATION.name());
    user.setBefattningar(Arrays.asList(TITLE_CODE));
    user.setSpecialiseringar(Arrays.asList(ALLMAN_MEDICIN, INVARTES_MEDICIN));
    user.setTitel(TITLE_NAME);
    user.setVardgivare(Arrays.asList(createVardgivare()));
    user.setMiuNamnPerEnhetsId(createMiuNamnPerEnhetsId());
    return user;
}
Also used : Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 9 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class BaseCreateDraftCertificateValidatorTest method buildUserUnauthorized.

protected WebCertUser buildUserUnauthorized() {
    WebCertUser user = new WebCertUser();
    user.setAuthorities(new HashMap<>());
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, createPrivilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, ALL_INTYG_TYPES));
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, createPrivilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, ALL_INTYG_TYPES));
    Feature feature = new Feature();
    feature.setName(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    feature.setIntygstyper(Arrays.asList(Fk7263EntryPoint.MODULE_ID, TsBasEntryPoint.MODULE_ID, TsDiabetesEntryPoint.MODULE_ID, LisjpEntryPoint.MODULE_ID, LuaenaEntryPoint.MODULE_ID, LuaefsEntryPoint.MODULE_ID, LuseEntryPoint.MODULE_ID, DbModuleEntryPoint.MODULE_ID, DoiModuleEntryPoint.MODULE_ID));
    user.setFeatures(Collections.singletonMap(feature.getName(), feature));
    user.setOrigin(UserOriginType.DJUPINTEGRATION.name());
    return user;
}
Also used : Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 10 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateNoMIUs.

@Test
public void testCreateDraftCertificateNoMIUs() {
    WebCertUser userWithoutMiu = buildWebCertUser();
    userWithoutMiu.setVardgivare(new ArrayList<>());
    when(webcertUserDetailsService.loadUserByHsaId(USER_HSAID)).thenReturn(userWithoutMiu);
    CreateDraftCertificateType certificateType = createCertificateType();
    when(mockValidator.validate(any(Intyg.class))).thenReturn(new ResultValidator());
    CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
    verify(mockMonitoringLogService).logMissingMedarbetarUppdrag(USER_HSAID, UNIT_HSAID);
    assertNotNull(response);
    assertEquals(response.getResult().getResultCode(), ResultCodeType.ERROR);
    assertEquals(response.getResult().getErrorId(), ErrorIdType.VALIDATION_ERROR);
}
Also used : CreateDraftCertificateResponseType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateResponseType) CreateDraftCertificateType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType) TypAvIntyg(se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg) Intyg(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest) Test(org.junit.Test)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)217 Test (org.junit.Test)123 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)31 Personnummer (se.inera.intyg.schemas.contract.Personnummer)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)23 Role (se.inera.intyg.infra.security.common.model.Role)18 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)16 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)15 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)15 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)14 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)14 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)13 Feature (se.inera.intyg.infra.security.common.model.Feature)13 HashMap (java.util.HashMap)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Path (javax.ws.rs.Path)10