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);
}
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());
}
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());
}
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);
}
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());
}
}
Aggregations