use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.
the class IntygServiceImpl method buildIntygContentHolderForUtkast.
// NOTE! INTYG-4086. This method is used when fetching Intyg/Utkast from WC locally. The question is, should we
// replace the patient on the existing model with a freshly fetched one here or not? In case we're storing patient
// info entered manually for non FK-types here, we may end up overwriting a manually stored name etc...
private IntygContentHolder buildIntygContentHolderForUtkast(Utkast utkast, boolean relations) {
try {
// INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
Patient newPatientData = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), utkast.getIntygsTyp());
// create an "empty" Patient with personnummer only.
if (newPatientData == null) {
newPatientData = new Patient();
newPatientData.setPersonId(utkast.getPatientPersonnummer());
}
// INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
Utlatande utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), utkast.getModel());
if (!completeAddressProvided(newPatientData)) {
// Use the old address data.
Patient oldPatientData = utlatande.getGrundData().getPatient();
copyOldAddressToNewPatientData(oldPatientData, newPatientData);
}
String updatedModel = moduleRegistry.getModuleApi(utkast.getIntygsTyp()).updateBeforeSave(utkast.getModel(), newPatientData);
utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), updatedModel);
List<Status> statuses = IntygConverterUtil.buildStatusesFromUtkast(utkast);
Relations certificateRelations = certificateRelationService.getRelations(utkast.getIntygsId());
final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(newPatientData.getPersonId());
if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
}
final boolean sekretessmarkerad = SekretessStatus.TRUE.equals(sekretessStatus);
boolean patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
boolean patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
return IntygContentHolder.builder().setContents(updatedModel).setUtlatande(utlatande).setStatuses(statuses).setRevoked(utkast.getAterkalladDatum() != null).setRelations(certificateRelations).setCreated(utkast.getSkapad()).setDeceased(isDeceased(utkast.getPatientPersonnummer())).setSekretessmarkering(sekretessmarkerad).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
} catch (ModuleException | ModuleNotFoundException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
}
}
use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.
the class PatientDetailsResolverImpl method resolveDoiPatient.
/**
* DOI har en specialregel som säger att namn och adress skall hämtas från ett DB-intyg i det fall sådant finns
* utfärdat inom samma Vårdgivare (Integration) eller Vårdenhet (Fristående).
*/
private Patient resolveDoiPatient(Personnummer personnummer, WebCertUser user) {
PersonSvar personSvar = getPersonSvar(personnummer);
// Find ALL existing intyg for this patient, filter out so we only have DB left.
List<Utkast> utkastList = new ArrayList<>();
if (user.getOrigin().equals(UserOriginType.DJUPINTEGRATION.name())) {
utkastList.addAll(utkastRepository.findDraftsByPatientAndVardgivareAndStatus(personnummer.getPersonnummer(), user.getValdVardgivare().getId(), UTKAST_STATUSES, Sets.newHashSet("db")));
} else {
utkastList.addAll(utkastRepository.findDraftsByPatientAndEnhetAndStatus(personnummer.getPersonnummer(), Arrays.asList(user.getValdVardenhet().getId()), UTKAST_STATUSES, Sets.newHashSet("db")));
}
// Use PU and integration parameters for deceased
if (utkastList.size() > 0) {
Utkast newest = utkastList.stream().sorted((u1, u2) -> u2.getSenastSparadDatum().compareTo(u1.getSenastSparadDatum())).findFirst().orElseThrow(() -> new IllegalStateException("List was > 0 but findFirst() returned no result."));
try {
ModuleApi moduleApi = moduleRegistry.getModuleApi("db");
Utlatande utlatande = moduleApi.getUtlatandeFromJson(newest.getModel());
Patient patient = utlatande.getGrundData().getPatient();
if (personSvar.getStatus() == PersonSvar.Status.FOUND) {
patient.setSekretessmarkering(personSvar.getPerson().isSekretessmarkering());
}
patient.setAvliden((personSvar.getStatus() == PersonSvar.Status.FOUND && personSvar.getPerson().isAvliden()) || (user.getParameters() != null && user.getParameters().isPatientDeceased()) || (personSvar.getStatus() != PersonSvar.Status.FOUND && user.getParameters() == null));
return patient;
} catch (ModuleNotFoundException | IOException e) {
// No usabe DB exist
return handleDoiNoExistingDb(personnummer, personSvar, user);
}
} else {
// No usabe DB exist
return handleDoiNoExistingDb(personnummer, personSvar, user);
}
}
Aggregations