Search in sources :

Example 21 with Utlatande

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

the class IntygModuleFacadeTest method testGetUtlatandeFromInternalModel.

@Test
public void testGetUtlatandeFromInternalModel() throws Exception {
    when(moduleApi.getUtlatandeFromJson(INT_JSON)).thenReturn(mock(Utlatande.class));
    Utlatande res = moduleFacade.getUtlatandeFromInternalModel(CERTIFICATE_TYPE, INT_JSON);
    assertNotNull(res);
    verify(moduleApi).getUtlatandeFromJson(INT_JSON);
}
Also used : Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Test(org.junit.Test)

Example 22 with Utlatande

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

the class UtkastServiceImplTest method testUpdatePatientOnDraft.

@Test
public void testUpdatePatientOnDraft() throws Exception {
    utkast.setEnhetsId(UTKAST_ENHETS_ID);
    Patient newPatient = getUpdatedPatient();
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(newPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    String expectedPatientId = defaultPatient.getPersonId().getPersonnummer();
    when(utlatande.getGrundData()).thenReturn(grunddata);
    // Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
    utkast = spy(utkast);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.updateBeforeSave(anyString(), any(Patient.class))).thenReturn("{}");
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    draftService.updatePatientOnDraft(request);
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
    verify(utkast).setPatientPersonnummer(any(Personnummer.class));
    assertEquals(expectedPatientId, user.getParameters().getBeforeAlternateSsn());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Patient(se.inera.intyg.common.support.model.common.internal.Patient) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 23 with Utlatande

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

the class UtkastServiceImplTest method testUpdatePatientOnDraftEmptyPatientId.

@Test
public void testUpdatePatientOnDraftEmptyPatientId() throws Exception {
    utkast.setEnhetsId(UTKAST_ENHETS_ID);
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(null, utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    when(utlatande.getGrundData()).thenReturn(grunddata);
    // Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
    utkast = spy(utkast);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(userService.getUser()).thenReturn(user);
    draftService.updatePatientOnDraft(request);
    verify(mockUtkastRepository, never()).save(any(Utkast.class));
    verify(notificationService, never()).sendNotificationForDraftChanged(any(Utkast.class));
    verify(utkast, never()).setPatientPersonnummer(any(Personnummer.class));
    assertEquals(defaultPatient.getPersonId().getPersonnummer(), user.getParameters().getBeforeAlternateSsn());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 24 with Utlatande

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

the class SignaturServiceImplTest method setup.

@Before
public void setup() throws Exception {
    hoSPerson = new HoSPersonal();
    hoSPerson.setPersonId("AAA");
    hoSPerson.setFullstandigtNamn("Dr Dengroth");
    VardpersonReferens vardperson = new VardpersonReferens();
    vardperson.setHsaId(hoSPerson.getPersonId());
    vardperson.setNamn(hoSPerson.getFullstandigtNamn());
    utkast = createUtkast(INTYG_ID, 1, INTYG_TYPE, UtkastStatus.DRAFT_INCOMPLETE, INTYG_JSON, vardperson, ENHET_ID, PERSON_ID);
    completedUtkast = createUtkast(INTYG_ID, 2, INTYG_TYPE, UtkastStatus.DRAFT_COMPLETE, INTYG_JSON, vardperson, ENHET_ID, PERSON_ID);
    signedUtkast = createUtkast(INTYG_ID, 3, INTYG_TYPE, UtkastStatus.SIGNED, INTYG_JSON, vardperson, ENHET_ID, PERSON_ID);
    vardenhet = new Vardenhet(ENHET_ID, "testNamn");
    vardgivare = new Vardgivare("123", "vardgivare");
    vardgivare.setVardenheter(Collections.singletonList(vardenhet));
    user = createWebCertUser(true);
    when(webcertUserService.getUser()).thenReturn(user);
    when(moduleRegistry.getModuleApi(any())).thenReturn(moduleApi);
    when(moduleApi.updateBeforeSigning(any(), any(), any())).thenReturn(INTYG_JSON);
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    when(utlatande.getGrundData()).thenReturn(grunddata);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    setTypedField(intygSignatureService, new SignaturTicketTracker());
    pagaendeSignering = mock(PagaendeSignering.class);
    when(pagaendeSignering.getInternReferens()).thenReturn(PAGAENDE_SIGN_ID);
    when(pagaendeSignering.getIntygData()).thenReturn(INTYG_JSON);
    when(pagaendeSignering.getIntygsId()).thenReturn(INTYG_ID);
    when(pagaendeSignering.getSigneradAvHsaId()).thenReturn(hoSPerson.getPersonId());
    when(pagaendeSignering.getSigneradAvNamn()).thenReturn(hoSPerson.getFullstandigtNamn());
    when(pagaendeSigneringRepository.findOne(any())).thenReturn(pagaendeSignering);
    when(pagaendeSigneringRepository.save(any(PagaendeSignering.class))).thenReturn(pagaendeSignering);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) Before(org.junit.Before)

Example 25 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande 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)

Aggregations

Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)18 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)14 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)11 IOException (java.io.IOException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)10 Relation (se.inera.intyg.common.support.model.common.internal.Relation)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)7 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)7 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)7 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)6 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)6 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)6 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)6 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)5 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)3