use of se.inera.intyg.common.support.model.common.internal.Relation in project webcert by sklintyg.
the class CreateReplacementUtkastBuilder method createRelation.
@Override
public Relation createRelation(CreateReplacementCopyRequest request) {
Relation relation = new Relation();
relation.setRelationIntygsId(request.getOriginalIntygId());
relation.setRelationKod(RelationKod.ERSATT);
return relation;
}
use of se.inera.intyg.common.support.model.common.internal.Relation 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;
}
use of se.inera.intyg.common.support.model.common.internal.Relation 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;
}
use of se.inera.intyg.common.support.model.common.internal.Relation in project webcert by sklintyg.
the class IntygServiceSendTest method testSendIntygThrowsExceptionForOldFk7263WithSekretessmarkeradPatient.
@Test(expected = WebCertServiceException.class)
public void testSendIntygThrowsExceptionForOldFk7263WithSekretessmarkeradPatient() throws Exception {
final String completionMeddelandeId = "meddelandeId";
intygService.setSekretessmarkeringStartDatum(LocalDateTime.now().plusMonths(1L));
WebCertUser webCertUser = createUser();
Utlatande completionUtlatande = utlatande;
completionUtlatande.getGrundData().setRelation(new Relation());
completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
when(moduleFacade.getUtlatandeFromInternalModel(isNull(), anyString())).thenReturn(completionUtlatande);
when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.TRUE);
when(webCertUserService.getUser()).thenReturn(webCertUser);
when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
try {
intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
} catch (Exception e) {
verifyZeroInteractions(logService);
throw e;
}
}
use of se.inera.intyg.common.support.model.common.internal.Relation in project webcert by sklintyg.
the class IntygServiceSendTest method testSendIntyg.
@Test
public void testSendIntyg() throws Exception {
final String completionMeddelandeId = "meddelandeId";
WebCertUser webCertUser = createUser();
Utlatande completionUtlatande = utlatande;
completionUtlatande.getGrundData().setRelation(new Relation());
completionUtlatande.getGrundData().getRelation().setRelationKod(RelationKod.KOMPLT);
completionUtlatande.getGrundData().getRelation().setMeddelandeId(completionMeddelandeId);
when(moduleFacade.getUtlatandeFromInternalModel(isNull(), anyString())).thenReturn(completionUtlatande);
when(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.FALSE);
when(webCertUserService.getUser()).thenReturn(webCertUser);
when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
IntygServiceResult res = intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
assertEquals(IntygServiceResult.OK, res);
verify(logService).logSendIntygToRecipient(any(LogRequest.class));
verify(certificateSenderService).sendCertificate(anyString(), any(Personnummer.class), anyString(), anyString(), eq(false));
verify(intygRepository, times(2)).findOne(INTYG_ID);
verify(intygRepository).save(any(Utkast.class));
}
Aggregations