Search in sources :

Example 1 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class UtkastServiceImpl method validateDraft.

@Override
public DraftValidation validateDraft(String intygId, String intygType, String draftAsJson) {
    LOG.debug("Validating Intyg '{}' with type '{}'", intygId, intygType);
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        ValidateDraftResponse validateDraftResponse = moduleApi.validateDraft(draftAsJson);
        return convertToDraftValidation(validateDraftResponse);
    } catch (ModuleException | ModuleNotFoundException me) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 2 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class CopyCompletionUtkastBuilderTest method testPopulateCompletionFromSignedIntyg.

@Test
public void testPopulateCompletionFromSignedIntyg() throws Exception {
    IntygContentHolder ich = createIntygContentHolder();
    when(mockIntygService.fetchIntygData(INTYG_ID, INTYG_TYPE, false)).thenReturn(ich);
    CreateCompletionCopyRequest copyRequest = buildCompletionRequest();
    copyRequest.setMeddelandeId("meddelandeId");
    Person patientDetails = new Person(PATIENT_SSN, false, false, PATIENT_FNAME, PATIENT_MNAME, PATIENT_LNAME, "Postadr", "12345", "postort");
    ValidateDraftResponse vdr = new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>());
    when(mockModuleApi.validateDraft(isNull())).thenReturn(vdr);
    CopyUtkastBuilderResponse builderResponse = copyCompletionBuilder.populateCopyUtkastFromSignedIntyg(copyRequest, patientDetails, true, 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());
    assertEquals(INTYG_ID, builderResponse.getUtkastCopy().getRelationIntygsId());
    ArgumentCaptor<CreateDraftCopyHolder> requestCaptor = ArgumentCaptor.forClass(CreateDraftCopyHolder.class);
    verify(mockModuleApi).createCompletionFromTemplate(requestCaptor.capture(), any(), eq(KOMMENTAR));
    // verify full name is set
    assertNotNull(requestCaptor.getValue().getPatient().getFullstandigtNamn());
    assertEquals(PATIENT_FNAME + " " + PATIENT_MNAME + " " + PATIENT_LNAME, requestCaptor.getValue().getPatient().getFullstandigtNamn());
}
Also used : CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) CreateCompletionCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest) 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 3 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class CopyCompletionUtkastBuilderTest method testPopulateCompletionFromOriginalDecoratesWithReferensId.

@Test
public void testPopulateCompletionFromOriginalDecoratesWithReferensId() throws Exception {
    final String intygsTyp = "lisjp";
    final String meddelandeId = "meddelandeId";
    final String referensId = UUID.randomUUID().toString();
    Arende arende = new Arende();
    arende.setReferensId(referensId);
    when(moduleRegistry.getModuleApi(intygsTyp)).thenReturn(mockModuleApi);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(createOriginalUtkast());
    when(mockModuleApi.validateDraft(isNull())).thenReturn(new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>()));
    when(arendeService.getArende(meddelandeId)).thenReturn(arende);
    CreateCompletionCopyRequest copyRequest = buildCompletionRequest();
    copyRequest.setMeddelandeId(meddelandeId);
    copyRequest.setTyp(intygsTyp);
    copyRequest.setOriginalIntygTyp(intygsTyp);
    Person patientDetails = new Person(PATIENT_SSN, false, false, PATIENT_FNAME, PATIENT_MNAME, PATIENT_LNAME, "Postadr", "12345", "postort");
    copyCompletionBuilder.populateCopyUtkastFromOrignalUtkast(copyRequest, patientDetails, true, false, false);
    ArgumentCaptor<CreateDraftCopyHolder> createDraftCopyHolderCaptor = ArgumentCaptor.forClass(CreateDraftCopyHolder.class);
    verify(mockModuleApi).createCompletionFromTemplate(createDraftCopyHolderCaptor.capture(), any(), eq(KOMMENTAR));
    assertNotNull(createDraftCopyHolderCaptor.getValue());
    assertEquals(meddelandeId, createDraftCopyHolderCaptor.getValue().getRelation().getMeddelandeId());
    assertEquals(RelationKod.KOMPLT, createDraftCopyHolderCaptor.getValue().getRelation().getRelationKod());
    assertEquals(referensId, createDraftCopyHolderCaptor.getValue().getRelation().getReferensId());
    assertEquals(INTYG_ID, createDraftCopyHolderCaptor.getValue().getRelation().getRelationIntygsId());
}
Also used : ArrayList(java.util.ArrayList) CreateCompletionCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest) CreateDraftCopyHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) 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 4 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class CreateRenewalCopyUtkastBuilderImplTest method testPopulateRenewalUtkastFromSignedIntygWithNoPatientDetails.

@Test
public void testPopulateRenewalUtkastFromSignedIntygWithNoPatientDetails() throws Exception {
    IntygContentHolder ich = createIntygContentHolder();
    when(mockIntygService.fetchIntygData(INTYG_ID, INTYG_TYPE, false)).thenReturn(ich);
    CreateRenewalCopyRequest renewalRequest = buildRenewalRequest();
    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, null, false, false, false);
    assertNotNull(builderResponse.getUtkastCopy());
    assertNotNull(builderResponse.getUtkastCopy().getModel());
    assertEquals(INTYG_TYPE, builderResponse.getUtkastCopy().getIntygsTyp());
    assertEquals(PATIENT_SSN, builderResponse.getUtkastCopy().getPatientPersonnummer());
    assertEquals("Test", builderResponse.getUtkastCopy().getPatientFornamn());
    assertNull(builderResponse.getUtkastCopy().getPatientMellannamn());
    assertEquals("Testorsson", builderResponse.getUtkastCopy().getPatientEfternamn());
}
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) Test(org.junit.Test)

Example 5 with ValidateDraftResponse

use of se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse in project webcert by sklintyg.

the class CreateRenewalCopyUtkastBuilderImplTest method testPopulateRenewalUtkastFromOriginal.

@Test
public void testPopulateRenewalUtkastFromOriginal() throws Exception {
    Utkast orgUtkast = createOriginalUtkast();
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(orgUtkast);
    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.populateCopyUtkastFromOrignalUtkast(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());
    assertNotNull(builderResponse.getUtkastCopy().getPatientMellannamn());
    assertEquals(PATIENT_LNAME, builderResponse.getUtkastCopy().getPatientEfternamn());
}
Also used : CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) 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)

Aggregations

ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)18 Test (org.junit.Test)15 CreateDraftCopyHolder (se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder)9 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)9 Person (se.inera.intyg.infra.integration.pu.model.Person)8 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)5 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)4 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)4 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)4 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 CreateCompletionCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest)4 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)2 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)2 CreateUtkastFromTemplateRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest)2 SaveDraftResponse (se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse)2