use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testFilterFragaSvarWithEnhetsIdAsParam.
@Test
public void testFilterFragaSvarWithEnhetsIdAsParam() {
WebCertUser webCertUser = createUser();
List<FragaSvar> queryResults = new ArrayList<>();
queryResults.add(buildFragaSvar(1L, MAY, null));
queryResults.add(buildFragaSvar(2L, MAY, null));
when(fragasvarRepositoryMock.filterFragaSvar(any(Filter.class))).thenReturn(queryResults);
when(fragasvarRepositoryMock.filterCountFragaSvar(any(Filter.class))).thenReturn(queryResults.size());
Filter params = new Filter();
params.setEnhetsIds(Arrays.asList(webCertUser.getValdVardenhet().getId()));
QueryFragaSvarResponse response = service.filterFragaSvar(params);
verify(fragasvarRepositoryMock).filterFragaSvar(any(Filter.class));
verify(fragasvarRepositoryMock).filterCountFragaSvar(any(Filter.class));
assertNotNull(response);
assertEquals(2, response.getResults().size());
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testSaveFragaOK.
@Test
public void testSaveFragaOK() {
FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
// Setup when - given -then
when(intygServiceMock.fetchIntygData(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), false)).thenReturn(getIntygContentHolder());
when(webCertUserService.getUser()).thenReturn(createUser());
when(webCertUserService.isAuthorizedForUnit(eq("VardenhetY"), eq(false))).thenReturn(true);
ArgumentCaptor<FragaSvar> capture = ArgumentCaptor.forClass(FragaSvar.class);
when(fragasvarRepositoryMock.save(capture.capture())).thenReturn(fraga);
// mock ws ok response
SendMedicalCertificateQuestionResponseType wsResponse = new SendMedicalCertificateQuestionResponseType();
wsResponse.setResult(ResultOfCallUtil.okResult());
when(sendQuestionToFKClientMock.sendMedicalCertificateQuestion(any(AttributedURIType.class), any(SendMedicalCertificateQuestionType.class))).thenReturn(wsResponse);
// test call
service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText());
verify(webCertUserService).getUser();
verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_QUESTION_FROM_CARE);
verify(webCertUserService).isAuthorizedForUnit(anyString(), eq(false));
verify(fragasvarRepositoryMock).save(any(FragaSvar.class));
verify(sendQuestionToFKClientMock).sendMedicalCertificateQuestion(any(AttributedURIType.class), any(SendMedicalCertificateQuestionType.class));
verify(monitoringServiceMock).logQuestionSent(anyString(), eq(1L), anyString(), anyString(), eq(Amne.OVRIGT));
assertEquals(Status.PENDING_EXTERNAL_ACTION, capture.getValue().getStatus());
assertEquals(createUser().getValdVardenhet().getId(), capture.getValue().getVardperson().getEnhetsId());
verify(arendeDraftService).delete(INTYG_ID, null);
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class NotificationServiceImplTest method createFragaSvar.
private FragaSvar createFragaSvar() {
FragaSvar fs = new FragaSvar();
fs.setAmne(Amne.OVRIGT);
fs.setSistaDatumForSvar(LocalDate.of(2018, 12, 12));
fs.setInternReferens(FRAGASVAR_ID);
fs.setIntygsReferens(new IntygsReferens());
fs.getIntygsReferens().setIntygsId(INTYG_ID);
fs.getIntygsReferens().setIntygsTyp(INTYG_TYP_FK);
fs.setVardperson(new Vardperson());
fs.getVardperson().setEnhetsId(ENHET_ID);
fs.getVardperson().setEnhetsnamn(ENHET_NAMN);
fs.getVardperson().setHsaId(SIGNED_BY_HSA_ID);
return fs;
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImpl method saveSvar.
@Override
public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) {
// Input sanity check
if (Strings.isNullOrEmpty(svarsText)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!");
}
// Look up entity in repository
FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId);
// Is user authorized to save an answer to this question?
verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false);
if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")");
}
// Implement Business Rule FS-007
if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer");
}
if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer");
}
LocalDateTime now = LocalDateTime.now();
WebCertUser user = webCertUserService.getUser();
// Ok, lets save the answer
fragaSvar.setVardAktorHsaId(user.getHsaId());
fragaSvar.setVardAktorNamn(user.getNamn());
fragaSvar.setSvarsText(svarsText);
fragaSvar.setSvarSkickadDatum(now);
fragaSvar.setStatus(Status.CLOSED);
fragaSvar.setSvarSigneringsDatum(now);
FragaSvar saved = fragaSvarRepository.save(fragaSvar);
sendFragaSvarToExternalParty(saved);
arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens()));
return saved;
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImpl method saveNewQuestion.
@Override
public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) {
// Argument check
if (Strings.isNullOrEmpty(frageText)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!");
}
if (amne == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!");
} else if (!VALID_VARD_AMNEN.contains(amne)) {
// Businessrule RE-013
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
}
// Fetch from Intygstjansten. Note that if Intygstjansten is unresponsive, the Intyg will be loaded from WebCert
// if possible.
IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false);
WebCertUser user = webCertUserService.getUser();
// Get vardperson that posed the question
// Is user authorized to save an answer to this question?
verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false);
// Verksamhetsregel FS-001 (Is the certificate sent to FK)
if (!isCertificateSentToFK(intyg.getStatuses())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!");
}
// Verify that certificate is not revoked
if (intyg.isRevoked()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!");
}
IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande());
HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null);
Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal);
FragaSvar fraga = new FragaSvar();
fraga.setFrageStallare(FrageStallare.WEBCERT.getKod());
fraga.setAmne(amne);
fraga.setFrageText(frageText);
LocalDateTime now = LocalDateTime.now();
fraga.setFrageSkickadDatum(now);
fraga.setFrageSigneringsDatum(now);
fraga.setIntygsReferens(intygsReferens);
fraga.setVardperson(vardPerson);
fraga.setStatus(Status.PENDING_EXTERNAL_ACTION);
fraga.setVardAktorHsaId(user.getHsaId());
fraga.setVardAktorNamn(user.getNamn());
// Ok, lets save the question
FragaSvar saved = fragaSvarRepository.save(fraga);
// Send to external party (FK)
SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType();
QuestionToFkType question = FKQuestionConverter.convert(saved);
// Remove ASAP.
if ("true".equalsIgnoreCase(forceFullstandigtNamn)) {
question.getLakarutlatande().getPatient().setFullstandigtNamn("---");
}
sendType.setQuestion(question);
AttributedURIType logicalAddress = new AttributedURIType();
logicalAddress.setValue(sendQuestionToFkLogicalAddress);
SendMedicalCertificateQuestionResponseType response;
try {
response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType);
} catch (SOAPFaultException e) {
LOGGER.error("Failed to send question to FK, error was: " + e.getMessage());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage());
}
if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) {
LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult().getErrorText());
}
monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardAktorHsaId(), saved.getAmne());
// Notify stakeholders
sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE);
arendeDraftService.delete(intygId, null);
return saved;
}
Aggregations