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