generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement logic to obtain out of service bed information
Amended existing findOutOfServiceBedIds query, renamed to findOutOfServiceBedIdForDates to fetch by optionally provided date Incorporate oosbeds into the premise day summary
- Loading branch information
1 parent
599f545
commit f263939
Showing
13 changed files
with
538 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...stice/digital/hmpps/approvedpremisesapi/service/cas1/Cas1OutOfServiceBedSummaryService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package uk.gov.justice.digital.hmpps.approvedpremisesapi.service.cas1 | ||
|
||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Cas1OutOfServiceBedSortField | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.SortDirection | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Temporality | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.Cas1OutOfServiceBedEntity | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.results.CasResult | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.util.PageCriteria | ||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
@Service | ||
class Cas1OutOfServiceBedSummaryService( | ||
private val cas1PremisesService: Cas1PremisesService, | ||
private val cas1OutOfServiceBedService: Cas1OutOfServiceBedService, | ||
) { | ||
|
||
fun getOutOfServiceBedSummaries( | ||
premisesId: UUID, | ||
apAreaId: UUID, | ||
date: LocalDate, | ||
): CasResult<List<Cas1OutOfServiceBedEntity>> { | ||
if (cas1PremisesService.findPremiseById(premisesId) == null) return CasResult.NotFound("premises", premisesId.toString()) | ||
|
||
val (outOfServiceBeds) = cas1OutOfServiceBedService.getOutOfServiceBedsForDate( | ||
temporality = setOf(Temporality.current), | ||
premisesId = premisesId, | ||
date = date, | ||
apAreaId = apAreaId, | ||
pageCriteria = PageCriteria( | ||
sortBy = Cas1OutOfServiceBedSortField.startDate, | ||
sortDirection = SortDirection.asc, | ||
page = 1, | ||
perPage = 1000, | ||
), | ||
) | ||
|
||
return CasResult.Success( | ||
outOfServiceBeds, | ||
) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...gital/hmpps/approvedpremisesapi/transformer/cas1/Cas1OutOfServiceBedSummaryTransformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package uk.gov.justice.digital.hmpps.approvedpremisesapi.transformer.cas1 | ||
|
||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Cas1OutOfServiceBedSummary | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.api.model.Cas1SpaceCharacteristic | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.Cas1OutOfServiceBedEntity | ||
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.CharacteristicEntity | ||
|
||
@Component | ||
class Cas1OutOfServiceBedSummaryTransformer( | ||
private val cas1OutOfServiceBedReasonTransformer: Cas1OutOfServiceBedReasonTransformer, | ||
) { | ||
|
||
fun toCas1OutOfServiceBedSummary(jpa: Cas1OutOfServiceBedEntity) = Cas1OutOfServiceBedSummary( | ||
id = jpa.id, | ||
roomName = jpa.bed.room.name, | ||
startDate = jpa.startDate, | ||
endDate = jpa.endDate, | ||
reason = cas1OutOfServiceBedReasonTransformer.transformJpaToApi(jpa.reason), | ||
characteristics = jpa.bed.room.characteristics.map { it.asCas1SpaceCharacteristic() }, | ||
) | ||
|
||
private fun CharacteristicEntity.asCas1SpaceCharacteristic() = | ||
Cas1SpaceCharacteristic.entries.first { it.value == this.propertyName } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.