use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView 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.ArendeConversationView in project webcert by sklintyg.
the class ArendeViewConverterTest method buildArendeConversationsTest.
@Test
public void buildArendeConversationsTest() {
final LocalDateTime january = LocalDateTime.parse("2013-01-12T11:22:11");
final LocalDateTime february = LocalDateTime.parse("2013-02-12T11:22:11");
final LocalDateTime decemberYear9999 = LocalDateTime.parse("9999-12-11T10:22:00");
List<Arende> arendeList = new ArrayList<>();
arendeList.add(buildArende(UUID.randomUUID().toString(), decemberYear9999, february));
arendeList.add(buildArende(UUID.randomUUID().toString(), january, january));
// svar
arendeList.get(1).setSvarPaId(arendeList.get(0).getMeddelandeId());
arendeList.add(buildArende(UUID.randomUUID().toString(), decemberYear9999, decemberYear9999));
arendeList.get(2).setAmne(ArendeAmne.PAMINN);
// paminnelse
arendeList.get(2).setPaminnelseMeddelandeId(arendeList.get(0).getMeddelandeId());
arendeList.add(buildArende(UUID.randomUUID().toString(), february, february));
arendeList.add(buildArende(UUID.randomUUID().toString(), decemberYear9999, decemberYear9999));
arendeList.add(buildArende(UUID.randomUUID().toString(), january, january));
List<ArendeConversationView> result = converter.buildArendeConversations(intygsId, arendeList, Collections.emptyList(), Collections.emptyList());
assertEquals(4, result.size());
assertEquals(1, result.get(0).getPaminnelser().size());
assertEquals(arendeList.get(0).getMeddelandeId(), result.get(0).getFraga().getInternReferens());
assertEquals(arendeList.get(1).getMeddelandeId(), result.get(0).getSvar().getInternReferens());
assertEquals(arendeList.get(2).getMeddelandeId(), result.get(0).getPaminnelser().get(0).getInternReferens());
assertEquals(arendeList.get(3).getMeddelandeId(), result.get(2).getFraga().getInternReferens());
assertEquals(arendeList.get(4).getMeddelandeId(), result.get(1).getFraga().getInternReferens());
assertEquals(arendeList.get(5).getMeddelandeId(), result.get(3).getFraga().getInternReferens());
assertEquals(decemberYear9999, result.get(0).getSenasteHandelse());
assertEquals(decemberYear9999, result.get(1).getSenasteHandelse());
assertEquals(february, result.get(2).getSenasteHandelse());
assertEquals(january, result.get(3).getSenasteHandelse());
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView 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.ArendeConversationView in project webcert by sklintyg.
the class ArendeServiceImpl method setForwarded.
@Override
@Transactional
public List<ArendeConversationView> setForwarded(String intygsId) {
WebCertUser user = webcertUserService.getUser();
List<Arende> arendenToForward = arendeRepository.save(arendeRepository.findByIntygsId(intygsId).stream().filter(isCorrectEnhet(user)).filter(isQuestion()).peek(arende -> authoritiesValidator.given(user, arende.getIntygTyp()).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_FRAGASVAR).orThrow()).peek(Arende::setArendeToVidareBerordrat).collect(Collectors.toList()));
if (arendenToForward.isEmpty()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find any arende related to IntygsId: " + intygsId);
}
return getArendeConversationViewList(intygsId, arendenToForward);
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.
the class ArendeServiceImpl method getArenden.
@Override
public List<ArendeConversationView> getArenden(String intygsId) {
WebCertUser user = webcertUserService.getUser();
List<Arende> arendeList = getArendeForIntygId(intygsId, user);
arendeList.stream().findFirst().map(Arende::getPatientPersonId).map(personNummer -> Personnummer.createPersonnummer(personNummer).orElseThrow(() -> new IllegalArgumentException("Could not parse personnummer when querying for arenden."))).ifPresent(pn -> authoritiesValidator.given(user).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, SekretessStatus.TRUE.equals(patientDetailsResolver.getSekretessStatus(pn))).orThrow());
return getArendeConversationViewList(intygsId, arendeList);
}
Aggregations