Search in sources :

Example 51 with Patient

use of se.inera.intyg.common.support.model.common.internal.Patient 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());
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) DraftHolder(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.DraftHolder) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 52 with Patient

use of se.inera.intyg.common.support.model.common.internal.Patient in project webcert by sklintyg.

the class AbstractUtkastBuilder method createModuleRequestForCopying.

protected CreateDraftCopyHolder createModuleRequestForCopying(AbstractCreateCopyRequest copyRequest, Person person, Relation relation, String newDraftCopyId) {
    LOG.debug("Created id '{}' for the new copy", newDraftCopyId);
    CreateDraftCopyHolder newDraftCopyHolder = new CreateDraftCopyHolder(newDraftCopyId, copyRequest.getHosPerson(), relation);
    if (person != null) {
        Patient patient = new Patient();
        patient.setFornamn(person.getFornamn());
        patient.setMellannamn(person.getMellannamn());
        patient.setEfternamn(person.getEfternamn());
        patient.setPersonId(person.getPersonnummer());
        patient.setPostadress(person.getPostadress());
        patient.setPostnummer(person.getPostnummer());
        patient.setPostort(person.getPostort());
        patient.setFullstandigtNamn(IntygConverterUtil.concatPatientName(patient.getFornamn(), patient.getMellannamn(), patient.getEfternamn()));
        newDraftCopyHolder.setPatient(patient);
        LOG.debug("Added new patient data to CreateDraftCopyHolder");
    }
    if (copyRequest.containsNyttPatientPersonnummer()) {
        newDraftCopyHolder.setNewPersonnummer(copyRequest.getNyttPatientPersonnummer());
        LOG.debug("Added new personnummer to CreateDraftCopyHolder");
    }
    return newDraftCopyHolder;
}
Also used : CreateDraftCopyHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder) Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 53 with Patient

use of se.inera.intyg.common.support.model.common.internal.Patient in project webcert by sklintyg.

the class AbstractIntygServiceTest method buildPatient.

protected Patient buildPatient(boolean sekretessMarkering, boolean avliden) {
    Patient patient = new Patient();
    patient.setPersonId(Personnummer.createPersonnummer("19121212-1212").get());
    patient.setFornamn("fornamn");
    patient.setMellannamn("mellannamn");
    patient.setEfternamn("efternamn");
    patient.setSekretessmarkering(sekretessMarkering);
    patient.setAvliden(avliden);
    return patient;
}
Also used : Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 54 with Patient

use of se.inera.intyg.common.support.model.common.internal.Patient in project webcert by sklintyg.

the class IntygServiceTest method testThatCompletePatientAddressIsUsed.

@Test
public void testThatCompletePatientAddressIsUsed() throws Exception {
    // Given
    String postadress = "ttipafpinu-postadress";
    String postort = "ttipafpinu-postort";
    String postnummer = "ttipafpinu-postnummer";
    Patient patientWithIncompleteAddress = buildPatient(false, false);
    patientWithIncompleteAddress.setPostadress(postadress);
    patientWithIncompleteAddress.setPostort(postort);
    patientWithIncompleteAddress.setPostnummer(postnummer);
    when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(patientWithIncompleteAddress);
    // When
    IntygContentHolder intygData = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    // Then
    ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
    verify(moduleApi).updateBeforeSave(anyString(), argumentCaptor.capture());
    assertEquals(postadress, argumentCaptor.getValue().getPostadress());
    assertEquals(postort, argumentCaptor.getValue().getPostort());
    assertEquals(postnummer, argumentCaptor.getValue().getPostnummer());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Patient(se.inera.intyg.common.support.model.common.internal.Patient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 55 with Patient

use of se.inera.intyg.common.support.model.common.internal.Patient in project webcert by sklintyg.

the class IntygServiceTest method testThatCompletePatientAddressIsUsedWhenIntygtjanstIsUnavailable.

@Test
public void testThatCompletePatientAddressIsUsedWhenIntygtjanstIsUnavailable() throws Exception {
    // Given
    when(moduleFacade.getCertificate(anyString(), anyString())).thenThrow(new WebServiceException());
    when(utkastRepository.findOneByIntygsIdAndIntygsTyp(anyString(), anyString())).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), null));
    String postadress = "ttipafpinuwiiu-postadress";
    String postort = "ttipafpinuwiiu-postort";
    String postnummer = "ttipafpinuwiiu-postnummer";
    Patient patientWithIncompleteAddress = buildPatient(false, false);
    patientWithIncompleteAddress.setPostadress(postadress);
    patientWithIncompleteAddress.setPostort(postort);
    patientWithIncompleteAddress.setPostnummer(postnummer);
    when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(patientWithIncompleteAddress);
    // When
    IntygContentHolder intygData = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    // Then
    ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
    verify(moduleApi).updateBeforeSave(anyString(), argumentCaptor.capture());
    assertEquals(postadress, argumentCaptor.getValue().getPostadress());
    assertEquals(postort, argumentCaptor.getValue().getPostort());
    assertEquals(postnummer, argumentCaptor.getValue().getPostnummer());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) WebServiceException(javax.xml.ws.WebServiceException) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Patient(se.inera.intyg.common.support.model.common.internal.Patient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Patient (se.inera.intyg.common.support.model.common.internal.Patient)62 Test (org.junit.Test)28 Personnummer (se.inera.intyg.schemas.contract.Personnummer)28 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)5 Vardgivare (se.inera.intyg.common.support.model.common.internal.Vardgivare)5 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)5 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)5 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)5 IOException (java.io.IOException)4 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)4 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)4 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)4 PersonSvar (se.inera.intyg.infra.integration.pu.model.PersonSvar)4