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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations