Skip to content
Merged
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 @@ -63,24 +63,32 @@ public ResponseEntity<ApiResponse<List<MedicationGroupItemResponse>>> getGroup(
return ResponseUtils.ok(medicationQueryService.getGroup(userId, seniorId, hospitalName, prescriptionDate));
}

@Operation(summary = "약물노트 목록 조회", description = "복용 시작일 + 병원 기준으로 그룹화된 약물 목록을 반환합니다.")
@Operation(
summary = "약물노트 목록 조회",
description = "복용 시작일 + 병원 기준으로 그룹화된 약물 목록을 반환합니다. isActive=true(복용중만) / isActive=false(복용완료만) / 미전달(전체)."
)
@GetMapping("/notes")
public ResponseEntity<ApiResponse<List<MedicationNoteGroupResponse>>> getNoteList(
@AuthenticationPrincipal Long userId,
@RequestParam Long seniorId
@RequestParam Long seniorId,
@RequestParam(required = false) Boolean isActive
) {
return ResponseUtils.ok(medicationQueryService.getNoteList(userId, seniorId));
return ResponseUtils.ok(medicationQueryService.getNoteList(userId, seniorId, isActive));
}

@Operation(summary = "약물노트 검색", description = "약 이름/별명/병원명으로 검색합니다. period: 1w·1m·3m·1y (기본 1y)")
@Operation(
summary = "약물노트 검색",
description = "약 이름/별명/병원명으로 검색합니다. period: 1w·1m·3m·1y (기본 1y). isActive=true(복용중만) / isActive=false(복용완료만) / 미전달(전체)."
)
@GetMapping("/notes/search")
public ResponseEntity<ApiResponse<List<MedicationNoteGroupResponse>>> searchNotes(
@AuthenticationPrincipal Long userId,
@RequestParam Long seniorId,
@RequestParam String keyword,
@RequestParam(required = false, defaultValue = "1y") String period
@RequestParam(required = false, defaultValue = "1y") String period,
@RequestParam(required = false) Boolean isActive
) {
return ResponseUtils.ok(medicationQueryService.searchNotes(userId, seniorId, keyword, period));
return ResponseUtils.ok(medicationQueryService.searchNotes(userId, seniorId, keyword, period, isActive));
}

@Operation(summary = "약 수정", description = "null 필드는 변경하지 않습니다. timesPerDay 변경 시 스케줄을 재생성합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,31 @@ public interface MedicationRepository extends JpaRepository<Medication, Long> {
""")
List<Medication> findActiveWithDrugInfoBySeniorId(@Param("seniorId") Long seniorId);

// 약물노트 전체 리스트: 활성/비활성 관계없이 전체 조회 (startDate DESC → hospitalName ASC 정렬)
// 약물노트 전체 리스트: isActive null이면 전체, true/false면 해당 상태만 조회
@Query("""
SELECT m FROM Medication m
WHERE m.senior.id = :seniorId
AND (:isActive IS NULL OR m.isActive = :isActive)
ORDER BY m.startDate DESC, m.hospitalName ASC NULLS LAST
""")
List<Medication> findAllBySeniorId(@Param("seniorId") Long seniorId);
List<Medication> findAllBySeniorId(@Param("seniorId") Long seniorId,
@Param("isActive") Boolean isActive);

// 약물노트 검색: 약 이름/별명/병원명 키워드 + 날짜 범위 필터 (활성/비활성 모두 포함)
// 약물노트 검색: 약 이름/별명/병원명 키워드 + 날짜 범위 + 상태 필터
@Query("""
SELECT m FROM Medication m
WHERE m.senior.id = :seniorId
AND m.startDate >= :fromDate
AND (:isActive IS NULL OR m.isActive = :isActive)
AND (LOWER(m.drugName) LIKE LOWER(CONCAT('%', :keyword, '%'))
OR LOWER(m.drugNickname) LIKE LOWER(CONCAT('%', :keyword, '%'))
OR LOWER(m.hospitalName) LIKE LOWER(CONCAT('%', :keyword, '%')))
ORDER BY m.startDate DESC, m.hospitalName ASC NULLS LAST
""")
List<Medication> searchByKeyword(@Param("seniorId") Long seniorId,
@Param("keyword") String keyword,
@Param("fromDate") LocalDate fromDate);
@Param("fromDate") LocalDate fromDate,
@Param("isActive") Boolean isActive);

// 약물노트 그룹 상세 조회: 병원명 + 처방일 조합이 그룹 키 (둘 다 null 가능)
@Query("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ public List<MedicationGroupItemResponse> getGroup(Long userId, Long seniorId, St
.toList();
}

// 시니어의 약 전체 목록 (활성/비활성 모두) — startDate+병원 기준 그룹화
public List<MedicationNoteGroupResponse> getNoteList(Long userId, Long seniorId) {
// 시니어의 약 목록 — isActive: true(복용중) / false(복용완료) / null(전체)
public List<MedicationNoteGroupResponse> getNoteList(Long userId, Long seniorId, Boolean isActive) {
if (userId == null) throw new CallCareException(ErrorCode.FORBIDDEN);
seniorRepository.findByIdAndUser_Id(seniorId, userId)
.orElseThrow(() -> new CallCareException(ErrorCode.SENIOR_NOT_FOUND));
List<Medication> medications = medicationRepository.findAllBySeniorId(seniorId);
List<Medication> medications = medicationRepository.findAllBySeniorId(seniorId, isActive);
return toNoteGroupResponses(medications);
}

// 약 이름/별명/병원명 키워드 검색 + 기간 필터 (1w·1m·3m·1y)
public List<MedicationNoteGroupResponse> searchNotes(Long userId, Long seniorId, String keyword, String period) {
// 약 이름/별명/병원명 키워드 검색 + 기간 필터 + 상태 필터
public List<MedicationNoteGroupResponse> searchNotes(Long userId, Long seniorId, String keyword, String period, Boolean isActive) {
if (userId == null) throw new CallCareException(ErrorCode.FORBIDDEN);
seniorRepository.findByIdAndUser_Id(seniorId, userId)
.orElseThrow(() -> new CallCareException(ErrorCode.SENIOR_NOT_FOUND));
LocalDate fromDate = resolveFromDate(period);
List<Medication> medications = medicationRepository.searchByKeyword(seniorId, keyword, fromDate);
List<Medication> medications = medicationRepository.searchByKeyword(seniorId, keyword, fromDate, isActive);
return toNoteGroupResponses(medications);
}

Expand Down