use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType in project webcert by sklintyg.
the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateHsaException.
@Test
public void testCreateDraftCertificateHsaException() {
when(webcertUserDetailsService.loadUserByHsaId(USER_HSAID)).thenThrow(new MissingMedarbetaruppdragException(USER_HSAID));
CreateDraftCertificateType certificateType = createCertificateType();
CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
verifyZeroInteractions(mockUtkastService);
verifyZeroInteractions(mockIntegreradeEnheterService);
verify(monitoringLogService).logMissingMedarbetarUppdrag(USER_HSAID, UNIT_HSAID);
assertNotNull(response);
assertEquals(response.getResult().getResultCode(), ResultCodeType.ERROR);
assertEquals(ErrorIdType.VALIDATION_ERROR, response.getResult().getErrorId());
assertEquals("No valid MIU was found for person SE1234567890 on unit SE0987654321, can not create draft!", response.getResult().getResultText());
}
use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType in project webcert by sklintyg.
the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateHsaReturnsNoMIUs.
@Test
public void testCreateDraftCertificateHsaReturnsNoMIUs() {
WebCertUser userWithNoMiu = buildWebCertUser();
userWithNoMiu.setVardgivare(new ArrayList<>());
when(webcertUserDetailsService.loadUserByHsaId(USER_HSAID)).thenReturn(userWithNoMiu);
ResultValidator resultsValidator = new ResultValidator();
CreateDraftCertificateType certificateType = createCertificateType();
when(mockValidator.validate(any(Utlatande.class))).thenReturn(resultsValidator);
CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
verifyZeroInteractions(mockUtkastService);
verifyZeroInteractions(mockIntegreradeEnheterService);
verify(monitoringLogService).logMissingMedarbetarUppdrag(USER_HSAID, UNIT_HSAID);
assertNotNull(response);
assertEquals(response.getResult().getResultCode(), ResultCodeType.ERROR);
assertEquals(ErrorIdType.VALIDATION_ERROR, response.getResult().getErrorId());
assertEquals("No valid MIU was found for person SE1234567890 on unit SE0987654321, can not create draft!", response.getResult().getResultText());
}
use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType in project webcert by sklintyg.
the class CreateDraftCertificateResponderImplTest method whenNewCertificateDraftSuccessResponse.
/**
* When a new certificate draft is being created the caller
* should get a success response returned and any stakeholder
* should be notified with a notification message.
*/
@Test
public void whenNewCertificateDraftSuccessResponse() {
// Given
ResultValidator resultsValidator = new ResultValidator();
Vardgivare vardgivare = createVardgivare();
Vardenhet vardenhet = createVardenhet(vardgivare);
CreateNewDraftRequest draftRequest = createCreateNewDraftRequest(vardenhet);
CreateDraftCertificateType certificateType = createCertificateType();
VardpersonReferens vardperson = createVardpersonReferens(certificateType.getUtlatande().getSkapadAv().getPersonalId().getRoot(), certificateType.getUtlatande().getSkapadAv().getFullstandigtNamn());
Utkast utkast = createUtkast(UTKAST_ID, Long.parseLong(UTKAST_VERSION), UTKAST_TYPE, UtkastStatus.DRAFT_INCOMPLETE, UTKAST_JSON, vardperson);
// When
when(mockValidator.validate(any(Utlatande.class))).thenReturn(resultsValidator);
when(mockRequestBuilder.buildCreateNewDraftRequest(any(Utlatande.class), any(IntygUser.class))).thenReturn(draftRequest);
when(mockUtkastService.createNewDraft(any(CreateNewDraftRequest.class))).thenReturn(utkast);
when(takService.verifyTakningForCareUnit(any(String.class), any(String.class), any(SchemaVersion.class), any(IntygUser.class))).thenReturn(new TakResult(true, Lists.emptyList()));
// Then
CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
verify(mockUtkastService).createNewDraft(any(CreateNewDraftRequest.class));
verify(mockIntegreradeEnheterService).putIntegreradEnhet(any(IntegreradEnhetEntry.class), eq(true), eq(false));
verify(takService).verifyTakningForCareUnit(any(String.class), any(String.class), any(SchemaVersion.class), any(IntygUser.class));
// Assert response content
assertNotNull(response);
assertEquals(response.getResult().getResultCode(), ResultCodeType.OK);
assertEquals(response.getUtlatandeId().getExtension(), UTKAST_ID);
}
use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType in project webcert by sklintyg.
the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateApplicationError.
@Test
public void testCreateDraftCertificateApplicationError() {
final String validationError = "error";
ResultValidator resultsValidator = new ResultValidator();
resultsValidator.addError(validationError);
CreateDraftCertificateType certificateType = createCertificateType();
when(mockValidator.validate(any(Utlatande.class))).thenReturn(new ResultValidator());
when(mockValidator.validateApplicationErrors(any(Utlatande.class), any(IntygUser.class))).thenReturn(resultsValidator);
CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
verifyZeroInteractions(mockUtkastService);
verifyZeroInteractions(mockIntegreradeEnheterService);
assertNotNull(response);
assertEquals(response.getResult().getResultCode(), ResultCodeType.ERROR);
assertEquals(ErrorIdType.APPLICATION_ERROR, response.getResult().getErrorId());
assertEquals(validationError, response.getResult().getResultText());
}
use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType in project webcert by sklintyg.
the class CreateDraftCertificateResponderImplTest method createCertificateType.
private CreateDraftCertificateType createCertificateType() {
// Type
TypAvUtlatande utlTyp = new TypAvUtlatande();
utlTyp.setCode("fk7263");
// HoSPerson
HsaId userHsaId = new HsaId();
userHsaId.setExtension(USER_HSAID);
userHsaId.setRoot("USERHSAID");
HsaId unitHsaId = new HsaId();
unitHsaId.setExtension(UNIT_HSAID);
unitHsaId.setRoot("UNITHSAID");
Enhet hosEnhet = new Enhet();
hosEnhet.setEnhetsId(unitHsaId);
HosPersonal hosPerson = new HosPersonal();
hosPerson.setFullstandigtNamn("Abel Baker");
hosPerson.setPersonalId(userHsaId);
hosPerson.setEnhet(hosEnhet);
// Patient
PersonId personId = new PersonId();
personId.setRoot("PERSNR");
personId.setExtension("19121212-1212");
Patient patType = new Patient();
patType.setPersonId(personId);
patType.getFornamn().add("Adam");
patType.getFornamn().add("Bertil");
patType.getMellannamn().add("Cesarsson");
patType.getMellannamn().add("Davidsson");
patType.setEfternamn("Eriksson");
Utlatande utlatande = new Utlatande();
utlatande.setTypAvUtlatande(utlTyp);
utlatande.setSkapadAv(hosPerson);
utlatande.setPatient(patType);
CreateDraftCertificateType certificateType = new CreateDraftCertificateType();
certificateType.setUtlatande(utlatande);
return certificateType;
}
Aggregations