Skip to content

Commit 31abae5

Browse files
authored
CDPS-1253: Support common ref data object (#33)
1 parent 1b3b177 commit 31abae5

File tree

7 files changed

+166
-68
lines changed

7 files changed

+166
-68
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/common/client/PrisonApiClient.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.U
2222
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateReligion
2323
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.DistinguishingMarkPrisonDto
2424
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.MilitaryRecordPrisonDto
25-
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.PhysicalAttributes
25+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.PhysicalAttributesPrisonDto
2626

2727
@HttpExchange("/api")
2828
interface PrisonApiClient {
@@ -71,7 +71,7 @@ interface PrisonApiClient {
7171
@GetExchange("/offenders/{offenderNo}/core-person-record/physical-attributes")
7272
fun getPhysicalAttributes(
7373
@PathVariable offenderNo: String,
74-
): ResponseEntity<PhysicalAttributes>
74+
): ResponseEntity<PhysicalAttributesPrisonDto>
7575

7676
@PutExchange("/offenders/{offenderNo}/core-person-record/physical-attributes")
7777
fun updatePhysicalAttributes(

src/main/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/common/client/response/PhysicalAttributes.kt

-54
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL
5+
import io.swagger.v3.oas.annotations.media.Schema
6+
7+
@JsonInclude(NON_NULL)
8+
@Schema(description = "Physical Attributes")
9+
data class PhysicalAttributesPrisonDto(
10+
@Schema(description = "Height (in centimetres)")
11+
val height: Int? = null,
12+
13+
@Schema(description = "Weight (in kilograms)")
14+
val weight: Int? = null,
15+
16+
@Schema(description = "Hair type or colour")
17+
val hair: ProfileCode? = null,
18+
19+
@Schema(description = "Facial hair type")
20+
val facialHair: ProfileCode? = null,
21+
22+
@Schema(description = "Face shape")
23+
val face: ProfileCode? = null,
24+
25+
@Schema(description = "Build")
26+
val build: ProfileCode? = null,
27+
28+
@Schema(description = "Left eye colour")
29+
val leftEyeColour: ProfileCode? = null,
30+
31+
@Schema(description = "Right eye colour")
32+
val rightEyeColour: ProfileCode? = null,
33+
34+
@Schema(description = "Shoe size", example = "9")
35+
val shoeSize: String? = null,
36+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import io.swagger.v3.oas.annotations.media.Schema
5+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataValue
6+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.mapper.mapRefDataDescription
7+
import java.time.LocalDate
8+
9+
@JsonInclude(JsonInclude.Include.NON_NULL)
10+
@Schema(description = "Profile Code Type")
11+
data class ProfileCodeType(
12+
@Schema(description = "Profile Type", required = true)
13+
val type: String,
14+
15+
@Schema(description = "Category", required = true)
16+
val category: String,
17+
18+
@Schema(description = "Description")
19+
val description: String? = null,
20+
21+
@Schema(description = "Mandatory Flag", required = true)
22+
val mandatory: Boolean = false,
23+
24+
@Schema(description = "Update Allowed Flag", required = true)
25+
val updateAllowed: Boolean = true,
26+
27+
@Schema(description = "Code Value Type", required = true)
28+
val codeValueType: String,
29+
30+
@Schema(description = "Active Flag", required = true)
31+
val active: Boolean = true,
32+
33+
@Schema(description = "Expiry Date")
34+
val endDate: LocalDate? = null,
35+
36+
@Schema(description = "List Sequence", required = true)
37+
val listSequence: Int = 99,
38+
)
39+
40+
@JsonInclude(JsonInclude.Include.NON_NULL)
41+
@Schema(description = "Profile Code ID")
42+
data class ProfileCodeId(
43+
@Schema(description = "Type", required = true)
44+
val type: ProfileCodeType,
45+
46+
@Schema(description = "Code", required = true)
47+
val code: String,
48+
)
49+
50+
@JsonInclude(JsonInclude.Include.NON_NULL)
51+
@Schema(description = "Profile Code")
52+
data class ProfileCode(
53+
@Schema(description = "ID", required = true)
54+
val id: ProfileCodeId,
55+
56+
@Schema(description = "Description")
57+
val description: String? = null,
58+
59+
@Schema(description = "Update Allowed Flag", required = true)
60+
val updateAllowed: Boolean = true,
61+
62+
@Schema(description = "Active Flag", required = true)
63+
val active: Boolean = true,
64+
65+
@Schema(description = "Expiry Date")
66+
val endDate: LocalDate? = null,
67+
68+
@Schema(description = "List Sequence", required = true)
69+
val listSequence: Int = 99,
70+
) {
71+
fun toReferenceDataValue(): ReferenceDataValue = ReferenceDataValue(
72+
id = "${id.type.type}_${id.code}",
73+
code = id.code,
74+
description = mapRefDataDescription(id.type.type, id.code, description),
75+
)
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL
5+
import io.swagger.v3.oas.annotations.media.Schema
6+
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataValue
7+
8+
@JsonInclude(NON_NULL)
9+
@Schema(description = "Physical Attributes")
10+
data class PhysicalAttributesDto(
11+
@Schema(description = "Height (in centimetres)")
12+
val height: Int? = null,
13+
14+
@Schema(description = "Weight (in kilograms)")
15+
val weight: Int? = null,
16+
17+
@Schema(description = "Hair type or colour")
18+
val hair: ReferenceDataValue? = null,
19+
20+
@Schema(description = "Facial hair type")
21+
val facialHair: ReferenceDataValue? = null,
22+
23+
@Schema(description = "Face shape")
24+
val face: ReferenceDataValue? = null,
25+
26+
@Schema(description = "Build")
27+
val build: ReferenceDataValue? = null,
28+
29+
@Schema(description = "Left eye colour")
30+
val leftEyeColour: ReferenceDataValue? = null,
31+
32+
@Schema(description = "Right eye colour")
33+
val rightEyeColour: ReferenceDataValue? = null,
34+
35+
@Schema(description = "Shoe size", example = "9")
36+
val shoeSize: String? = null,
37+
)

src/main/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/corepersonrecord/resource/CorePersonRecordV1Resource.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import uk.gov.justice.digital.hmpps.personintegrationapi.common.annotation.Valid
2828
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.MilitaryRecordRequest
2929
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.PhysicalAttributesRequest
3030
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality
31-
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.PhysicalAttributes
3231
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataCodeDto
3332
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.CorePersonRecordRoleConstants
3433
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response.MilitaryRecordDto
34+
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response.PhysicalAttributesDto
3535
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CorePersonRecordV1UpdateRequestDto
3636
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.service.CorePersonRecordService
3737
import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
@@ -393,7 +393,7 @@ class CorePersonRecordV1Resource(
393393
ApiResponse(
394394
responseCode = "200",
395395
description = "Physical attributes found",
396-
content = [Content(schema = Schema(implementation = PhysicalAttributes::class))],
396+
content = [Content(schema = Schema(implementation = PhysicalAttributesDto::class))],
397397
),
398398
ApiResponse(
399399
responseCode = "401",
@@ -420,7 +420,7 @@ class CorePersonRecordV1Resource(
420420
@PreAuthorize("hasAnyRole('${CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_ROLE}', '${CorePersonRecordRoleConstants.CORE_PERSON_RECORD_READ_WRITE_ROLE}')")
421421
fun getPhysicalAttributes(
422422
@RequestParam(required = true) @Valid @ValidPrisonerNumber prisonerNumber: String,
423-
): ResponseEntity<PhysicalAttributes> = corePersonRecordService.getPhysicalAttributes(prisonerNumber)
423+
): ResponseEntity<PhysicalAttributesDto> = corePersonRecordService.getPhysicalAttributes(prisonerNumber)
424424

425425
@PutMapping("/physical-attributes")
426426
@ResponseStatus(HttpStatus.NO_CONTENT)

src/main/kotlin/uk/gov/justice/digital/hmpps/personintegrationapi/corepersonrecord/service/CorePersonRecordService.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.P
99
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthCountry
1010
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateBirthPlace
1111
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.request.UpdateNationality
12-
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.response.PhysicalAttributes
1312
import uk.gov.justice.digital.hmpps.personintegrationapi.common.dto.ReferenceDataCodeDto
1413
import uk.gov.justice.digital.hmpps.personintegrationapi.common.mapper.mapRefDataDescription
1514
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response.MilitaryRecordDto
15+
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.response.PhysicalAttributesDto
1616
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.BirthplaceUpdateDto
1717
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CorePersonRecordV1UpdateRequestDto
1818
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request.CountryOfBirthUpdateDto
@@ -106,19 +106,22 @@ class CorePersonRecordService(
106106

107107
fun updateNationality(prisonerNumber: String, updateNationality: UpdateNationality): ResponseEntity<Void> = prisonApiClient.updateNationalityForWorkingName(prisonerNumber, updateNationality)
108108

109-
fun getPhysicalAttributes(prisonerNumber: String): ResponseEntity<PhysicalAttributes> {
109+
fun getPhysicalAttributes(prisonerNumber: String): ResponseEntity<PhysicalAttributesDto> {
110110
val response = prisonApiClient.getPhysicalAttributes(prisonerNumber)
111111

112112
if (!response.statusCode.is2xxSuccessful) return ResponseEntity.status(response.statusCode).build()
113113

114114
val mappedResponse = response.body?.let { body ->
115-
body.copy(
116-
hairDescription = body.hairCode?.let { mapRefDataDescription(HAIR, it, body.hairDescription) },
117-
facialHairDescription = body.facialHairCode?.let { mapRefDataDescription(FACIAL_HAIR, it, body.facialHairDescription) },
118-
faceDescription = body.faceCode?.let { mapRefDataDescription(FACE, it, body.faceDescription) },
119-
buildDescription = body.buildCode?.let { mapRefDataDescription(BUILD, it, body.buildDescription) },
120-
leftEyeColourDescription = body.leftEyeColourCode?.let { mapRefDataDescription(L_EYE_C, it, body.leftEyeColourDescription) },
121-
rightEyeColourDescription = body.rightEyeColourCode?.let { mapRefDataDescription(R_EYE_C, it, body.rightEyeColourDescription) },
115+
PhysicalAttributesDto(
116+
height = body.height,
117+
weight = body.weight,
118+
hair = body.hair?.toReferenceDataValue(),
119+
facialHair = body.facialHair?.toReferenceDataValue(),
120+
face = body.face?.toReferenceDataValue(),
121+
build = body.build?.toReferenceDataValue(),
122+
leftEyeColour = body.leftEyeColour?.toReferenceDataValue(),
123+
rightEyeColour = body.rightEyeColour?.toReferenceDataValue(),
124+
shoeSize = body.shoeSize,
122125
)
123126
}
124127

0 commit comments

Comments
 (0)