Skip to content

Commit

Permalink
MAN-156 - update note to add created by
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Nov 19, 2024
1 parent 1e4a6ea commit db7efc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppointmentOutcomeIntegrationTest {
@Autowired
internal lateinit var mockMvc: MockMvc

val outcome = Outcome(123, "ATTC", "N")
val outcome = Outcome(123, "Jack Ryan","ATTC", "N")

@Test
fun `unauthorized status returned`() {
Expand Down Expand Up @@ -70,7 +70,7 @@ class AppointmentOutcomeIntegrationTest {
.perform(
MockMvcRequestBuilders.patch("/appointment")
.withToken()
.withJson(Outcome(response.appointments[0].id, "ABC", "Y"))
.withJson(Outcome(response.appointments[0].id, "Jon Jones", "ABC", "Y"))
)
.andExpect(MockMvcResultMatchers.status().isNotFound)
.andExpect(
Expand All @@ -94,7 +94,7 @@ class AppointmentOutcomeIntegrationTest {
assertNull(createdAppointment.outcomeId)
assertNull(createdAppointment.sensitive)

val request = Outcome(response.appointments[0].id, "ATTC", "Y", notes = "my notes")
val request = Outcome(response.appointments[0].id, "Jason Bourne", "ATTC", "Y", notes = "my notes")

mockMvc
.perform(
Expand All @@ -108,7 +108,7 @@ class AppointmentOutcomeIntegrationTest {

assertEquals("Y", updatedAppointment.attended)
assertEquals("Y", updatedAppointment.complied)
assertEquals(request.notes, updatedAppointment.notes)
assertEquals(request.notes, updatedAppointment.notes!!.lines()[1])
assertEquals(ATTENDED_COMPLIED.id, updatedAppointment.outcomeId)
assertFalse(updatedAppointment.sensitive!!)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.api.model.appointment

data class Outcome(
val id: Long,
val recordedBy: String,
val code: String,
val attended: String,
val sensitive: Boolean? = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package uk.gov.justice.digital.hmpps.service

import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.api.model.appointment.Outcome
import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AppointmentRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.ContactTypeOutcomeRepository
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.getByTypeIdAndOutcomeCode
import java.time.LocalDateTime

@Service
class AppointmentOutcomeService(
Expand All @@ -21,9 +23,13 @@ class AppointmentOutcomeService(
contactTypeOutcomeRepository.getByTypeIdAndOutcomeCode(appointment.type.id, outcome.code)

appointment.apply {
val dateTime = LocalDateTime.now()
attended = outcome.attended
complied = if (contactTypeOutcome.outcome.outcomeCompliantAcceptable!!) "Y" else "N"
notes = outcome.notes
notes = outcome.notes?.let { """
Comment added by ${outcome.recordedBy} on ${dateTime.format(DeliusDateTimeFormatter).substring(0, 10)} at ${dateTime.format(DeliusDateTimeFormatter).substring(11, 16)}
$it
""".trimIndent() }
outcomeId = contactTypeOutcome.outcome.id
sensitive = outcome.sensitive
}
Expand Down

0 comments on commit db7efc6

Please sign in to comment.