Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StartDate to limit contacts search result #304

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
*/
package de.hs_mannheim.informatik.ct.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -112,14 +111,24 @@ public String searchPage() {
}

@PostMapping("/results")
public String doSearch(@RequestParam String email, Model model) {
public String doSearch(
@RequestParam String email,
@RequestParam(required=false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Optional<Date> startDate,
Model model) {

val target = visitorService.findVisitorByEmail(email);
if (!target.isPresent()) {
model.addAttribute("error", "Eingegebene E-Mail-Adresse konnte im System nicht gefunden werden!");
return "tracing/search";
}

val contacts = contactTracingService.getVisitorContacts(target.get());
List<Contact<? extends Visit>> contacts;
if(startDate.isPresent()){
contacts = contactTracingService.getVisitorContacts(target.get(), startDate.get());
}else{
contacts = contactTracingService.getVisitorContacts(target.get());
}

List<Contact<?>> contactsStudents = filterContactList(contacts, "students");
List<Contact<?>> contactsStaff = filterContactList(contacts, "staff");
List<Contact<?>> contactsGuests = filterContactList(contacts, "guests");
Expand Down Expand Up @@ -157,6 +166,8 @@ public String doSearch(@RequestParam String email, Model model) {
return rowValues;
}).collect(Collectors.toList());

DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

model.addAttribute("numberOfContacts", contacts.size());
model.addAttribute("tableHeadersStudents", tracingColumnsStudents.stream().map(TracingColumn::getHeader).toArray());
model.addAttribute("tableHeadersStaff", tracingColumnsStaff.stream().map(TracingColumn::getHeader).toArray());
Expand All @@ -165,6 +176,7 @@ public String doSearch(@RequestParam String email, Model model) {
model.addAttribute("tableValuesStaff", contactTableStaff);
model.addAttribute("tableValuesGuests", contactTableGuests);
model.addAttribute("target", target.get().getEmail());
model.addAttribute("searchStartDate", startDate.isPresent() ? dateFormat.format(startDate.get()) : null);

return "tracing/contactList.html";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public interface RoomVisitRepository extends JpaRepository<RoomVisit, Long> {
"ORDER BY visitTarget.startDate")
List<Contact<RoomVisit>> findVisitsWithContact(@Param(value = "visitor") Visitor visitor);

@Query("SELECT NEW de.hs_mannheim.informatik.ct.model.Contact(visitTarget, visitOther) " +
"FROM RoomVisit visitTarget," +
"RoomVisit visitOther " +
"WHERE visitTarget.visitor = :visitor AND " +
"visitTarget.visitor != visitOther.visitor AND " +
"visitTarget.room = visitOther.room AND " +
"visitTarget.startDate <= visitOther.endDate AND " +
"visitOther.startDate <= visitTarget.endDate AND " +
"visitOther.startDate >= :startDate " +
"ORDER BY visitTarget.startDate")
List<Contact<RoomVisit>> findVisitsWithContactAndStartDate(@Param(value = "visitor") Visitor visitor, @Param(value = "startDate") Date startDate);

/**
* Gets the total number of people currently checked in in a study room
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package de.hs_mannheim.informatik.ct.persistence.services;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import de.hs_mannheim.informatik.ct.model.Visit;
Expand All @@ -44,4 +45,13 @@ public List<Contact<? extends Visit>> getVisitorContacts(@NonNull Visitor visito

return contacts;
}

@NonNull
public List<Contact<? extends Visit>> getVisitorContacts(@NonNull Visitor visitor, Date startDate) {
val contacts = new ArrayList<Contact<?>>();
for (val service : visitServices) {
contacts.addAll(service.getVisitorContacts(visitor, startDate));
}
return contacts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public LocalDateTime getNow() {
public Date getDateNow() {
return Date.from(getNow().atZone(ZoneId.systemDefault()).toInstant());
}

public Date getDate(int year, int month, int dayOfMonth, int hour, int minute){
return Date.from(LocalDateTime.of(year, month, dayOfMonth, hour, minute).atZone(ZoneId.systemDefault()).toInstant());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ public void deleteExpiredRecords(Period recordLifeTime) {
public List<Contact<EventVisit>> getVisitorContacts(@NonNull Visitor visitor) {
return eventVisitRepository.findVisitsWithContact(visitor);
}

@Override
public List<Contact<EventVisit>> getVisitorContacts(@NonNull Visitor visitor, Date startDate) {
return eventVisitRepository.findVisitsWithContact(visitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -71,7 +72,11 @@ public class RoomVisitService implements VisitService<RoomVisit> {
private String studyRooms;

public RoomVisit visitRoom(Visitor visitor, Room room) {
return roomVisitRepository.save(new RoomVisit(visitor, room, dateTimeService.getDateNow()));
return visitRoom(visitor, room, dateTimeService.getDateNow());
}

public RoomVisit visitRoom(Visitor visitor, Room room, Date date) {
return roomVisitRepository.save(new RoomVisit(visitor, room, date));
}

/**
Expand Down Expand Up @@ -99,9 +104,14 @@ public RoomVisit visitFullRoom(Visitor visitor, Room fullRoom) {
*/
@NonNull
public List<RoomVisit> checkOutVisitor(@NonNull Visitor visitor) {
return checkOutVisitor(visitor, dateTimeService.getDateNow());
}

@NonNull
public List<RoomVisit> checkOutVisitor(@NonNull Visitor visitor, Date date) {
List<RoomVisit> notSignedOutVisits = getCheckedInRoomVisits(visitor);
notSignedOutVisits.forEach((visit) -> {
visit.checkOut(dateTimeService.getDateNow(), CheckOutSource.UserCheckout);
visit.checkOut(date, CheckOutSource.UserCheckout);
roomVisitRepository.save(visit);
});

Expand Down Expand Up @@ -191,6 +201,13 @@ public List<Contact<RoomVisit>> getVisitorContacts(@NonNull Visitor visitor) {
return contacts;
}

public List<Contact<RoomVisit>> getVisitorContacts(@NonNull Visitor visitor, Date startDate) {
val contacts = roomVisitRepository.findVisitsWithContactAndStartDate(visitor, startDate);
log.info("Contact tracing delivered {} contacts.", contacts.size());

return contacts;
}

public int getRemainingStudyPlaces() {
if (studyRooms.isEmpty())
return -1; // if no study rooms are configured in application.properties, skip DB queries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package de.hs_mannheim.informatik.ct.persistence.services;

import java.util.Date;
import java.util.List;

import de.hs_mannheim.informatik.ct.model.Contact;
Expand All @@ -27,4 +28,5 @@

public interface VisitService<T extends Visit> {
List<Contact<T>> getVisitorContacts(@NonNull Visitor visitor);
List<Contact<T>> getVisitorContacts(@NonNull Visitor visitor, Date startDate);
}
10 changes: 5 additions & 5 deletions src/main/resources/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

<head>
<title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE">HSMA CTT</title>
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/style.css"/>

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.7.2/css/all.css">
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.7.2/css/all.css"/>

<style>
@media screen and (max-width: 768px){
Expand All @@ -34,7 +34,7 @@
<nav class="navbar navbar-expand-md fixed-top navbar-dark text-white" style="background-color: #22376f;">
<a class="navbar-brand" href="/">
<img src="https://www.hs-mannheim.de/typo3conf/ext/hs_mannheim_site/Resources/Public/Icons/logo_bildmarke.svg"
alt="HSMA" style="width:40px;" class="mr-2">CTT
alt="HSMA" style="width:40px;" class="mr-2"/>CTT
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/tracing/contactList.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h4 class="mb-4">Kontaktverfolgung</h4>

<div th:unless="${numberOfContacts} == 0">

<p>Hier sind die Kontakte f&uuml;r <span th:text="${target}"></span>.
<p>Hier sind die Kontakte f&uuml;r <strong th:text="${target}"></strong><span th:if="${searchStartDate != null}"> ab dem </span><strong th:text="${searchStartDate}"></strong>.
Zur Weitergabe an das Gesundheitsamt können die Daten in Form von Excel Dateien heruntergeladen werden.
Dabei kann jeweils eine seperate Excel-Datei für Studenten, Lehrende/Hochschulangestellte und Gäste
heruntergeladen werden.
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/templates/tracing/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,28 @@ <h5 class="mb-4">Nachverfolgung</h5>

<form action="#" th:action="@{results}" method="POST">
<div class="form-group">
<label for="email">E-Mail: *</label>
<label class="ml-1" for="email">E-Mail: *</label>
<input type="text" id="email" name="email" size="32" class="ml-1" required>
<input type="submit" class="btn btn-info ml-2" value="Suchen">
</div>

<div class="form-group">
<label class="ml-1" for="startDate">Suche ab (Datum):</label>
<input type="date" id="startDate" name="startDate" size="32" class="ml-1">
</div>
<p><small><i>* = notwendige Eingabe</i></small></p>

</form>

<p class="error-contact-tracing"th:text="${error}"></p>

</div>

<script>
var date = new Date();
date.setDate(date.getDate() - 7);
document.getElementById('startDate').value = date.toISOString().substr(0, 10);
</script>

</div>
</body>

Expand Down
Loading