Search in sources :

Example 6 with Relation

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

the class IntygServiceSendTest method testSendIntygFailsForReplacedCertificate.

@Test(expected = WebCertServiceException.class)
public void testSendIntygFailsForReplacedCertificate() throws Exception {
    final String completionMeddelandeId = "meddelandeId";
    WebCertUser webCertUser = createUser();
    Utlatande completionUtlatande = utlatande;
    completionUtlatande.getGrundData().setRelation(new Relation());
    completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
    completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
    when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(eq(INTYG_ID), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.of(ersattRelation));
    CertificateMetaData metaData = new CertificateMetaData();
    metaData.setStatus(new ArrayList<>());
    CertificateResponse revokedCertificateResponse = new CertificateResponse(json, utlatande, metaData, false);
    when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenReturn(revokedCertificateResponse);
    when(moduleFacade.getUtlatandeFromInternalModel(any(), any())).thenReturn(utlatande);
    intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    verifyZeroInteractions(logService);
}
Also used : Relation(se.inera.intyg.common.support.model.common.internal.Relation) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) CertificateResponse(se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CertificateMetaData(se.inera.intyg.common.support.modules.support.api.dto.CertificateMetaData) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 7 with Relation

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

the class CreateRenewalCopyUtkastBuilder method createRelation.

private Relation createRelation(CreateRenewalCopyRequest request, RelationKod relationKod) {
    Relation relation = new Relation();
    relation.setRelationIntygsId(request.getOriginalIntygId());
    relation.setRelationKod(relationKod);
    return relation;
}
Also used : Relation(se.inera.intyg.common.support.model.common.internal.Relation)

Example 8 with Relation

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

the class CopyCompletionUtkastBuilder method createRelation.

private Relation createRelation(CreateCompletionCopyRequest request, RelationKod relationKod) {
    Relation relation = new Relation();
    relation.setRelationIntygsId(request.getOriginalIntygId());
    relation.setRelationKod(relationKod);
    relation.setMeddelandeId(request.getMeddelandeId());
    relation.setReferensId(getArendeReferensId(request.getMeddelandeId(), request.getTyp()));
    return relation;
}
Also used : Relation(se.inera.intyg.common.support.model.common.internal.Relation)

Example 9 with Relation

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

the class IntygServiceSendTest method testSendIntygCompletion.

@Test
public void testSendIntygCompletion() throws Exception {
    final String completionMeddelandeId = "meddelandeId";
    WebCertUser webCertUser = createUser();
    when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.FALSE);
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    Utlatande completionUtlatande = utlatande;
    completionUtlatande.getGrundData().setRelation(new Relation());
    completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
    completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
    when(moduleFacade.getUtlatandeFromInternalModel(isNull(), anyString())).thenReturn(completionUtlatande);
    when(certificateRelationService.getNewestRelationOfType(eq(INTYG_ID), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.empty());
    IntygServiceResult res = intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    assertEquals(IntygServiceResult.OK, res);
    verify(logService).logSendIntygToRecipient(any(LogRequest.class));
    verify(certificateSenderService).sendCertificate(anyString(), any(Personnummer.class), anyString(), anyString(), eq(false));
    verify(intygRepository, times(2)).findOne(INTYG_ID);
    verify(intygRepository).save(any(Utkast.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Relation(se.inera.intyg.common.support.model.common.internal.Relation) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) IntygServiceResult(se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 10 with Relation

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

the class IntygServiceSendTest method testSendIntygReturnsInfo.

@Test
public void testSendIntygReturnsInfo() throws Exception {
    final String completionMeddelandeId = "meddelandeId";
    SendCertificateToRecipientResponseType response = new SendCertificateToRecipientResponseType();
    response.setResult(ResultTypeUtil.infoResult("Info text"));
    WebCertUser webCertUser = createUser();
    Utlatande completionUtlatande = utlatande;
    completionUtlatande.getGrundData().setRelation(new Relation());
    completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
    completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
    when(moduleFacade.getUtlatandeFromInternalModel(isNull(), anyString())).thenReturn(completionUtlatande);
    when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.FALSE);
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    IntygServiceResult res = intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    assertEquals(IntygServiceResult.OK, res);
    verify(logService).logSendIntygToRecipient(any(LogRequest.class));
    verify(certificateSenderService).sendCertificate(anyString(), any(Personnummer.class), anyString(), anyString(), eq(false));
    verify(intygRepository, times(2)).findOne(INTYG_ID);
    verify(intygRepository).save(any(Utkast.class));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) SendCertificateToRecipientResponseType(se.riv.clinicalprocess.healthcond.certificate.sendCertificateToRecipient.v2.SendCertificateToRecipientResponseType) Relation(se.inera.intyg.common.support.model.common.internal.Relation) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) IntygServiceResult(se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult) Fk7263Utlatande(se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

Relation (se.inera.intyg.common.support.model.common.internal.Relation)11 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)8 Test (org.junit.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)6 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)6 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)5 IOException (java.io.IOException)4 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)4 IntygServiceResult (se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult)3 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)2 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)2 Transactional (org.springframework.transaction.annotation.Transactional)1 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)1 Patient (se.inera.intyg.common.support.model.common.internal.Patient)1