use of se.inera.intyg.webcert.web.web.controller.api.dto.Relations in project webcert by sklintyg.
the class UtkastModuleApiController method getDraft.
/**
* Returns the draft certificate as JSON identified by the intygId.
*
* @param intygsId The id of the certificate
* @return a JSON object
*/
@GET
@Path("/{intygsTyp}/{intygsId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @Context HttpServletRequest request) {
LOG.debug("Retrieving Intyg with id {} and type {}", intygsId, intygsTyp);
Utkast utkast = utkastService.getDraft(intygsId, intygsTyp);
Patient resolvedPatient = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), intygsTyp);
if (resolvedPatient == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not resolve Patient in PU-service when opening draft.");
}
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
verifySekretessmarkering(intygsTyp, utkast.getEnhetsId(), resolvedPatient);
request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
DraftHolder draftHolder = new DraftHolder();
draftHolder.setVersion(utkast.getVersion());
draftHolder.setVidarebefordrad(utkast.getVidarebefordrad());
draftHolder.setStatus(utkast.getStatus());
draftHolder.setEnhetsNamn(utkast.getEnhetsNamn());
draftHolder.setVardgivareNamn(utkast.getVardgivarNamn());
draftHolder.setLatestTextVersion(intygTextsService.getLatestVersion(utkast.getIntygsTyp()));
Relations relations1 = certificateRelationService.getRelations(utkast.getIntygsId());
draftHolder.setRelations(relations1);
draftHolder.setKlartForSigneringDatum(utkast.getKlartForSigneringDatum());
draftHolder.setCreated(utkast.getSkapad());
// The patientResolved is unnecessary?
draftHolder.setPatientResolved(true);
draftHolder.setSekretessmarkering(resolvedPatient.isSekretessmarkering());
draftHolder.setAvliden(resolvedPatient.isAvliden());
// Businesss logic below should not be here inside a controller.. Should preferably be moved in the future.
try {
try {
Utlatande utlatande = moduleRegistry.getModuleApi(intygsTyp).getUtlatandeFromJson(utkast.getModel());
draftHolder.setPatientNameChangedInPU(patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), resolvedPatient));
draftHolder.setPatientAddressChangedInPU(patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), resolvedPatient));
} catch (IOException e) {
LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygsId);
}
if (!completeAddressProvided(resolvedPatient)) {
// Overwrite retrieved address data with saved one.
Patient oldPatientData = null;
try {
oldPatientData = moduleRegistry.getModuleApi(intygsTyp).getUtlatandeFromJson(utkast.getModel()).getGrundData().getPatient();
} catch (IOException e) {
LOG.error("Error while using the module api to convert json to Utlatande for intygsId {}", intygsId);
}
copyOldAddressToNewPatientData(oldPatientData, resolvedPatient);
}
// Update the internal model with the resolved patient. This means the draft may be updated
// with new patient info on the next auto-save!
String updatedModel = moduleRegistry.getModuleApi(intygsTyp).updateBeforeSave(utkast.getModel(), resolvedPatient);
utkast.setModel(updatedModel);
draftHolder.setContent(utkast.getModel());
return Response.ok(draftHolder).build();
} catch (ModuleException | ModuleNotFoundException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e.getMessage());
}
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.Relations in project webcert by sklintyg.
the class AbstractIntygServiceTest method setupMocks.
@Before
public void setupMocks() throws Exception {
json = FileUtils.getStringFromFile(new ClassPathResource("IntygServiceTest/utlatande.json").getFile());
utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
CertificateMetaData metaData = buildCertificateMetaData();
certificateResponse = new CertificateResponse(json, utlatande, metaData, false);
when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenReturn(certificateResponse);
when(certificateRelationService.getNewestRelationOfType(anyString(), any(RelationKod.class), any(List.class))).thenReturn(Optional.empty());
when(intygRelationHelper.getRelationsForIntyg(anyString())).thenReturn(new Relations());
when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(buildPatient(false, false));
when(moduleRegistry.getModuleApi(anyString())).thenReturn(moduleApi);
when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(new Fk7263Utlatande());
when(moduleApi.updateBeforeSave(anyString(), any(Patient.class))).thenReturn("MODEL");
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.Relations in project webcert by sklintyg.
the class IntygServiceRevokeTest method setupMocks.
@Override
@Before
public void setupMocks() throws Exception {
json = FileUtils.getStringFromFile(new ClassPathResource("IntygServiceTest/utlatande.json").getFile());
utlatande = objectMapper.readValue(json, Fk7263Utlatande.class);
CertificateMetaData metaData = buildCertificateMetaData();
certificateResponse = new CertificateResponse(json, utlatande, metaData, false);
when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenReturn(certificateResponse);
when(intygRelationHelper.getRelationsForIntyg(anyString())).thenReturn(new Relations());
when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(buildPatient(false, false));
when(moduleRegistry.getModuleApi(anyString())).thenReturn(moduleApi);
when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(new Fk7263Utlatande());
when(moduleApi.updateBeforeSave(anyString(), any(Patient.class))).thenReturn("MODEL");
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.Relations in project webcert by sklintyg.
the class IntygServiceTest method setupIntygstjanstListResponse.
@Before
public void setupIntygstjanstListResponse() throws Exception {
ClassPathResource response = new ClassPathResource("IntygServiceTest/response-list-certificates.xml");
JAXBContext context = JAXBContext.newInstance(ListCertificatesForCareResponseType.class);
listResponse = context.createUnmarshaller().unmarshal(new StreamSource(response.getInputStream()), ListCertificatesForCareResponseType.class).getValue();
when(intygRelationHelper.getRelationsForIntyg(anyString())).thenReturn(new Relations());
doNothing().when(intygRelationHelper).decorateIntygListWithRelations(anyList());
when(certificateRelationService.getRelations(anyString())).thenReturn(new Relations());
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.Relations 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);
}
}
Aggregations