Search in sources :

Example 1 with GrundData

use of se.inera.intyg.common.support.model.common.internal.GrundData 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 2 with GrundData

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

the class UtkastServiceImplTest method testSaveDoesNotUpdateOnEmptyFornamn.

@Test
public void testSaveDoesNotUpdateOnEmptyFornamn() throws Exception {
    final String utkastFornamn = "fornamn";
    final String utkastEfternamn = "efternamn";
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.VALID, Collections.emptyList());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(buildPatient(PERSON_ID, null, "Tolvansson"));
    when(utlatande.getGrundData()).thenReturn(grunddata);
    utkast.setPatientFornamn(utkastFornamn);
    utkast.setPatientEfternamn(utkastEfternamn);
    // 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.validateDraft(anyString())).thenReturn(validationResponse);
    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.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, false);
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(utkast, times(0)).setPatientFornamn(null);
    verify(utkast, times(0)).setPatientEfternamn("Tolvansson");
    verify(utkast).setPatientPersonnummer(any(Personnummer.class));
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 3 with GrundData

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

the class UtkastServiceImplTest method testSaveDraftDraftFirstSave.

@Test
public void testSaveDraftDraftFirstSave() throws Exception {
    ValidationMessage valMsg = new ValidationMessage("a.category", "a.field.somewhere", ValidationMessageType.OTHER, "This is soooo wrong!");
    ValidateDraftResponse validationResponse = new ValidateDraftResponse(ValidationStatus.INVALID, Collections.singletonList(valMsg));
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setSkapadAv(new HoSPersonal());
    grunddata.setPatient(defaultPatient);
    when(utlatande.getGrundData()).thenReturn(grunddata);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(moduleRegistry.getModuleApi(INTYG_TYPE)).thenReturn(mockModuleApi);
    when(mockModuleApi.validateDraft(anyString())).thenReturn(validationResponse);
    when(mockModuleApi.getUtlatandeFromJson(anyString())).thenReturn(utlatande);
    when(mockUtkastRepository.save(utkast)).thenReturn(utkast);
    when(mockModuleApi.shouldNotify(any(String.class), any(String.class))).thenReturn(true);
    when(userService.getUser()).thenReturn(user);
    when(mockModuleApi.updateBeforeSave(anyString(), any(HoSPersonal.class))).thenReturn("{}");
    SaveDraftResponse res = draftService.saveDraft(INTYG_ID, UTKAST_VERSION, INTYG_JSON, true);
    verify(mockUtkastRepository).save(any(Utkast.class));
    // Assert notification message
    verify(notificationService).sendNotificationForDraftChanged(any(Utkast.class));
    // Assert pdl log
    verify(logService).logUpdateIntyg(any(LogRequest.class));
    verify(mockMonitoringService).logUtkastEdited(INTYG_ID, INTYG_TYPE);
    assertNotNull("An DraftValidation should be returned", res);
    assertEquals("Validation should fail", UtkastStatus.DRAFT_INCOMPLETE, res.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) ValidationMessage(se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) SaveDraftResponse(se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 4 with GrundData

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

the class PatientDetailsResolverTest method buildSosDoiUtlatande.

private Utlatande buildSosDoiUtlatande() {
    GrundData grundData = new GrundData();
    grundData.setPatient(buildPatient());
    return DbUtlatande.builder().setGrundData(grundData).setId("abc-123").setTextVersion("1.0").build();
}
Also used : GrundData(se.inera.intyg.common.support.model.common.internal.GrundData)

Example 5 with GrundData

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

the class UtkastServiceImplTest method testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException.

@Test(expected = WebCertServiceException.class)
public void testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException() throws Exception {
    utkast.setEnhetsId("<unknownenhet>");
    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());
    // 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(userService.getUser()).thenReturn(user);
    draftService.updatePatientOnDraft(request);
    verifyNoMoreInteractions(mockUtkastRepository, notificationService);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) 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)

Aggregations

GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)13 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)11 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)10 Test (org.junit.Test)9 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)9 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)8 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Patient (se.inera.intyg.common.support.model.common.internal.Patient)4 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)4 UpdatePatientOnDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest)4 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)2 SaveDraftResponse (se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)1 Status (se.inera.intyg.common.support.model.Status)1 Relation (se.inera.intyg.common.support.model.common.internal.Relation)1