Search in sources :

Example 16 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class CreateRenewalCopyUtkastBuilderImplTest method testPopulateRenewalUtkastFromSignedIntyg.

@Test
public void testPopulateRenewalUtkastFromSignedIntyg() throws Exception {
    IntygContentHolder ich = createIntygContentHolder();
    when(mockIntygService.fetchIntygData(INTYG_ID, INTYG_TYPE, false)).thenReturn(ich);
    CreateRenewalCopyRequest renewalRequest = buildRenewalRequest();
    Person patientDetails = new Person(PATIENT_SSN, false, false, PATIENT_FNAME, PATIENT_MNAME, PATIENT_LNAME, "Postadr", "12345", "postort");
    when(mockModuleApi.createRenewalFromTemplate(any(CreateDraftCopyHolder.class), any())).thenReturn(INTYG_JSON);
    ValidateDraftResponse vdr = new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>());
    when(mockModuleApi.validateDraft(anyString())).thenReturn(vdr);
    CopyUtkastBuilderResponse builderResponse = renewalBuilder.populateCopyUtkastFromSignedIntyg(renewalRequest, patientDetails, false, false, false);
    assertNotNull(builderResponse.getUtkastCopy());
    assertNotNull(builderResponse.getUtkastCopy().getModel());
    assertEquals(INTYG_TYPE, builderResponse.getUtkastCopy().getIntygsTyp());
    assertEquals(PATIENT_SSN, builderResponse.getUtkastCopy().getPatientPersonnummer());
    assertEquals(PATIENT_FNAME, builderResponse.getUtkastCopy().getPatientFornamn());
    assertEquals(PATIENT_MNAME, builderResponse.getUtkastCopy().getPatientMellannamn());
    assertEquals(PATIENT_LNAME, builderResponse.getUtkastCopy().getPatientEfternamn());
    ArgumentCaptor<CreateDraftCopyHolder> requestCaptor = ArgumentCaptor.forClass(CreateDraftCopyHolder.class);
    verify(mockModuleApi).createRenewalFromTemplate(requestCaptor.capture(), any());
    // verify full name is set
    assertNotNull(requestCaptor.getValue().getPatient().getFullstandigtNamn());
    assertEquals(PATIENT_FNAME + " " + PATIENT_MNAME + " " + PATIENT_LNAME, requestCaptor.getValue().getPatient().getFullstandigtNamn());
}
Also used : CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) CreateDraftCopyHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) Person(se.inera.intyg.infra.integration.pu.model.Person) Test(org.junit.Test)

Example 17 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testGetIntygWithCoherentJournaling.

@Test
public void testGetIntygWithCoherentJournaling() {
    final String intygsTyp = "fk7263";
    final String intygContent = "CONTENTS";
    setupUser(AuthoritiesConstants.PRIVILEGE_VISA_INTYG, intygsTyp, true, true);
    IntygContentHolder content = mock(IntygContentHolder.class);
    when(content.getContents()).thenReturn(intygContent);
    when(intygService.fetchIntygDataWithRelations(eq(CERTIFICATE_ID), eq(intygsTyp), eq(true))).thenReturn(content);
    Response response = moduleApiController.getIntyg(intygsTyp, CERTIFICATE_ID);
    assertEquals(OK.getStatusCode(), response.getStatus());
    assertEquals(intygContent, ((IntygContentHolder) response.getEntity()).getContents());
    verify(intygService).fetchIntygDataWithRelations(eq(CERTIFICATE_ID), eq(intygsTyp), eq(true));
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Test(org.junit.Test)

Example 18 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygModuleApiController method getIntyg.

/**
 * Retrieves a signed intyg from intygstjÀnst.
 *
 * @param intygsId intygid
 * @return Response
 */
@GET
@Path("/{intygsTyp}/{intygsId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).privilege(AuthoritiesConstants.PRIVILEGE_VISA_INTYG).orThrow();
    WebCertUser user = userService.getUser();
    boolean coherentJournaling = user.getParameters() != null && user.getParameters().isSjf();
    LOG.debug("Fetching signed intyg with id '{}' from IT, coherent journaling {}", intygsId, coherentJournaling);
    IntygContentHolder intygAsExternal = intygService.fetchIntygDataWithRelations(intygsId, intygsTyp, coherentJournaling);
    return Response.ok().entity(intygAsExternal).build();
}
Also used : IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 19 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder 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 20 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygServiceTest method testFetchIntygDataWithCreatedTimestamp.

@Test
public void testFetchIntygDataWithCreatedTimestamp() throws Exception {
    final LocalDateTime timestamp = LocalDateTime.of(2010, 11, 12, 13, 14, 15);
    Utkast utkast = new Utkast();
    utkast.setSkapad(timestamp);
    when(utkastRepository.findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenReturn(utkast);
    IntygContentHolder res = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertEquals(timestamp, res.getCreated());
    verify(moduleFacade).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(utkastRepository).findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(logservice).logReadIntyg(any(LogRequest.class));
    verify(mockMonitoringService).logIntygRead(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(intygRelationHelper).getRelationsForIntyg(CERTIFICATE_ID);
    verifyNoMoreInteractions(moduleFacade, utkastRepository, logservice, mockMonitoringService, intygRelationHelper);
}
Also used : LocalDateTime(java.time.LocalDateTime) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Aggregations

IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)30 Test (org.junit.Test)23 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)9 Personnummer (se.inera.intyg.schemas.contract.Personnummer)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Patient (se.inera.intyg.common.support.model.common.internal.Patient)5 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)5 CreateDraftCopyHolder (se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder)4 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)4 Person (se.inera.intyg.infra.integration.pu.model.Person)4 LocalDateTime (java.time.LocalDateTime)3 WebServiceException (javax.xml.ws.WebServiceException)3 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)3 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 IntygModuleFacadeException (se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException)3 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)3 Response (javax.ws.rs.core.Response)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)2