Skip to content

Commit

Permalink
feat: 사용자 생년월일 기반 추천 백신 조회 (#21)
Browse files Browse the repository at this point in the history
* feat: 추천 백신 조회 API

* feat: 사용자 연령 기반 백신 추천
  • Loading branch information
h-beeen authored Mar 22, 2024
1 parent 8b02c12 commit 4e33e5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ enum class AgeCondition(
AGE60TO64("만 60-64세", 0b000010),
AGEOVER65("만 65세 이상", 0b000001);

fun isMatching(value: Int): Boolean {
return value and this.value == this.value
}

companion object {
fun getConditions(value: Int): List<AgeCondition> {
return entries.filter { it.isMatching(value) }
fun getAgeCondition(value: Int): AgeCondition {
return when {
value in 19..29 -> AGE19TO29
value in 30..39 -> AGE30TO39
value in 40..49 -> AGE40TO49
value in 50..59 -> AGE50TO59
value in 60..64 -> AGE60TO64
value >= 65 -> AGEOVER65
else -> AGE19TO29
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.vacgom.backend.member.infrastructure.persistence.MemberRepository
import com.vacgom.backend.search.application.dto.DiseaseSearchResponse
import com.vacgom.backend.search.application.dto.VaccinationSearchResponse
import org.springframework.stereotype.Service
import java.time.LocalDate
import java.util.*


Expand Down Expand Up @@ -51,15 +52,16 @@ class SearchService(
}

fun searchRecommendVaccination(memberId: UUID): List<VaccinationSearchResponse> {
val ageCondition = AgeCondition.AGE19TO29
val member = memberRepository.findById(memberId).orElseThrow {
BusinessException(MemberError.NOT_FOUND)
}

val ageCondition = AgeCondition.getAgeCondition(member.memberDetails?.birthday?.year!!.minus(LocalDate.now().year))
val vaccinations = findAllVaccinations()
val inoculatedDiseaseName = inoculationRepository.findDistinctDiseaseNameByMemberId(memberId).flatMap { it.split("·") }.toSet()
val recommendedVaccinations = vaccinations.filter { vaccination -> !inoculatedDiseaseName.contains(vaccination.vaccineName) }

val healthProfiles = memberRepository.findById(memberId).orElseThrow {
BusinessException(MemberError.NOT_FOUND)
}.healthProfiles.map { it.healthCondition }.toList()
val healthProfiles = member.healthProfiles.map { it.healthCondition }.toList()

val diseases = this.searchDisease(listOf(ageCondition), healthProfiles).filter { response ->
!inoculatedDiseaseName.contains(response.name)
Expand Down

0 comments on commit 4e33e5b

Please sign in to comment.