Search in sources :

Example 26 with Utlatande

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

the class IntygResource method insertUtkast.

@POST
@Consumes(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Produces(MediaType.APPLICATION_JSON)
@Path("/utkast")
public Response insertUtkast(IntygContentWrapper intygContents) throws ModuleNotFoundException, IOException {
    String intygsTyp = intygContents.getContents().get("typ").textValue();
    String model = intygContents.getContents().toString();
    Utlatande utlatande = moduleFacade.getUtlatandeFromInternalModel(intygsTyp, model);
    Utkast utkast = new Utkast();
    utkast.setModel(model);
    utkast.setEnhetsId(utlatande.getGrundData().getSkapadAv().getVardenhet().getEnhetsid());
    utkast.setEnhetsNamn(utlatande.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn());
    utkast.setVardgivarId(utlatande.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarid());
    utkast.setIntygsTyp(utlatande.getTyp());
    utkast.setIntygsId(utlatande.getId());
    utkast.setPatientEfternamn(utlatande.getGrundData().getPatient().getEfternamn());
    utkast.setPatientFornamn(utlatande.getGrundData().getPatient().getFornamn());
    utkast.setPatientPersonnummer(utlatande.getGrundData().getPatient().getPersonId());
    if (utlatande.getGrundData().getRelation() != null && utlatande.getGrundData().getRelation().getRelationIntygsId() != null) {
        if (utlatande.getId() != null && utlatande.getId().equals(utlatande.getGrundData().getRelation().getRelationIntygsId())) {
            LOG.error("Utkast relation to itself is invalid.");
        } else {
            utkast.setRelationIntygsId(utlatande.getGrundData().getRelation().getRelationIntygsId());
            utkast.setRelationKod(utlatande.getGrundData().getRelation().getRelationKod());
        }
    }
    utkast.setStatus(intygContents.getUtkastStatus());
    utkast.setVidarebefordrad(false);
    if (utkast.getStatus() == UtkastStatus.SIGNED) {
        Signatur signatur = new Signatur(LocalDateTime.now(), utlatande.getGrundData().getSkapadAv().getPersonId(), utlatande.getId(), model, "ruffel", "fusk");
        utkast.setSignatur(signatur);
    }
    VardpersonReferens vardpersonReferens = new VardpersonReferens();
    vardpersonReferens.setHsaId(utlatande.getGrundData().getSkapadAv().getPersonId());
    vardpersonReferens.setNamn(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn());
    utkast.setSkapadAv(vardpersonReferens);
    utkast.setSenastSparadAv(vardpersonReferens);
    utkastRepository.save(utkast);
    return Response.ok().build();
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) Path(javax.ws.rs.Path) XPath(javax.xml.xpath.XPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 27 with Utlatande

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

the class NotificationTransformer method process.

public void process(Message message) throws ModuleException, IOException, ModuleNotFoundException, TemporaryException {
    LOG.debug("Receiving message: {}", message.getMessageId());
    NotificationMessage notificationMessage = message.getBody(NotificationMessage.class);
    message.setHeader(NotificationRouteHeaders.LOGISK_ADRESS, notificationMessage.getLogiskAdress());
    message.setHeader(NotificationRouteHeaders.INTYGS_ID, notificationMessage.getIntygsId());
    // Note that this header have been set already by the original sender to accommodate header-based routing
    // in the aggreagatorRoute. It is 100% safe to overwrite it at this point.
    message.setHeader(NotificationRouteHeaders.HANDELSE, notificationMessage.getHandelse().value());
    if (notificationMessage.getVersion() != null) {
        message.setHeader(NotificationRouteHeaders.VERSION, notificationMessage.getVersion().name());
    } else {
        message.setHeader(NotificationRouteHeaders.VERSION, SchemaVersion.VERSION_1.name());
    }
    if (SchemaVersion.VERSION_3.equals(notificationMessage.getVersion())) {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(notificationMessage.getIntygsTyp());
        Utlatande utlatande = moduleApi.getUtlatandeFromJson(notificationMessage.getUtkast());
        Intyg intyg = moduleApi.getIntygFromUtlatande(utlatande);
        notificationPatientEnricher.enrichWithPatient(intyg);
        message.setBody(NotificationTypeConverter.convert(notificationMessage, intyg));
    } else if (Fk7263EntryPoint.MODULE_ID.equals(notificationMessage.getIntygsTyp())) {
        message.setBody(fk7263Transform.createCertificateStatusUpdateForCareType(notificationMessage));
    } else {
        throw new IllegalArgumentException("Unsupported combination of version '" + notificationMessage.getVersion() + "' and type '" + notificationMessage.getIntygsTyp() + "'");
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande)

Example 28 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande 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 29 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande 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)

Example 30 with Utlatande

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

the class IntygServiceSendTest method testSendIntygThrowsExceptionWhenPUServiceIsUnavailable.

@Test(expected = WebCertServiceException.class)
public void testSendIntygThrowsExceptionWhenPUServiceIsUnavailable() throws IOException {
    final String completionMeddelandeId = "meddelandeId";
    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.UNDEFINED);
    when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
    try {
        intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
    } catch (Exception e) {
        verifyZeroInteractions(logService);
        throw e;
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)18 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)14 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)11 IOException (java.io.IOException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)10 Relation (se.inera.intyg.common.support.model.common.internal.Relation)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)7 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)7 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)7 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)6 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)6 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)6 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)6 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)5 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)3