Search in sources :

Example 6 with CopyUtkastBuilderResponse

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

the class AbstractUtkastBuilder method populateCopyUtkastFromSignedIntyg.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromSignedIntyg(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
public CopyUtkastBuilderResponse populateCopyUtkastFromSignedIntyg(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    String originalIntygsTyp = copyRequest.getOriginalIntygTyp();
    String intygsTyp = copyRequest.getTyp();
    IntygContentHolder signedIntygHolder = intygService.fetchIntygData(orignalIntygsId, originalIntygsTyp, coherentJournaling);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(originalIntygsTyp);
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(signedIntygHolder.getContents());
    } catch (IOException e) {
        throw new ModuleException("Could not convert orignal certificate to Utlatande", e);
    }
    GrundData grundData = signedIntygHolder.getUtlatande().getGrundData();
    se.inera.intyg.common.support.model.common.internal.Vardenhet vardenhet = grundData.getSkapadAv().getVardenhet();
    if (coherentJournaling && enforceEnhet) {
        verifyEnhetsAuth(vardenhet.getVardgivare().getVardgivarid(), vardenhet.getEnhetsid(), true);
    }
    LOG.debug("Populating copy with details from signed Intyg '{}'", orignalIntygsId);
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(vardenhet.getEnhetsid());
    builderResponse.setOrginalEnhetsNamn(vardenhet.getEnhetsnamn());
    builderResponse.setOrginalVardgivarId(vardenhet.getVardgivare().getVardgivarid());
    builderResponse.setOrginalVardgivarNamn(vardenhet.getVardgivare().getVardgivarnamn());
    ModuleApi moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, intygsTyp, addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        se.inera.intyg.common.support.model.common.internal.Patient patient = signedIntygHolder.getUtlatande().getGrundData().getPatient();
        populatePatientDetailsFromPatient(utkast, patient);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) IOException(java.io.IOException) Relation(se.inera.intyg.common.support.model.common.internal.Relation) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) 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) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 7 with CopyUtkastBuilderResponse

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

the class AbstractUtkastBuilder method populateCopyUtkastFromOrignalUtkast.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromOrignalUtkast(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public CopyUtkastBuilderResponse populateCopyUtkastFromOrignalUtkast(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    Utkast orgUtkast = utkastRepository.findOne(orignalIntygsId);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(copyRequest.getOriginalIntygTyp());
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(orgUtkast.getModel());
    } catch (IOException e) {
        throw new ModuleException("Could not convert original certificate to Utlatande", e);
    }
    // Perform enhets auth if coherent journaling is not active.
    if (!coherentJournaling || enforceEnhet) {
        verifyEnhetsAuth(orgUtkast.getVardgivarId(), orgUtkast.getEnhetsId(), true);
    } else {
        LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(orgUtkast, coherentJournaling);
        logService.logReadIntyg(logRequest);
    }
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(orgUtkast.getEnhetsId());
    builderResponse.setOrginalEnhetsNamn(orgUtkast.getEnhetsNamn());
    builderResponse.setOrginalVardgivarId(orgUtkast.getVardgivarId());
    builderResponse.setOrginalVardgivarNamn(orgUtkast.getVardgivarNamn());
    LOG.debug("Populating copy with details from Utkast '{}'", orignalIntygsId);
    ModuleApi moduleApi = moduleRegistry.getModuleApi(copyRequest.getTyp());
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, copyRequest.getTyp(), addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        populatePatientDetailsFromUtkast(utkast, orgUtkast);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) Relation(se.inera.intyg.common.support.model.common.internal.Relation) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with CopyUtkastBuilderResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse 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 9 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImplTest method testCreateRenewalWhenIntegratedAndSjfTrue.

@Test
public void testCreateRenewalWhenIntegratedAndSjfTrue() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setOrigin(DJUPINTEGRATION.name());
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", true, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.TRUE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), isNull(), any(boolean.class), eq(true), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest copyReq = buildRenewalRequest();
    copyReq.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalResponse = copyService.createRenewalCopy(copyReq);
    assertNotNull(renewalResponse);
    assertEquals(INTYG_COPY_ID, renewalResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalResponse.getNewDraftIntygType());
    assertEquals(INTYG_ID, renewalResponse.getOriginalIntygId());
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), isNull(), any(boolean.class), eq(true), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, true);
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 10 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImplTest method testCreateReplacementCopy.

@Test
public void testCreateReplacementCopy() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createReplacementUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), eq(true), any(boolean.class), eq(true))).thenReturn(resp);
    CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
    CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(logService).logCreateIntyg(any(LogRequest.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Aggregations

CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)26 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)17 Test (org.junit.Test)15 Person (se.inera.intyg.infra.integration.pu.model.Person)14 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)11 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)8 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 CreateDraftCopyHolder (se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder)7 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)6 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)5 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)5 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)5 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)4 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)3 CreateCompletionCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest)3 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)3 IOException (java.io.IOException)2