Search in sources :

Example 66 with Arende

use of se.inera.intyg.webcert.persistence.arende.model.Arende in project webcert by sklintyg.

the class BaseRestIntegrationTest method createArendeQuestion.

/**
 * Inserts a question of type arende for an existing certificate
 *
 * @param intygTyp
 *            type to create
 * @param intygsId
 *            id of the intyg to create the arende for
 * @param personnummer
 *            patient to create it for
 * @return
 */
protected String createArendeQuestion(String intygTyp, String intygsId, String personnummer, ArendeAmne messageType) {
    Arende arende;
    switch(messageType) {
        case AVSTMN:
            arende = createAvstamningArendeFromFktoWebcertUser(intygTyp, intygsId, personnummer);
            break;
        case KOMPLT:
            arende = createKompletteringArendeFromFkToWebcertUser(intygTyp, intygsId, personnummer);
            break;
        default:
            throw new IllegalArgumentException();
    }
    Response response = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).body(arende).expect().statusCode(200).when().post("testability/arendetest").then().extract().response();
    JsonPath model = new JsonPath(response.body().asString());
    return model.get("meddelandeId");
}
Also used : Response(com.jayway.restassured.response.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) JsonPath(com.jayway.restassured.path.json.JsonPath)

Example 67 with Arende

use of se.inera.intyg.webcert.persistence.arende.model.Arende in project webcert by sklintyg.

the class ArendeServiceImpl method updateRelated.

private void updateRelated(Arende arende) {
    Arende orig;
    if (arende.getSvarPaId() != null) {
        orig = arendeRepository.findOneByMeddelandeId(arende.getSvarPaId());
        if (orig != null) {
            orig.setSenasteHandelse(arende.getSenasteHandelse());
            orig.setStatus(arende.getStatus());
            arendeRepository.save(orig);
        }
    } else if (arende.getPaminnelseMeddelandeId() != null) {
        orig = arendeRepository.findOneByMeddelandeId(arende.getPaminnelseMeddelandeId());
        if (orig != null) {
            orig.setSenasteHandelse(arende.getSenasteHandelse());
            arendeRepository.save(orig);
        }
    }
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende)

Example 68 with Arende

use of se.inera.intyg.webcert.persistence.arende.model.Arende in project webcert by sklintyg.

the class ArendeServiceImpl method openArendeAsUnhandled.

@Override
public ArendeConversationView openArendeAsUnhandled(String meddelandeId) {
    Arende arende = lookupArende(meddelandeId);
    boolean arendeIsAnswered = !arendeRepository.findBySvarPaId(meddelandeId).isEmpty();
    // Enforce business rule FS-011, from FK + answer should remain closed
    if (!FrageStallare.WEBCERT.isKodEqual(arende.getSkickatAv()) && arendeIsAnswered) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FS-011: Cant revert status for question " + meddelandeId);
    }
    NotificationEvent notificationEvent = determineNotificationEvent(arende, arendeIsAnswered);
    if (arendeIsAnswered) {
        arende.setStatus(Status.ANSWERED);
    } else {
        if (FrageStallare.WEBCERT.isKodEqual(arende.getSkickatAv())) {
            arende.setStatus(Status.PENDING_EXTERNAL_ACTION);
        } else {
            arende.setStatus(Status.PENDING_INTERNAL_ACTION);
        }
    }
    Arende openedArende = arendeRepository.save(arende);
    sendNotification(openedArende, notificationEvent);
    return arendeViewConverter.convertToArendeConversationView(openedArende, arendeRepository.findBySvarPaId(meddelandeId).stream().findFirst().orElse(null), null, arendeRepository.findByPaminnelseMeddelandeId(meddelandeId), null);
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 69 with Arende

use of se.inera.intyg.webcert.persistence.arende.model.Arende in project webcert by sklintyg.

the class ArendeServiceImpl method processIncomingMessage.

@Override
public Arende processIncomingMessage(Arende arende) {
    if (arendeRepository.findOneByMeddelandeId(arende.getMeddelandeId()) != null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "meddelandeId not unique");
    }
    Utkast utkast = utkastRepository.findOne(arende.getIntygsId());
    validateArende(arende.getIntygsId(), utkast);
    ArendeConverter.decorateArendeFromUtkast(arende, utkast, LocalDateTime.now(systemClock), hsaEmployeeService);
    updateRelated(arende);
    monitoringLog.logArendeReceived(arende.getIntygsId(), utkast.getIntygsTyp(), utkast.getEnhetsId(), arende.getAmne(), arende.getKomplettering().stream().map(MedicinsktArende::getFrageId).collect(Collectors.toList()), arende.getSvarPaId() != null);
    Arende saved = arendeRepository.save(arende);
    if (ArendeAmne.PAMINN == saved.getAmne() || saved.getSvarPaId() == null) {
        notificationService.sendNotificationForQuestionReceived(saved);
    } else {
        notificationService.sendNotificationForAnswerRecieved(saved);
    }
    return saved;
}
Also used : MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 70 with Arende

use of se.inera.intyg.webcert.persistence.arende.model.Arende in project webcert by sklintyg.

the class ArendeServiceImpl method setForwarded.

@Override
@Transactional
public List<ArendeConversationView> setForwarded(String intygsId) {
    WebCertUser user = webcertUserService.getUser();
    List<Arende> arendenToForward = arendeRepository.save(arendeRepository.findByIntygsId(intygsId).stream().filter(isCorrectEnhet(user)).filter(isQuestion()).peek(arende -> authoritiesValidator.given(user, arende.getIntygTyp()).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_FRAGASVAR).orThrow()).peek(Arende::setArendeToVidareBerordrat).collect(Collectors.toList()));
    if (arendenToForward.isEmpty()) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find any arende related to IntygsId: " + intygsId);
    }
    return getArendeConversationViewList(intygsId, arendenToForward);
}
Also used : Arrays(java.util.Arrays) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) CertificateSenderService(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderService) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) SendMessageToRecipientTypeConverter(se.inera.intyg.webcert.common.client.converter.SendMessageToRecipientTypeConverter) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) HsaEmployeeService(se.inera.intyg.infra.integration.hsa.services.HsaEmployeeService) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Objects(java.util.Objects) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) NotNull(org.jetbrains.annotations.NotNull) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvarService(se.inera.intyg.webcert.web.service.fragasvar.FragaSvarService) SendMessageToRecipientTypeBuilder(se.inera.intyg.webcert.web.integration.builders.SendMessageToRecipientTypeBuilder) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Value(org.springframework.beans.factory.annotation.Value) ArendeConverter(se.inera.intyg.webcert.web.converter.ArendeConverter) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) Service(org.springframework.stereotype.Service) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Clock(java.time.Clock) FilterConverter(se.inera.intyg.webcert.web.converter.FilterConverter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)125 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)95 Test (org.junit.Test)88 Filter (se.inera.intyg.webcert.persistence.model.Filter)32 LocalDateTime (java.time.LocalDateTime)20 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)20 Matchers.anyString (org.mockito.Matchers.anyString)17 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)15 ArendeConversationView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView)14 ArendeAmne (se.inera.intyg.webcert.persistence.arende.model.ArendeAmne)12 QueryFragaSvarParameter (se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter)11 QueryFragaSvarResponse (se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse)11 ArendeView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView)8 ImmutableList (com.google.common.collect.ImmutableList)6 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)6 NotificationEvent (se.inera.intyg.webcert.web.service.notification.NotificationEvent)6 ArendeListItem (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem)6 SendMessageToRecipientType (se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType)6 ArrayList (java.util.ArrayList)5