Search in sources :

Example 1 with WebcertCertificateRelation

use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation 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 2 with WebcertCertificateRelation

use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testRenewalCopyFailIfSignedReplacementExists.

@Test(expected = WebCertServiceException.class)
public void testRenewalCopyFailIfSignedReplacementExists() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.SIGNED))).thenReturn(Optional.of(ersattRelation));
    CreateRenewalCopyRequest renewalCopyRequest = buildRenewalRequest();
    try {
        CreateRenewalCopyResponse copyResp = copyService.createRenewalCopy(renewalCopyRequest);
        fail("An exception should have been thrown.");
    } catch (Exception e) {
        verifyZeroInteractions(mockUtkastRepository);
        verifyZeroInteractions(mockNotificationService);
        verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
        // Assert no pdl logging
        verifyZeroInteractions(logService);
        throw e;
    }
}
Also used : IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 3 with WebcertCertificateRelation

use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg.

@Test(expected = WebCertServiceException.class)
public void testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.values()))).thenReturn(Optional.of(ersattRelation));
    CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
    CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(logService).logCreateIntyg(any(LogRequest.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Example 4 with WebcertCertificateRelation

use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.

the class IntygRelationHelperImplTest method testGetRelationsForIntygNothingInITWithMergeFromWebcert.

@Test
public void testGetRelationsForIntygNothingInITWithMergeFromWebcert() {
    when(listRelationsForCertificateResponderInterface.listRelationsForCertificate(isNull(), any(ListRelationsForCertificateType.class))).thenReturn(new ListRelationsForCertificateResponseType());
    Relations webcertRelations = new Relations();
    Relations.FrontendRelations fr = webcertRelations.getLatestChildRelations();
    fr.setReplacedByIntyg(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.ERSATT, LocalDateTime.now().minusDays(1), UtkastStatus.SIGNED));
    fr.setReplacedByUtkast(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.ERSATT, LocalDateTime.now().minusDays(1), UtkastStatus.DRAFT_COMPLETE));
    fr.setComplementedByIntyg(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.KOMPLT, LocalDateTime.now().minusDays(2), UtkastStatus.SIGNED));
    fr.setComplementedByUtkast(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.KOMPLT, LocalDateTime.now().minusDays(2), UtkastStatus.DRAFT_INCOMPLETE));
    webcertRelations.setParent(new WebcertCertificateRelation(PARENT_INTYG_1, RelationKod.KOMPLT, LocalDateTime.now().minusDays(3), UtkastStatus.SIGNED));
    when(certificateRelationService.getRelations(INTYG_ID)).thenReturn(webcertRelations);
    Relations relationsForIntyg = testee.getRelationsForIntyg(INTYG_ID);
    assertNotNull(relationsForIntyg);
    assertFrontendRelations(relationsForIntyg.getLatestChildRelations(), webcertRelations.getLatestChildRelations().getComplementedByIntyg(), webcertRelations.getLatestChildRelations().getComplementedByUtkast(), webcertRelations.getLatestChildRelations().getReplacedByIntyg(), webcertRelations.getLatestChildRelations().getReplacedByUtkast());
}
Also used : ListRelationsForCertificateResponseType(se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.ListRelationsForCertificateResponseType) ListRelationsForCertificateType(se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.ListRelationsForCertificateType) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IntygRelations(se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.IntygRelations) Test(org.junit.Test)

Example 5 with WebcertCertificateRelation

use of se.inera.intyg.webcert.common.model.WebcertCertificateRelation in project webcert by sklintyg.

the class IntygRelationHelperImplTest method buildWebcertRelations.

private Relations buildWebcertRelations() {
    Relations relations = new Relations();
    Relations.FrontendRelations fr = relations.getLatestChildRelations();
    fr.setReplacedByUtkast(new WebcertCertificateRelation(OTHER_INTYG_ID_2, RelationKod.ERSATT, LocalDateTime.now().minusDays(1), UtkastStatus.DRAFT_COMPLETE));
    fr.setComplementedByIntyg(new WebcertCertificateRelation(OTHER_INTYG_ID_3, RelationKod.KOMPLT, LocalDateTime.now().minusDays(2), UtkastStatus.SIGNED));
    return relations;
}
Also used : WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IntygRelations(se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.IntygRelations)

Aggregations

WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)9 Test (org.junit.Test)5 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 IntygRelations (se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.IntygRelations)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)3 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)2 ListRelationsForCertificateResponseType (se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.ListRelationsForCertificateResponseType)1 ListRelationsForCertificateType (se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.ListRelationsForCertificateType)1 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)1 Relation (se.inera.intyg.common.support.model.common.internal.Relation)1 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)1 CertificateMetaData (se.inera.intyg.common.support.modules.support.api.dto.CertificateMetaData)1 CertificateResponse (se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse)1 Person (se.inera.intyg.infra.integration.pu.model.Person)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1