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

Man 108 record if complied and update note #4442

Closed
wants to merge 4 commits into from
Closed
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 @@ -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 @@ -89,11 +89,12 @@ class AppointmentOutcomeIntegrationTest {
val createdAppointment = appointmentRepository.findById(response.appointments[0].id).get()

assertNull(createdAppointment.attended)
assertNull(createdAppointment.complied)
assertNull(createdAppointment.notes)
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 @@ -106,7 +107,8 @@ class AppointmentOutcomeIntegrationTest {
val updatedAppointment = appointmentRepository.findById(response.appointments[0].id).get()

assertEquals("Y", updatedAppointment.attended)
assertEquals(request.notes, updatedAppointment.notes)
assertEquals("Y", updatedAppointment.complied)
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 @@ -83,6 +83,9 @@ class Appointment(
@Column(name = "attended", columnDefinition = "char(1)")
var attended: String? = null,

@Column(name = "complied", columnDefinition = "char(1")
var complied: String? = null,

@Column(name = "contact_outcome_type_id")
var outcomeId: Long? = null,

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,8 +23,17 @@ class AppointmentOutcomeService(
contactTypeOutcomeRepository.getByTypeIdAndOutcomeCode(appointment.type.id, outcome.code)

appointment.apply {
val dateTime = LocalDateTime.now()
attended = outcome.attended
notes = outcome.notes
complied = if (contactTypeOutcome.outcome.outcomeCompliantAcceptable!!) "Y" else "N"
notes = outcome.notes?.let {
"""
Comment added by ${outcome.recordedBy} on ${
dateTime.format(DeliusDateTimeFormatter).substring(0, 10)
} at ${dateTime.format(DeliusDateTimeFormatter).substring(11, 16)}
Comment on lines +31 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this line added by the Delius DB trigger? Do you need to add it manually?

Copy link
Contributor Author

@achimber-moj achimber-moj Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-11-19 at 16 20 20 When I ran the api in dev, only the note was added. The 'created by' part was empty, see second contact for D001024 in dev.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's because you're overwriting the notes rather than appending to them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, you might need to stick a new line in there as well but I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to deploy my branch to dev with an update to see if the notes are created successfully

$it
""".trimIndent()
}
outcomeId = contactTypeOutcome.outcome.id
sensitive = outcome.sensitive
}
Expand Down
Loading