Search in sources :

Example 16 with Utlatande

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

the class IntygServiceImpl method sendIntyg.

@Override
public IntygServiceResult sendIntyg(String intygsId, String typ, String recipient, boolean delay) {
    Utlatande intyg = getUtlatandeForIntyg(intygsId, typ);
    verifyEnhetsAuth(intyg, true);
    if (isRevoked(intygsId, typ, false)) {
        LOG.debug("Cannot send certificate with id '{}', the certificate is revoked", intygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificate is revoked");
    }
    verifyNotReplacedBySignedIntyg(intygsId, "send");
    // WC-US-SM-001 - vi får ej skicka FK-intyg för sekretessmarkerad patient som innehåller personuppgifter.
    verifyNoExposureOfSekretessmarkeradPatient(intyg);
    SendIntygConfiguration sendConfig = new SendIntygConfiguration(recipient, webCertUserService.getUser());
    monitoringService.logIntygSent(intygsId, recipient);
    // send PDL log event
    LogRequest logRequest = LogRequestFactory.createLogRequestFromUtlatande(intyg);
    logRequest.setAdditionalInfo(sendConfig.getPatientConsentMessage());
    logService.logSendIntygToRecipient(logRequest);
    markUtkastWithSendDateAndRecipient(intygsId, recipient);
    return sendIntygToCertificateSender(sendConfig, intyg, delay);
}
Also used : SendIntygConfiguration(se.inera.intyg.webcert.web.service.intyg.config.SendIntygConfiguration) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 17 with Utlatande

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

the class ArendeViewConverter method convertToMedicinsktArendeView.

private List<MedicinsktArendeView> convertToMedicinsktArendeView(List<MedicinsktArende> medicinskaArenden, String intygsId, String intygsTyp) {
    List<MedicinsktArendeView> medicinskaArendenViews = new ArrayList<>();
    if (CollectionUtils.isEmpty(medicinskaArenden)) {
        return medicinskaArendenViews;
    }
    List<String> frageIds = medicinskaArenden.stream().map(MedicinsktArende::getFrageId).distinct().collect(Collectors.toList());
    ModuleApi moduleApi = null;
    try {
        moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    } catch (ModuleNotFoundException e) {
        LOG.error("Module not found for certificate of type {}", intygsTyp);
        Throwables.propagate(e);
    }
    Utlatande utlatande = intygService.fetchIntygData(intygsId, intygsTyp, false).getUtlatande();
    Map<String, List<String>> arendeParameters = moduleApi.getModuleSpecificArendeParameters(utlatande, frageIds);
    for (MedicinsktArende arende : medicinskaArenden) {
        Integer position = getListPositionForInstanceId(arende);
        String jsonPropertyHandle = getJsonPropertyHandle(arende, position, arendeParameters);
        MedicinsktArendeView view = MedicinsktArendeView.builder().setFrageId(arende.getFrageId()).setInstans(arende.getInstans()).setText(arende.getText()).setPosition(Math.max(position - 1, 0)).setJsonPropertyHandle(jsonPropertyHandle).build();
        medicinskaArendenViews.add(view);
    }
    return medicinskaArendenViews;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MedicinsktArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.MedicinsktArendeView)

Example 18 with Utlatande

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

the class UtkastServiceImplTest method testSaveDraftSecondSave.

@Test
public void testSaveDraftSecondSave() throws Exception {
    ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(defaultPatient);
    when(utlatande.getGrundData()).thenReturn(grunddata);
    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(mockModuleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    SaveDraftResponse res = draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
    verify(mockUtkastRepository).save(any(Utkast.class));
    // Assert notification message
    verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
    // Assert that no logs are called
    verifyZeroInteractions(logService);
    verifyZeroInteractions(mockMonitoringService);
    assertNotNull("An DraftValidation should be returned", res);
    assertEquals("Validation should fail", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus());
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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 19 with Utlatande

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

the class UtkastServiceImplTest method setupReferensMocks.

private void setupReferensMocks() throws ModuleNotFoundException, ModuleException, IOException {
    ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
    Utlatande utlatande = mock(Utlatande.class);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockUtkastRepository.save(any(Utkast.class))).then(invocation -> invocation.getArguments()[0]);
}
Also used : ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)

Example 20 with Utlatande

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

the class UtkastServiceImplTest method testUpdatePatientOnDraftSamePatientId.

@Test
public void testUpdatePatientOnDraftSamePatientId() throws Exception {
    utkast.setEnhetsId(UTKAST_ENHETS_ID);
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(defaultPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    when(utlatande.getGrundData()).thenReturn(grunddata);
    // 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.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(userService.getUser()).thenReturn(user);
    draftService.updatePatientOnDraft(request);
    verify(mockUtkastRepository, never()).save(any(Utkast.class));
    verify(notificationService, never()).sendNotificationForDraftChanged(any(Utkast.class));
    verify(utkast, never()).setPatientPersonnummer(any(Personnummer.class));
    assertEquals(defaultPatient.getPersonId().getPersonnummer(), user.getParameters().getBeforeAlternateSsn());
}
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) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)18 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)14 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)11 IOException (java.io.IOException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)10 Relation (se.inera.intyg.common.support.model.common.internal.Relation)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)7 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)7 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)7 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)6 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)6 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)6 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)6 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)5 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)3