Search in sources :

Example 6 with WebcertCertificateRelation

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

the class IntygRelationHelperImplTest method buildWebcertRelationsWithParent.

private Relations buildWebcertRelationsWithParent() {
    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));
    relations.setParent(new WebcertCertificateRelation(PARENT_INTYG_1, RelationKod.KOMPLT, LocalDateTime.now().minusDays(3), 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)

Example 7 with WebcertCertificateRelation

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

the class IntygRelationHelperImpl method applyRelation.

/*
     * In this context, all (draft) statuses are SIGNED.
     */
private void applyRelation(String intygId, Relations certificateRelations, Relation r) {
    if (r.getTillIntygsId().getExtension().equals(intygId)) {
        Relations.FrontendRelations latest = certificateRelations.getLatestChildRelations();
        WebcertCertificateRelation wcr = createWebcertCertificateRelation(r, true);
        switch(wcr.getRelationKod()) {
            case ERSATT:
                if (firstSkapadLaterDateThanSecond(wcr, latest.getReplacedByIntyg())) {
                    latest.setReplacedByIntyg(wcr);
                } else if (firstSkapadLaterDateThanSecond(wcr, latest.getReplacedByUtkast())) {
                    latest.setReplacedByUtkast(wcr);
                }
                break;
            case KOMPLT:
                if (firstSkapadLaterDateThanSecond(wcr, latest.getComplementedByIntyg())) {
                    latest.setComplementedByIntyg(wcr);
                } else if (firstSkapadLaterDateThanSecond(wcr, latest.getComplementedByUtkast())) {
                    latest.setComplementedByUtkast(wcr);
                }
                break;
            case FRLANG:
                break;
        }
    } else if (r.getFranIntygsId().getExtension().equals(intygId)) {
        certificateRelations.setParent(createWebcertCertificateRelation(r, false));
    }
}
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)

Example 8 with WebcertCertificateRelation

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

the class CertificateRelationServiceImpl method getRelations.

@Override
public Relations getRelations(String intygsId) {
    Relations relations = new Relations();
    Optional<WebcertCertificateRelation> parentRelation = findParentRelation(intygsId);
    parentRelation.ifPresent(relations::setParent);
    List<WebcertCertificateRelation> childRelations = findChildRelations(intygsId);
    relations.setLatestChildRelations(prepareChildRelationDataForFrontend(childRelations));
    return relations;
}
Also used : WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations)

Example 9 with WebcertCertificateRelation

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

the class CopyUtkastServiceImplTest method testCreateRenewalFailsWhenReplacedBySignedIntyg.

@Test(expected = WebCertServiceException.class)
public void testCreateRenewalFailsWhenReplacedBySignedIntyg() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    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 copyReq = buildRenewalRequest();
    try {
        copyService.createRenewalCopy(copyReq);
        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) 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)

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