Removed unneeded entity fields, moved observation view to new format

This commit is contained in:
neviyn 2018-11-30 11:39:21 +00:00
parent cb58720c23
commit d8b3c0040d
9 changed files with 229 additions and 510 deletions

View File

@ -20,7 +20,6 @@ data class NewObservation(
val site: Long, val site: Long,
val type: TrainingType, val type: TrainingType,
val observed: String, val observed: String,
val whom: String,
val scenarios: List<Scenario>, val scenarios: List<Scenario>,
val tutors: List<Long>, val tutors: List<Long>,
val person: String val person: String

View File

@ -87,7 +87,6 @@ class Controller {
date = LocalDate.now(), date = LocalDate.now(),
type = newObservation.type, type = newObservation.type,
observed = newObservation.scenarios.joinToString { it.title }, observed = newObservation.scenarios.joinToString { it.title },
whom = newObservation.whom,
monitoring = newObservation.scenarios.map { it.monitoring.rating }.average(), monitoring = newObservation.scenarios.map { it.monitoring.rating }.average(),
conservatism = newObservation.scenarios.map { it.conservatism.rating }.average(), conservatism = newObservation.scenarios.map { it.conservatism.rating }.average(),
controlProcedural = newObservation.scenarios.map { it.controlProcedural.rating }.average(), controlProcedural = newObservation.scenarios.map { it.controlProcedural.rating }.average(),
@ -116,34 +115,19 @@ class Controller {
fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> { fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> {
if (observationsRequest.tutor != null) { if (observationsRequest.tutor != null) {
return tutorRepository.findById(observationsRequest.tutor).map { return tutorRepository.findById(observationsRequest.tutor).map {
when { observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(tutor = it,
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(tutor = it,
startDate = observationsRequest.startDate, startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate) endDate = observationsRequest.endDate)
else -> observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor = it,
whom = observationsRequest.whom,
startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate)
}
}.orElse(listOf()) }.orElse(listOf())
} else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) { } else if (observationsRequest.person != null && observationsRequest.person.isNotEmpty() && observationsRequest.site != null) {
val person = personRepository.findFirstByNameLike(observationsRequest.person.toUpperCase()) ?: return listOf() val person = personRepository.findFirstByNameLike(observationsRequest.person.toUpperCase()) ?: return listOf()
val site = siteRepository.findById(observationsRequest.site).get() val site = siteRepository.findById(observationsRequest.site).get()
return if (observationsRequest.whom == null || observationsRequest.whom.isEmpty()) return observationRepository.findBySiteAndPersonAndDateBetweenOrderByDateAsc(site, person, observationsRequest.startDate, observationsRequest.endDate)
observationRepository.findBySiteAndPersonAndDateBetweenOrderByDateAsc(site, person, observationsRequest.startDate, observationsRequest.endDate)
else
observationRepository.findBySiteAndWhomIgnoreCaseAndPersonAndDateBetweenOrderByDateAsc(site, observationsRequest.whom, person, observationsRequest.startDate, observationsRequest.endDate)
} else if (observationsRequest.site != null) { } else if (observationsRequest.site != null) {
return siteRepository.findById(observationsRequest.site).map { return siteRepository.findById(observationsRequest.site).map {
when { observationRepository.findBySiteAndDateBetweenOrderByDateAsc(site = it,
(observationsRequest.whom == null || observationsRequest.whom.isEmpty()) -> observationRepository.findBySiteAndDateBetweenOrderByDateAsc(site = it,
startDate = observationsRequest.startDate, startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate) endDate = observationsRequest.endDate)
else -> observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site = it,
whom = observationsRequest.whom,
startDate = observationsRequest.startDate,
endDate = observationsRequest.endDate)
}
}.orElse(listOf()) }.orElse(listOf())
} }
return listOf() return listOf()

View File

@ -3,8 +3,8 @@ package uk.co.neviyn.observationdatabase
import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import org.joda.time.LocalDate import org.joda.time.LocalDate
import javax.persistence.CascadeType
import javax.persistence.Column import javax.persistence.Column
import javax.persistence.ElementCollection
import javax.persistence.Entity import javax.persistence.Entity
import javax.persistence.FetchType import javax.persistence.FetchType
import javax.persistence.GeneratedValue import javax.persistence.GeneratedValue
@ -76,8 +76,6 @@ data class Observation(
@Column(nullable = false) @Column(nullable = false)
val type: TrainingType, val type: TrainingType,
@Column(nullable = false) @Column(nullable = false)
val whom: String,
@Column(nullable = false)
val observed: String, val observed: String,
val monitoring: Double?, val monitoring: Double?,
val controlProcedural: Double?, val controlProcedural: Double?,
@ -87,7 +85,7 @@ data class Observation(
val teamworkLeadership: Double?, val teamworkLeadership: Double?,
val teamworkWorkload: Double?, val teamworkWorkload: Double?,
val knowledge: Double?, val knowledge: Double?,
@ElementCollection @OneToMany(cascade = [CascadeType.ALL])
val scenarios: List<Scenario>, val scenarios: List<Scenario>,
@ManyToMany(mappedBy = "observations") @ManyToMany(mappedBy = "observations")
val tutors: Set<Tutor>, val tutors: Set<Tutor>,
@ -132,21 +130,21 @@ data class Scenario(
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0, val id: Long = 0,
val title: String, val title: String,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val monitoring: RatingComponent, val monitoring: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val controlProcedural: RatingComponent, val controlProcedural: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val control: RatingComponent, val control: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val conservatism: RatingComponent, val conservatism: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val teamworkCommunications: RatingComponent, val teamworkCommunications: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val teamworkLeadership: RatingComponent, val teamworkLeadership: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val teamworkWorkload: RatingComponent, val teamworkWorkload: RatingComponent,
@OneToOne @OneToOne(cascade = [CascadeType.ALL])
val knowledge: RatingComponent val knowledge: RatingComponent
) )

View File

@ -17,13 +17,7 @@ interface ObservationRepository : CrudRepository<Observation, Long> {
fun findByTutorsAndDateBetweenOrderByDateAsc(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List<Observation> fun findByTutorsAndDateBetweenOrderByDateAsc(tutor: Tutor, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site: Site, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor: Tutor, whom: String, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndPersonAndDateBetweenOrderByDateAsc(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation> fun findBySiteAndPersonAndDateBetweenOrderByDateAsc(site: Site, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
fun findBySiteAndWhomIgnoreCaseAndPersonAndDateBetweenOrderByDateAsc(site: Site, whom: String, person: Person, startDate: LocalDate, endDate: LocalDate): List<Observation>
} }
@Repository @Repository

View File

@ -112,11 +112,11 @@ class ControllerTest {
} }
@Test @Test
fun testGetObservations_WithSite_TutorNull_NoWhom() { fun testGetObservations_WithSite_TutorNull() {
val request = ObservationsRequest(1, null, "", "", LocalDate.now(), LocalDate.now()) val request = ObservationsRequest(1, null, "", "", LocalDate.now(), LocalDate.now())
val site = Site(1, "Area 51") val site = Site(1, "Area 51")
val observation = Observation(site = site, date = LocalDate.now(), val observation = Observation(site = site, date = LocalDate.now(),
type = TrainingType.INITIAL, observed = "1", whom = "G1", monitoring = 5.0, controlProcedural = 3.0, type = TrainingType.INITIAL, observed = "1", monitoring = 5.0, controlProcedural = 3.0,
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(), person = Person(name = "noone")) teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(), person = Person(name = "noone"))
doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
@ -128,28 +128,12 @@ class ControllerTest {
} }
@Test @Test
fun testGetObservations_WithSite_TutorNull_WithWhom() { fun testGetObservations_WithSite_WithTutor() {
val request = ObservationsRequest(1, null, "Group A", "", LocalDate.now(), LocalDate.now())
val site = Site(1, "Area 51")
val observation = Observation(site = site, date = LocalDate.now(),
type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0, controlProcedural = 3.0,
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(), person = Person(name = "noone"))
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
doReturn(listOf(observation))
.`when`(observationRepository).findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(site, "Group A", LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request)
assertEquals(1, result.size)
assertEquals(observation, result[0])
}
@Test
fun testGetObservations_WithSite_WithTutor_NoWhom() {
val request = ObservationsRequest(null, 1, "", "", LocalDate.now(), LocalDate.now()) val request = ObservationsRequest(null, 1, "", "", LocalDate.now(), LocalDate.now())
val site = Site(1, "Area 51") val site = Site(1, "Area 51")
val tutor = Tutor(1, "Mr Unknown", site) val tutor = Tutor(1, "Mr Unknown", site)
val observation = Observation(site = site, date = LocalDate.now(), val observation = Observation(site = site, date = LocalDate.now(),
type = TrainingType.INITIAL, observed = "1", whom = "G1", monitoring = 5.0, controlProcedural = 3.0, type = TrainingType.INITIAL, observed = "1", monitoring = 5.0, controlProcedural = 3.0,
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = Person(name = "noone")) teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = Person(name = "noone"))
doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1) doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1)
@ -160,23 +144,6 @@ class ControllerTest {
assertEquals(observation, result[0]) assertEquals(observation, result[0])
} }
@Test
fun testGetObservations_WithSite_WithTutor_WithWhom() {
val request = ObservationsRequest(null, 1, "Group A", "", LocalDate.now(), LocalDate.now())
val site = Site(1, "Area 51")
val tutor = Tutor(1, "Mr Unknown", site)
val observation = Observation(site = site, date = LocalDate.now(),
type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0, controlProcedural = 3.0,
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = Person(name = "noone"))
doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1)
doReturn(listOf(observation))
.`when`(observationRepository).findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(tutor, "Group A", LocalDate.now(), LocalDate.now())
val result = controller.getObservations(request)
assertEquals(1, result.size)
assertEquals(observation, result[0])
}
@Test @Test
fun testGetObservations_WithPerson() { fun testGetObservations_WithPerson() {
val request = ObservationsRequest(1, null, null, "Foo Bar", LocalDate.now(), LocalDate.now()) val request = ObservationsRequest(1, null, null, "Foo Bar", LocalDate.now(), LocalDate.now())
@ -184,7 +151,7 @@ class ControllerTest {
val tutor = Tutor(1, "Mr Unknown", site) val tutor = Tutor(1, "Mr Unknown", site)
val person = Person(1, "Foo Bar") val person = Person(1, "Foo Bar")
val observation = Observation(site = site, date = LocalDate.now(), val observation = Observation(site = site, date = LocalDate.now(),
type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0, controlProcedural = 3.0, type = TrainingType.INITIAL, observed = "1", monitoring = 5.0, controlProcedural = 3.0,
control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0, control = 4.0, conservatism = 3.0, teamworkCommunications = 2.0, teamworkLeadership = 3.0,
teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = person) teamworkWorkload = 1.0, knowledge = 1.0, scenarios = listOf(), tutors = setOf(tutor), person = person)
doReturn(Optional.of(site)).`when`(siteRepository).findById(1) doReturn(Optional.of(site)).`when`(siteRepository).findById(1)

View File

@ -31,15 +31,6 @@ class RepositoryTest {
assertTrue(result.isEmpty()) assertTrue(result.isEmpty())
} }
@Test
fun testFindBySiteAndWhomIgnoreCaseAndDateBetween_EmptyRepository() {
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(Site(
id = 1,
name = "x"
), "none", LocalDate.now(), LocalDate.now())
assertTrue(result.isEmpty())
}
@Test @Test
fun testFindByTutorsAndDateBetween_EmptyRepository() { fun testFindByTutorsAndDateBetween_EmptyRepository() {
val result = observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(Tutor( val result = observationRepository.findByTutorsAndDateBetweenOrderByDateAsc(Tutor(
@ -50,16 +41,6 @@ class RepositoryTest {
assertTrue(result.isEmpty()) assertTrue(result.isEmpty())
} }
@Test
fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween_EmptyRepository() {
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(Tutor(
id = 1,
name = "x",
site = Site(1, "x")
), "none", LocalDate.now(), LocalDate.now())
assertTrue(result.isEmpty())
}
@Test @Test
fun testFindBySiteAndDateBetween() { fun testFindBySiteAndDateBetween() {
val correctSite = entityManager.persist(Site(name = "Correct")) val correctSite = entityManager.persist(Site(name = "Correct"))
@ -72,7 +53,6 @@ class RepositoryTest {
date = LocalDate.now().minusDays(5), date = LocalDate.now().minusDays(5),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -90,7 +70,6 @@ class RepositoryTest {
date = LocalDate.now().plusDays(5), date = LocalDate.now().plusDays(5),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -108,7 +87,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -126,7 +104,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -152,118 +129,6 @@ class RepositoryTest {
assertEquals(justRight, result.first()) assertEquals(justRight, result.first())
} }
@Test
fun testFindBySiteAndWhomIgnoreCaseAndDateBetween() {
val correctSite = entityManager.persist(Site(name = "Correct"))
val incorrectSite = entityManager.persist(Site(name = "Incorrect"))
val person = entityManager.persist(Person(name = "Foo Bar"))
val tutor = entityManager.persist(Tutor(name = "X", site = correctSite))
val tutor2 = entityManager.persist(Tutor(name = "N", site = incorrectSite))
val tooEarly = Observation(
site = correctSite,
date = LocalDate.now().minusDays(5),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(tutor),
person = person
)
val tooLate = Observation(
site = correctSite,
date = LocalDate.now().plusDays(5),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(tutor),
person = person
)
val wrongSite = Observation(
site = incorrectSite,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(tutor2),
person = person
)
val justRight = Observation(
site = correctSite,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(tutor),
person = person
)
val wrongWhom = Observation(
site = correctSite,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G2",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(tutor),
person = person
)
entityManager.persist(tooEarly)
entityManager.persist(tooLate)
entityManager.persist(wrongSite)
entityManager.persist(justRight)
entityManager.persist(wrongWhom)
val result = observationRepository.findBySiteAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(
site = correctSite,
startDate = LocalDate.now().minusDays(1),
endDate = LocalDate.now().plusDays(1),
whom = "G1"
)
assertEquals(1, result.size)
assertEquals(justRight, result.first())
}
@Test @Test
fun testFindByTutorsAndDateBetween() { fun testFindByTutorsAndDateBetween() {
val site = entityManager.persist(Site(name = "Correct")) val site = entityManager.persist(Site(name = "Correct"))
@ -275,7 +140,6 @@ class RepositoryTest {
date = LocalDate.now().minusDays(5), date = LocalDate.now().minusDays(5),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -293,7 +157,6 @@ class RepositoryTest {
date = LocalDate.now().plusDays(5), date = LocalDate.now().plusDays(5),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -311,7 +174,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -329,7 +191,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -347,7 +208,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -380,143 +240,6 @@ class RepositoryTest {
assertFalse(result.contains(wrongTutor)) assertFalse(result.contains(wrongTutor))
} }
@Test
fun testFindByTutorsAndWhomIgnoreCaseAndDateBetween() {
val site = entityManager.persist(Site(name = "Correct"))
val person = entityManager.persist(Person(name = "Foo Bar"))
val correctTutor = entityManager.persist(Tutor(name = "X", site = site))
val incorrectTutor = entityManager.persist(Tutor(name = "N", site = site))
val tooEarly = Observation(
site = site,
date = LocalDate.now().minusDays(5),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(correctTutor),
person = person
)
val tooLate = Observation(
site = site,
date = LocalDate.now().plusDays(5),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(correctTutor),
person = person
)
val wrongTutor = Observation(
site = site,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(incorrectTutor),
person = person
)
val justRight = Observation(
site = site,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(correctTutor),
person = person
)
val wrongGroup = Observation(
site = site,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G2",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(correctTutor),
person = person
)
val justRightMultipleTutors = Observation(
site = site,
date = LocalDate.now(),
type = TrainingType.INITIAL,
observed = "1",
whom = "G1",
monitoring = 5.0,
controlProcedural = 3.0,
control = 4.0,
conservatism = 3.0,
teamworkCommunications = 2.0,
teamworkLeadership = 3.0,
teamworkWorkload = 1.0,
knowledge = 1.0,
scenarios = listOf(),
tutors = setOf(correctTutor, incorrectTutor),
person = person
)
entityManager.persist(tooEarly)
entityManager.persist(tooLate)
entityManager.persist(wrongTutor)
entityManager.persist(justRight)
entityManager.persist(wrongGroup)
entityManager.persist(justRightMultipleTutors)
correctTutor.observations.addAll(listOf(tooEarly, tooLate, justRight, justRightMultipleTutors, wrongGroup))
entityManager.persist(correctTutor)
incorrectTutor.observations.addAll(listOf(wrongTutor, justRightMultipleTutors))
entityManager.persist(incorrectTutor)
val result = observationRepository.findByTutorsAndWhomIgnoreCaseAndDateBetweenOrderByDateAsc(
tutor = correctTutor,
startDate = LocalDate.now().minusDays(1),
endDate = LocalDate.now().plusDays(1),
whom = "G1"
)
assertEquals(2, result.size)
assertTrue(result.contains(justRight))
assertTrue(result.contains(justRightMultipleTutors))
assertFalse(result.contains(wrongTutor))
assertFalse(result.contains(wrongGroup))
}
@Test @Test
fun testFindBySiteAndPersonsAndDateBetween() { fun testFindBySiteAndPersonsAndDateBetween() {
val person = entityManager.persist(Person(name = "Foo Bar")) val person = entityManager.persist(Person(name = "Foo Bar"))
@ -528,7 +251,6 @@ class RepositoryTest {
date = LocalDate.now().minusDays(5), date = LocalDate.now().minusDays(5),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -546,7 +268,6 @@ class RepositoryTest {
date = LocalDate.now().plusDays(5), date = LocalDate.now().plusDays(5),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -564,7 +285,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,
@ -582,7 +302,6 @@ class RepositoryTest {
date = LocalDate.now(), date = LocalDate.now(),
type = TrainingType.INITIAL, type = TrainingType.INITIAL,
observed = "1", observed = "1",
whom = "G1",
monitoring = 5.0, monitoring = 5.0,
controlProcedural = 3.0, controlProcedural = 3.0,
control = 4.0, control = 4.0,

View File

@ -1,6 +1,6 @@
<template> <template>
<b-container fluid> <b-container fluid>
<!-- <b-container v-if="description != null && type != null && whom != null && site != null && tutors != null" fluid style="padding-left: 130px;"> --> <!-- <b-container type != null && whom != null && site != null && tutors != null" fluid style="padding-left: 130px;"> -->
<b-container fluid style="padding-left: 130px;"> <b-container fluid style="padding-left: 130px;">
<h3> <h3>
<v-icon name="tag" scale="1.5"/> <v-icon name="tag" scale="1.5"/>
@ -324,7 +324,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(["description", "type", "whom", "site", "tutors"]) ...mapState(["type", "whom", "site", "tutors"])
}, },
methods: { methods: {
addAnotherObservation: function() { addAnotherObservation: function() {
@ -468,8 +468,9 @@ export default {
{ {
site: this.site, site: this.site,
tutors: this.tutors, tutors: this.tutors,
whom: this.whom, person: this.whom,
type: this.type, type: this.type,
observed: this.scenarios.map(x => x.title).join(', '),
scenarios: JSON.parse(JSON.stringify(this.scenarios)) scenarios: JSON.parse(JSON.stringify(this.scenarios))
}, },
axiosConfig axiosConfig

View File

@ -112,7 +112,7 @@ export default {
} }
}, },
computed: { computed: {
...mapState(["site", "description", "type", "tutors", "whom"]) ...mapState(["site", "type", "tutors", "whom"])
}, },
watch: { watch: {
site: function() { site: function() {
@ -130,7 +130,6 @@ export default {
methods: { methods: {
...mapMutations([ ...mapMutations([
"setSite", "setSite",
"setDescription",
"setType", "setType",
"setTutors", "setTutors",
"setWhom", "setWhom",

View File

@ -5,25 +5,22 @@
<h3 class="modal-title w-100">{{ errorStatus }}</h3> <h3 class="modal-title w-100">{{ errorStatus }}</h3>
</div> </div>
<div class="d-block"> <div class="d-block">
<br/> <br>
<span style="font-size:20px;" v-html="errorMessage"/> <span style="font-size:20px;" v-html="errorMessage"/>
<button class="btn btn-warning" @click="$refs.errorModal.hide()"> <button class="btn btn-warning" @click="$refs.errorModal.hide()">
<v-icon name="exclamation-circle"/> <v-icon name="exclamation-circle"/>Dismiss
Dismiss
</button> </button>
</div> </div>
</b-modal> </b-modal>
<b-row> <b-row>
<b-col> <b-col>
<b-form-group label="Site"> <b-form-group label="Site">
<b-form-select class="text-center" v-model="siteSelection" <b-form-select class="text-center" v-model="siteSelection" :options="siteOptions"/>
:options="siteOptions"/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
<b-form-group label="Tutor"> <b-form-group label="Tutor">
<b-form-select class="text-center" v-model="tutorSelection" <b-form-select class="text-center" v-model="tutorSelection" :options="tutorOptions"/>
:options="tutorOptions"/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
@ -38,14 +35,22 @@
</b-col> </b-col>
<b-col> <b-col>
<b-form-group label="From"> <b-form-group label="From">
<date-picker v-model="startDate" @dp-change="changeStartDate" value="startDate" <date-picker
:config="dateOptions"/> v-model="startDate"
@dp-change="changeStartDate"
value="startDate"
:config="dateOptions"
/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
<b-form-group label="To"> <b-form-group label="To">
<date-picker v-model="endDate" @dp-change="changeEndDate" value="endDate" <date-picker
:config="dateOptions"/> v-model="endDate"
@dp-change="changeEndDate"
value="endDate"
:config="dateOptions"
/>
</b-form-group> </b-form-group>
</b-col> </b-col>
<b-col> <b-col>
@ -56,60 +61,110 @@
<b-card no-body> <b-card no-body>
<b-tabs pills card vertical> <b-tabs pills card vertical>
<b-tab v-for="(observation, index) in observationData" v-bind:key="index"> <b-tab v-for="(observation, index) in observationData" v-bind:key="index">
<p slot="title">{{ observation.date }}<br/>{{ observation.whom }} {{ observation.type }}<br/>{{ shortenedString(observation.observed) }}</p> <p slot="title">
<h2>{{ observation.date }}, {{ observation.whom }}<br/>{{ observation.type }}, {{ observation.observed }}</h2> {{ observation.date }}
<br>
{{ observation.whom }} {{ observation.type }}
<br>
{{ shortenedString(observation.observed) }}
</p>
<h2>
{{ observation.date }}, {{ observation.whom }}
<br>
{{ observation.type }} / {{ observation.observed }}
</h2>
<b-row align-h="center"> <b-row align-h="center">
<h4>Observed by:&nbsp;<span v-bind:key="index" v-for="(tutor, index) in observation.tutors"><i>{{ tutor.name }}<span v-if="index+1 < observation.tutors.length">,&nbsp;</span></i></span></h4> <h4>Observed by:
<span v-bind:key="index" v-for="(tutor, index) in observation.tutors">
<i>
{{ tutor.name }}
<span v-if="index+1 < observation.tutors.length">,&nbsp;</span>
</i>
</span>
</h4>
</b-row> </b-row>
<b-row align-h="center"> <b-row align-h="center">
<h4>Participants:&nbsp;<span v-bind:key="index" v-for="(person, index) in observation.persons"><i>{{ person.name }}<span v-if="index+1 < observation.persons.length">,&nbsp;</span></i></span></h4> <h4>Participant:&nbsp;{{ observation.person.name }}</h4>
</b-row> </b-row>
<br /> <br>
<b-row class="mb-2"> <b-row class="mb-2">
<b-col class="centered-image" v-if="observation.monitoring"> <b-col class="centered-image" v-if="observation.monitoring">
<img src="../assets/Monitoring.svg" class="image-opacity"/> <img src="../assets/Monitoring.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.monitoring < 2.5 }">
<div class="image-centered-text">{{ observation.monitoring.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.monitoring.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.controlProcedural"> <b-col class="centered-image" v-if="observation.controlProcedural">
<img src="../assets/Control.svg" class="image-opacity"/> <img src="../assets/Control.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.controlProcedural < 2.5 }">
<div class="image-centered-text">{{ observation.controlProcedural.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.controlProcedural.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.control"> <b-col class="centered-image" v-if="observation.control">
<img src="../assets/Control.svg" class="image-opacity"/> <img src="../assets/Control.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.control < 2.5 }">
<div class="image-centered-text">{{ observation.control.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.control.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.conservatism"> <b-col class="centered-image" v-if="observation.conservatism">
<img src="../assets/Conservatism.svg" class="image-opacity"/> <img src="../assets/Conservatism.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.conservatism < 2.5 }">
<div class="image-centered-text">{{ observation.conservatism.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.conservatism.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.teamworkCommunications"> <b-col class="centered-image" v-if="observation.teamworkCommunications">
<img src="../assets/Teamwork.svg" class="image-opacity"/> <img src="../assets/Teamwork.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.teamworkCommunications < 2.5 }">
<div class="image-centered-text">{{ observation.teamworkCommunications.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.teamworkCommunications.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.teamworkLeadership"> <b-col class="centered-image" v-if="observation.teamworkLeadership">
<img src="../assets/Teamwork.svg" class="image-opacity"/> <img src="../assets/Teamwork.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.teamworkLeadership < 2.5 }">
<div class="image-centered-text">{{ observation.teamworkLeadership.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.teamworkLeadership.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.teamworkWorkload"> <b-col class="centered-image" v-if="observation.teamworkWorkload">
<img src="../assets/Teamwork.svg" class="image-opacity"/> <img src="../assets/Teamwork.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.teamworkWorkload < 2.5 }">
<div class="image-centered-text">{{ observation.teamworkWorkload.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.teamworkWorkload.toFixed(1) }}</div>
</b-col> </b-col>
<b-col class="centered-image" v-if="observation.knowledge"> <b-col class="centered-image" v-if="observation.knowledge">
<img src="../assets/Knowledge.svg" class="image-opacity"/> <img src="../assets/Knowledge.svg" class="image-opacity" v-bind:class="{ scorewarning: observation.knowledge < 2.5 }">
<div class="image-centered-text">{{ observation.knowledge.toFixed(1) }}</div> <div class="image-centered-text">{{ observation.knowledge.toFixed(1) }}</div>
</b-col> </b-col>
</b-row> </b-row>
<div v-for="(entry, index2) in observation.entries" v-bind:key="index2"> <b-row v-for="(entry, index2) in observation.scenarios" v-bind:key="index2">
<p>{{ entry.type }} - {{ entry.rating }}</p> <b-col class="border">
<b-form-group label="Strengths"> <b-row align-h="center">
<b-form-textarea :value="entry.strengths" readonly> <h3>{{ entry.title }}</h3>
</b-form-textarea> </b-row>
</b-form-group> <b-row>
<b-form-group label="Areas of Improvement"> <observation-entry
<b-form-textarea :value="entry.improvements" readonly> :scenariofundamental="entry.monitoring"
</b-form-textarea> :description="'Monitoring'"
</b-form-group> ></observation-entry>
</div> <observation-entry
:scenariofundamental="entry.controlProcedural"
:description="'Control Procedural'"
></observation-entry>
</b-row>
<b-row>
<observation-entry :scenariofundamental="entry.control" :description="'Control'"></observation-entry>
<observation-entry
:scenariofundamental="entry.conservatism"
:description="'Conservatism'"
></observation-entry>
</b-row>
<b-row>
<observation-entry
:scenariofundamental="entry.teamworkCommunications"
:description="'Teamwork Communications'"
></observation-entry>
<observation-entry
:scenariofundamental="entry.teamworkLeadership"
:description="'Teamwork Leadership'"
></observation-entry>
</b-row>
<b-row>
<observation-entry
:scenariofundamental="entry.teamworkWorkload"
:description="'Teamwork Workload'"
></observation-entry>
<observation-entry
:scenariofundamental="entry.knowledge"
:description="'Knowledge'"
></observation-entry>
</b-row>
</b-col>
</b-row>
</b-tab> </b-tab>
</b-tabs> </b-tabs>
</b-card> </b-card>
@ -129,11 +184,13 @@
<script> <script>
import Vue from "vue"; import Vue from "vue";
import "vue-awesome/icons/search"; import "vue-awesome/icons/search";
import ObservationEntry from "../components/ObservationEntry.vue";
var moment = require("moment"); var moment = require("moment");
export default { export default {
name: "viewobservations", name: "viewobservations",
title: "Observations History", title: "Observations History",
components: { ObservationEntry },
data: function() { data: function() {
return { return {
dateOptions: { dateOptions: {
@ -158,7 +215,6 @@ export default {
this.$router.push("/dberror"); this.$router.push("/dberror");
return; return;
} }
console.log(error);
}); });
this.getTutors(); this.getTutors();
this.getFiltered(); this.getFiltered();
@ -169,7 +225,7 @@ export default {
return this.$store.state.search.start; return this.$store.state.search.start;
}, },
set(data) { set(data) {
this.$store.commit('setSearchStartDate', data); this.$store.commit("setSearchStartDate", data);
} }
}, },
endDate: { endDate: {
@ -177,7 +233,7 @@ export default {
return this.$store.state.search.end; return this.$store.state.search.end;
}, },
set(data) { set(data) {
this.$store.commit('setSearchEndDate', data); this.$store.commit("setSearchEndDate", data);
} }
}, },
siteSelection: { siteSelection: {
@ -185,7 +241,7 @@ export default {
return this.$store.state.search.site; return this.$store.state.search.site;
}, },
set(data) { set(data) {
this.$store.commit('setSearchSite', data); this.$store.commit("setSearchSite", data);
} }
}, },
tutorSelection: { tutorSelection: {
@ -193,7 +249,7 @@ export default {
return this.$store.state.search.tutor; return this.$store.state.search.tutor;
}, },
set(data) { set(data) {
this.$store.commit('setSearchTutor', data) this.$store.commit("setSearchTutor", data);
} }
}, },
whom: { whom: {
@ -201,7 +257,7 @@ export default {
return this.$store.state.search.whom; return this.$store.state.search.whom;
}, },
set(data) { set(data) {
this.$store.commit('setSearchWhom', data) this.$store.commit("setSearchWhom", data);
} }
}, },
person: { person: {
@ -209,7 +265,7 @@ export default {
return this.$store.state.search.person; return this.$store.state.search.person;
}, },
set(data) { set(data) {
this.$store.commit('setSearchPerson', data) this.$store.commit("setSearchPerson", data);
} }
} }
}, },
@ -278,8 +334,7 @@ export default {
shortenedString: function(data) { shortenedString: function(data) {
if (data.len < 20) { if (data.len < 20) {
return data; return data;
} } else {
else{
return data.substr(0, 20) + "..."; return data.substr(0, 20) + "...";
} }
} }
@ -302,6 +357,9 @@ export default {
position: relative; position: relative;
text-align: center; text-align: center;
} }
.scorewarning {
background-color: red;
}
.image-centered-text { .image-centered-text {
position: absolute; position: absolute;
top: 50%; top: 50%;