use of se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg in project webcert by sklintyg.
the class ArendeViewConverterTest method ifMultipleKompltIntygClosestInTimeShouldBeChoosen.
@Test
public void ifMultipleKompltIntygClosestInTimeShouldBeChoosen() {
// Given
LocalDateTime fragaDate = LocalDateTime.parse("2016-03-01T11:22:11");
Arende fraga = createValidArendeForLuse("fraga", fragaDate, "fraga-id", null);
List<AnsweredWithIntyg> komplt = ImmutableList.of(createMatchingAnsweredWithIntyg(fraga, fragaDate.plusDays(3)), createMatchingAnsweredWithIntyg(fraga, fragaDate.plusDays(1)), createMatchingAnsweredWithIntyg(fraga, fragaDate.plusDays(2)));
// When
List<ArendeConversationView> messageThreads = converter.buildArendeConversations(fraga.getIntygsId(), ImmutableList.of(fraga), komplt, Collections.emptyList());
// Then
Assertions.assertThat(messageThreads).hasSize(1).extracting(ArendeConversationView::getAnsweredWithIntyg).contains(komplt.get(1));
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg 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.web.web.controller.api.dto.AnsweredWithIntyg 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