Search in sources :

Example 1 with UpdatePatientOnDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest in project webcert by sklintyg.

the class IntygIntegrationServiceImpl method ensureDraftPatientInfoUpdated.

/**
 * Updates Patient section of a draft with updated patient details for selected types.
 */
void ensureDraftPatientInfoUpdated(String intygsType, String draftId, long draftVersion, WebCertUser user) {
    // To be allowed to update utkast, we need to have the same authority as when saving a draft..
    authoritiesValidator.given(user, intygsType).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    String alternatePatientSSn = user.getParameters().getAlternateSsn();
    Personnummer personnummer = Personnummer.createPersonnummer(alternatePatientSSn).orElse(null);
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(personnummer, draftId, draftVersion);
    utkastService.updatePatientOnDraft(request);
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest)

Example 2 with UpdatePatientOnDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest in project webcert by sklintyg.

the class UtkastServiceImplTest method testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException.

@Test(expected = WebCertServiceException.class)
public void testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException() throws Exception {
    utkast.setEnhetsId("<unknownenhet>");
    Patient newPatient = getUpdatedPatient();
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(newPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    // 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(userService.getUser()).thenReturn(user);
    draftService.updatePatientOnDraft(request);
    verifyNoMoreInteractions(mockUtkastRepository, notificationService);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) 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)

Example 3 with UpdatePatientOnDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest 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)

Example 4 with UpdatePatientOnDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest in project webcert by sklintyg.

the class UtkastServiceImplTest method testUpdatePatientOnDraft.

@Test
public void testUpdatePatientOnDraft() throws Exception {
    utkast.setEnhetsId(UTKAST_ENHETS_ID);
    Patient newPatient = getUpdatedPatient();
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(newPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    String expectedPatientId = defaultPatient.getPersonId().getPersonnummer();
    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.updateBeforeSave(anyString(), any(Patient.class))).thenReturn("{}");
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    draftService.updatePatientOnDraft(request);
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
    verify(utkast).setPatientPersonnummer(any(Personnummer.class));
    assertEquals(expectedPatientId, 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) Patient(se.inera.intyg.common.support.model.common.internal.Patient) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 5 with UpdatePatientOnDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest in project webcert by sklintyg.

the class UtkastServiceImplTest method testUpdatePatientOnDraftEmptyPatientId.

@Test
public void testUpdatePatientOnDraftEmptyPatientId() throws Exception {
    utkast.setEnhetsId(UTKAST_ENHETS_ID);
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(null, 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

UpdatePatientOnDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest)5 Test (org.junit.Test)4 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)4 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)4 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)4 Personnummer (se.inera.intyg.schemas.contract.Personnummer)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 Patient (se.inera.intyg.common.support.model.common.internal.Patient)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1