Search in sources :

Example 1 with IntygServiceResult

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult in project webcert by sklintyg.

the class IntygModuleApiController method revokeSignedIntyg.

/**
 * Issues a request to Intygstjanst to revoke the signed intyg.
 *
 * @param intygsId The id of the intyg to revoke
 * @param param    A JSON struct containing an optional message
 */
@POST
@Path("/{intygsTyp}/{intygsId}/aterkalla")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response revokeSignedIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, RevokeSignedIntygParameter param) {
    validateRevokeAuthority(intygsTyp);
    if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_MAKULERA_INTYG_KRAVER_ANLEDNING).isVerified() && !param.isValid()) {
        LOG.warn("Request to revoke '{}' is not valid", intygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
    }
    IntygServiceResult result = revokeIntyg(intygsTyp, intygsId, param);
    return Response.ok(result).build();
}
Also used : IntygServiceResult(se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 2 with IntygServiceResult

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult in project webcert by sklintyg.

the class IntygModuleApiController method sendSignedIntyg.

/**
 * Issues a request to Intygstjanst to send the signed intyg to a recipient.
 */
@POST
@Path("/{intygsTyp}/{intygsId}/skicka")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response sendSignedIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, SendSignedIntygParameter param) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_SKICKA_INTYG).orThrow();
    IntygServiceResult sendResult = intygService.sendIntyg(intygsId, intygsTyp, param.getRecipient(), false);
    return Response.ok(sendResult).build();
}
Also used : IntygServiceResult(se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult)

Example 3 with IntygServiceResult

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult in project webcert by sklintyg.

the class IntygServiceRevokeTest method testRevokeIntyg.

@Test
public void testRevokeIntyg() throws Exception {
    when(intygRepository.findOne(INTYG_ID)).thenReturn(signedUtkast);
    // do the call
    IntygServiceResult res = intygService.revokeIntyg(INTYG_ID, INTYG_TYP_FK, REVOKE_MSG, REVOKE_REASON);
    // verify that services were called
    verify(arendeService).closeAllNonClosed(INTYG_ID);
    verify(notificationService, times(1)).sendNotificationForIntygRevoked(INTYG_ID);
    verify(logService).logRevokeIntyg(any(LogRequest.class));
    verify(intygRepository).save(any(Utkast.class));
    verify(certificateSenderService, times(1)).revokeCertificate(eq(INTYG_ID), any(), eq(INTYG_TYP_FK));
    verify(moduleFacade, times(1)).getRevokeCertificateRequest(eq(INTYG_TYP_FK), any(), any(), eq(REVOKE_MSG));
    verify(monitoringService).logIntygRevoked(INTYG_ID, HSA_ID, REVOKE_REASON);
    assertEquals(IntygServiceResult.OK, res);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygServiceResult(se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Example 4 with IntygServiceResult

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult in project webcert by sklintyg.

the class IntygServiceSendTest method testSendIntyg.

@Test
public void testSendIntyg() 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(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) 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 5 with IntygServiceResult

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult 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)

Aggregations

IntygServiceResult (se.inera.intyg.webcert.web.service.intyg.dto.IntygServiceResult)7 Test (org.junit.Test)5 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)4 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)3 Relation (se.inera.intyg.common.support.model.common.internal.Relation)3 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)3 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)3 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)3 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 SendCertificateToRecipientResponseType (se.riv.clinicalprocess.healthcond.certificate.sendCertificateToRecipient.v2.SendCertificateToRecipientResponseType)1