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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations