use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.
the class UtkastBootstrapBean method buildUtlatande.
// INTYG-4086: An incredibly ugly hack to mitigate the fact that we're populating test-data using the XML format
// and also directly to WC instead of storing in IT where these actually belong...
private Utlatande buildUtlatande(Resource resource, String moduleName) throws ModuleException, ModuleNotFoundException, IOException {
String xml = Resources.toString(resource.getURL(), Charsets.UTF_8);
Utlatande utlatande = registry.getModuleApi(moduleName).getUtlatandeFromXml(xml);
switch(moduleName) {
case "luse":
case "luae_fs":
case "luae_na":
case "lisjp":
RegisterCertificateType jaxbObject = JAXB.unmarshal(new StringReader(Resources.toString(resource.getURL(), Charsets.UTF_8)), RegisterCertificateType.class);
Patient patient = jaxbObject.getIntyg().getPatient();
utlatande.getGrundData().getPatient().setFornamn(patient.getFornamn());
utlatande.getGrundData().getPatient().setMellannamn(patient.getMellannamn());
utlatande.getGrundData().getPatient().setEfternamn(patient.getEfternamn());
utlatande.getGrundData().getPatient().setFullstandigtNamn(IntygConverterUtil.concatPatientName(patient.getFornamn(), patient.getMellannamn(), patient.getEfternamn()));
break;
case "fk7263":
RegisterMedicalCertificateType jaxbObject2 = JAXB.unmarshal(new StringReader(Resources.toString(resource.getURL(), Charsets.UTF_8)), RegisterMedicalCertificateType.class);
PatientType patient2 = jaxbObject2.getLakarutlatande().getPatient();
utlatande.getGrundData().getPatient().setEfternamn(patient2.getFullstandigtNamn());
utlatande.getGrundData().getPatient().setFullstandigtNamn(patient2.getFullstandigtNamn());
break;
case "ts-bas":
case "ts-diabetes":
break;
}
return utlatande;
}
use of se.inera.intyg.common.support.model.common.internal.Utlatande 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.Utlatande 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));
}
use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.
the class IntygServiceSendTest method testSendIntygFailsForReplacedCertificate.
@Test(expected = WebCertServiceException.class)
public void testSendIntygFailsForReplacedCertificate() 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(webCertUserService.isAuthorizedForUnit(anyString(), anyString(), anyBoolean())).thenReturn(true);
when(webCertUserService.getUser()).thenReturn(webCertUser);
when(intygRepository.findOne(INTYG_ID)).thenReturn(getUtkast(INTYG_ID));
WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
when(certificateRelationService.getNewestRelationOfType(eq(INTYG_ID), eq(RelationKod.ERSATT), eq(Arrays.asList(UtkastStatus.SIGNED)))).thenReturn(Optional.of(ersattRelation));
CertificateMetaData metaData = new CertificateMetaData();
metaData.setStatus(new ArrayList<>());
CertificateResponse revokedCertificateResponse = new CertificateResponse(json, utlatande, metaData, false);
when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenReturn(revokedCertificateResponse);
when(moduleFacade.getUtlatandeFromInternalModel(any(), any())).thenReturn(utlatande);
intygService.sendIntyg(INTYG_ID, INTYG_TYP_FK, "FKASSA", false);
verifyZeroInteractions(logService);
}
use of se.inera.intyg.common.support.model.common.internal.Utlatande 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));
}
Aggregations