Search in sources :

Example 1 with SchemaVersion

use of se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion in project webcert by sklintyg.

the class IntegreradeEnheterRegistryImplTest method testGetSchemaVersionOldV1Found.

@Test
public void testGetSchemaVersionOldV1Found() {
    final String enhetsId = "enhetsid";
    IntegreradEnhet enhet = new IntegreradEnhet();
    enhet.setSchemaVersion1(true);
    when(integreradEnhetRepository.findOne(eq(enhetsId))).thenReturn(enhet);
    Optional<SchemaVersion> result = registry.getSchemaVersion(enhetsId, Fk7263EntryPoint.MODULE_ID);
    assertTrue(result.isPresent());
    assertEquals(SchemaVersion.VERSION_1, result.get());
}
Also used : SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) IntegreradEnhet(se.inera.intyg.webcert.persistence.integreradenhet.model.IntegreradEnhet) Test(org.junit.Test)

Example 2 with SchemaVersion

use of se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion in project webcert by sklintyg.

the class IntegreradeEnheterRegistryImplTest method testGetSchemaVersionNewFound.

@Test
public void testGetSchemaVersionNewFound() {
    final String enhetsId = "enhetsid";
    IntegreradEnhet enhet = new IntegreradEnhet();
    enhet.setSchemaVersion1(false);
    enhet.setSchemaVersion3(true);
    when(integreradEnhetRepository.findOne(enhetsId)).thenReturn(enhet);
    Optional<SchemaVersion> result = registry.getSchemaVersion(enhetsId, LuseEntryPoint.MODULE_ID);
    assertTrue(result.isPresent());
    assertEquals(SchemaVersion.VERSION_3, result.get());
}
Also used : SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) IntegreradEnhet(se.inera.intyg.webcert.persistence.integreradenhet.model.IntegreradEnhet) Test(org.junit.Test)

Example 3 with SchemaVersion

use of se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion in project webcert by sklintyg.

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Utlatande utkastsParams = parameters.getUtlatande();
    // Redo this: Build a full Vårdgivare -> Vårdenhet -> Mottagning tree and then check.
    String invokingUserHsaId = utkastsParams.getSkapadAv().getPersonalId().getExtension();
    String invokingUnitHsaId = utkastsParams.getSkapadAv().getEnhet().getEnhetsId().getExtension();
    IntygUser user;
    try {
        user = webcertUserDetailsService.loadUserByHsaId(invokingUserHsaId);
    } catch (Exception e) {
        return createMIUErrorResponse(utkastsParams);
    }
    // Validate draft parameters
    ResultValidator resultsValidator = validator.validate(utkastsParams);
    if (resultsValidator.hasErrors()) {
        return createValidationErrorResponse(resultsValidator);
    }
    ResultValidator appErrorsValidator = validator.validateApplicationErrors(utkastsParams, user);
    if (appErrorsValidator.hasErrors()) {
        return createApplicationErrorResponse(appErrorsValidator);
    }
    LOG.debug("Creating draft for invoker '{}' on unit '{}'", invokingUserHsaId, invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!checkMIU(user, invokingUnitHsaId)) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = utkastsParams.getTypAvUtlatande().getCode().toLowerCase();
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft reques"));
    final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp + " kan inte utfärdas för patienter med sekretessmarkering", ErrorIdType.APPLICATION_ERROR);
    }
    Map<String, Map<String, Boolean>> intygstypToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
    String uniqueErrorString = AuthoritiesHelperUtil.validateMustBeUnique(user, intygsTyp, intygstypToBoolean);
    if (!uniqueErrorString.isEmpty()) {
        return createErrorResponse(uniqueErrorString, ErrorIdType.APPLICATION_ERROR);
    }
    if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_TAK_KONTROLL).isVerified()) {
        // Check if invoking health care unit has required TAK
        SchemaVersion schemaVersion = integreradeEnheterRegistry.getSchemaVersion(invokingUnitHsaId, intygsTyp).orElse(SchemaVersion.VERSION_1);
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, schemaVersion, user);
        if (!takResult.isValid()) {
            String error = Joiner.on("; ").join(takResult.getErrorMessages());
            return createErrorResponse(error, ErrorIdType.APPLICATION_ERROR);
        }
    }
    // Create the draft
    Utkast utkast = createNewDraft(utkastsParams, user);
    return createSuccessResponse(utkast.getIntygsId());
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map)

Example 4 with SchemaVersion

use of se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion in project webcert by sklintyg.

the class NotificationServiceImpl method createAndSendNotificationForQAs.

protected void createAndSendNotificationForQAs(Utkast utkast, NotificationEvent event, ArendeAmne amne, LocalDate sistaDatumForSvar) {
    Optional<SchemaVersion> version = sendNotificationStrategy.decideNotificationForIntyg(utkast);
    if (!version.isPresent()) {
        LOGGER.debug("Schema version is not present. Notification message not sent");
        return;
    }
    HandelsekodEnum handelse = null;
    if (SchemaVersion.VERSION_3 == version.get()) {
        handelse = getHandelseV3(event);
    } else {
        handelse = getHandelseV1(event);
    }
    if (handelse == null) {
        LOGGER.debug("Notification message not sent for event {} in version {}", event.name(), version.get().name());
        return;
    }
    createAndSendNotification(utkast, handelse, amne, sistaDatumForSvar, version.get());
}
Also used : SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) HandelsekodEnum(se.inera.intyg.common.support.common.enumerations.HandelsekodEnum)

Example 5 with SchemaVersion

use of se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion in project webcert by sklintyg.

the class IntegreradeEnheterRegistryImplTest method testGetSchemaVersionOldV3Found.

@Test
public void testGetSchemaVersionOldV3Found() {
    final String enhetsId = "enhetsid";
    IntegreradEnhet enhet = new IntegreradEnhet();
    enhet.setSchemaVersion1(true);
    enhet.setSchemaVersion3(true);
    when(integreradEnhetRepository.findOne(eq(enhetsId))).thenReturn(enhet);
    Optional<SchemaVersion> result = registry.getSchemaVersion(enhetsId, Fk7263EntryPoint.MODULE_ID);
    assertTrue(result.isPresent());
    assertEquals(SchemaVersion.VERSION_3, result.get());
}
Also used : SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) IntegreradEnhet(se.inera.intyg.webcert.persistence.integreradenhet.model.IntegreradEnhet) Test(org.junit.Test)

Aggregations

SchemaVersion (se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion)5 Test (org.junit.Test)3 IntegreradEnhet (se.inera.intyg.webcert.persistence.integreradenhet.model.IntegreradEnhet)3 Map (java.util.Map)1 HandelsekodEnum (se.inera.intyg.common.support.common.enumerations.HandelsekodEnum)1 IntygUser (se.inera.intyg.infra.security.common.model.IntygUser)1 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 TakResult (se.inera.intyg.webcert.integration.tak.model.TakResult)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1 ResultValidator (se.inera.intyg.webcert.web.integration.validators.ResultValidator)1 Utlatande (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande)1