use of se.inera.intyg.webcert.persistence.arende.model.ArendeDraft in project webcert by sklintyg.
the class ArendeDraftRepositoryTest method testFindByIntygIdAndQuestionId.
@Test
public void testFindByIntygIdAndQuestionId() {
ArendeDraft res = repo.findByIntygIdAndQuestionId("-1", "-1");
assertNull(res);
repo.save(buildArendeDraft("i1", "q1"));
res = repo.findByIntygIdAndQuestionId("i1", "q1");
assertNotNull(res);
assertEquals("i1", res.getIntygId());
assertEquals("q1", res.getQuestionId());
repo.save(buildArendeDraft("i1"));
res = repo.findByIntygIdAndQuestionId("i1", null);
assertNotNull(res);
assertEquals("i1", res.getIntygId());
assertNull(res.getQuestionId());
}
use of se.inera.intyg.webcert.persistence.arende.model.ArendeDraft in project webcert by sklintyg.
the class ArendeDraftServiceImplTest method buildArendeDraft.
private ArendeDraft buildArendeDraft(String intygId, String questionId, String text, String amne) {
ArendeDraft draft = new ArendeDraft();
draft.setIntygId(intygId);
draft.setQuestionId(questionId);
draft.setText(text);
draft.setAmne(amne);
return draft;
}
use of se.inera.intyg.webcert.persistence.arende.model.ArendeDraft in project webcert by sklintyg.
the class ArendeViewConverter method createConversationViewFromArendeList.
private ArendeConversationView createConversationViewFromArendeList(List<Arende> messagesInThread, List<AnsweredWithIntyg> kompltForIntyg, List<ArendeDraft> arendeDrafts) {
Optional<Arende> fraga = messagesInThread.stream().filter(a -> getArendeType(a) == ArendeType.FRAGA).reduce((element, otherElement) -> {
throw new IllegalArgumentException("More than 1 fraga found.");
});
Optional<Arende> svar = messagesInThread.stream().filter(a -> getArendeType(a) == ArendeType.SVAR).reduce((element, otherElement) -> {
throw new IllegalArgumentException("More than 1 svar found.");
});
List<Arende> paminnelser = messagesInThread.stream().filter(a -> getArendeType(a) == ArendeType.PAMINNELSE).collect(Collectors.toList());
if (!fraga.isPresent()) {
throw new IllegalArgumentException("No fraga found for the given message thread.");
}
String draftText = null;
if (!svar.isPresent() && !FrageStallare.WEBCERT.getKod().equals(fraga.get().getSkickatAv())) {
draftText = arendeDrafts.stream().filter(d -> d.getQuestionId().equals(fraga.get().getMeddelandeId())).findAny().map(ArendeDraft::getText).orElse(null);
}
// Find oldest intyg among kompletterande intyg, that's newer than the fraga
AnsweredWithIntyg komplt = null;
if (!svar.isPresent() && fraga.get().getAmne() == ArendeAmne.KOMPLT) {
komplt = AnsweredWithIntygUtil.returnOldestKompltOlderThan(fraga.get().getTimestamp(), kompltForIntyg);
}
return convertToArendeConversationView(fraga.get(), svar.orElse(null), komplt, paminnelser, draftText);
}
use of se.inera.intyg.webcert.persistence.arende.model.ArendeDraft in project webcert by sklintyg.
the class ArendeDraftApiControllerTest method buildArendeDraft.
private ArendeDraft buildArendeDraft(String intygId, String text, String amne) {
ArendeDraft arendeDraft = new ArendeDraft();
arendeDraft.setIntygId(intygId);
arendeDraft.setAmne(amne);
arendeDraft.setText(text);
return arendeDraft;
}
use of se.inera.intyg.webcert.persistence.arende.model.ArendeDraft in project webcert by sklintyg.
the class FragaSvarServiceImpl method getFragaSvar.
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public List<FragaSvarView> getFragaSvar(String intygId) {
List<FragaSvar> fragaSvarList = fragaSvarRepository.findByIntygsReferensIntygsId(intygId);
WebCertUser user = webCertUserService.getUser();
validateSekretessmarkering(intygId, fragaSvarList, user);
List<String> hsaEnhetIds = user.getIdsOfSelectedVardenhet();
// Filter questions to that current user only sees questions issued to
// units with active employment role
fragaSvarList.removeIf(fragaSvar -> fragaSvar.getVardperson() != null && !hsaEnhetIds.contains(fragaSvar.getVardperson().getEnhetsId()));
// Finally sort by senasteHandelseDatum
// We do the sorting in code, since we need to sort on a derived
// property and not a direct entity persisted
// property in which case we could have used an order by in the query.
fragaSvarList.sort(SENASTE_HANDELSE_DATUM_COMPARATOR);
List<ArendeDraft> drafts = arendeDraftService.listAnswerDrafts(intygId);
List<AnsweredWithIntyg> bmi = AnsweredWithIntygUtil.findAllKomplementForGivenIntyg(intygId, utkastRepository);
List<FragaSvarView> fragaSvarWithBesvaratMedIntygInfo = fragaSvarList.stream().map(fs -> FragaSvarView.create(fs, fs.getFrageSkickadDatum() == null ? null : AnsweredWithIntygUtil.returnOldestKompltOlderThan(fs.getFrageSkickadDatum(), bmi), drafts.stream().filter(d -> Long.toString(fs.getInternReferens()).equals(d.getQuestionId())).findAny().map(ArendeDraft::getText).orElse(null))).collect(Collectors.toList());
return fragaSvarWithBesvaratMedIntygInfo;
}
Aggregations