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 @@ -2,6 +2,7 @@

import com.piuda.callcare.domain.medication.dto.request.MedicationCreateRequest;
import com.piuda.callcare.domain.medication.dto.request.MedicationUpdateRequest;
import com.piuda.callcare.domain.medication.dto.response.MedicationDetailResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationGroupItemResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationNoteGroupResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationResponse;
Expand Down Expand Up @@ -39,6 +40,18 @@ public ResponseEntity<ApiResponse<List<MedicationResponse>>> registerBatch(
return ResponseUtils.created(medicationCommandService.registerBatch(userId, requests));
}

@Operation(
summary = "약 단건 상세 조회",
description = "약물노트에서 '재등록' 버튼 클릭 시 호출합니다. 약 이름·복용법·병원명·처방일·메모 등 등록 화면 프리필에 필요한 모든 필드를 반환합니다. 반환된 값을 그대로 POST /api/medications/batch에 담아 재등록하면 됩니다."
)
@GetMapping("/{medicationId}")
public ResponseEntity<ApiResponse<MedicationDetailResponse>> getDetail(
@AuthenticationPrincipal Long userId,
@PathVariable Long medicationId
) {
return ResponseUtils.ok(medicationQueryService.getDetail(userId, medicationId));
}

@Operation(summary = "약물노트 그룹 상세 조회", description = "병원+처방일 그룹 카드 클릭 시 해당 그룹의 약 리스트와 각 약의 메모를 반환합니다. hospitalName/prescriptionDate 미전달 시 null 그룹 조회.")
@GetMapping("/group")
public ResponseEntity<ApiResponse<List<MedicationGroupItemResponse>>> getGroup(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piuda.callcare.domain.medication.converter;

import com.piuda.callcare.domain.medication.dto.response.MedicationDetailResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationGroupItemResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationNoteItemResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationResponse;
Expand Down Expand Up @@ -31,6 +32,28 @@ public MedicationGroupItemResponse toGroupItemResponse(Medication medication) {
);
}

// Medication → MedicationDetailResponse (약 단건 상세 — 재등록 화면 프리필용)
public MedicationDetailResponse toDetailResponse(Medication medication) {
return new MedicationDetailResponse(
medication.getId(),
medication.getDrugName(),
medication.getDrugNickname(),
medication.getDrugType(),
medication.getImageUrl(),
medication.getDosagePerTime(),
medication.getTimesPerDay(),
medication.getTotalDays(),
medication.getStartDate(),
medication.getEndDate(),
medication.getPrescriptionDate(),
medication.getHospitalName(),
medication.getUsageStorageInfo(),
medication.getMemo(),
medication.getIsActive(),
medication.getDrugInfo() != null ? medication.getDrugInfo().getId() : null
);
}

// Medication → MedicationNoteItemResponse (약물노트 리스트 카드 내 약 단건)
public MedicationNoteItemResponse toNoteItemResponse(Medication medication) {
return new MedicationNoteItemResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.piuda.callcare.domain.medication.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDate;

@Schema(description = "약 단건 상세 응답 — 재등록 화면 프리필용")
public record MedicationDetailResponse(

@Schema(description = "약 ID")
Long medicationId,

@Schema(description = "약 이름")
String drugName,

@Schema(description = "약 별명 (없으면 null)")
String drugNickname,

@Schema(description = "약 종류 (없으면 null)")
String drugType,

@Schema(description = "약 이미지 URL (없으면 null)")
String imageUrl,

@Schema(description = "1회 복용량 (예: 1정, 5ml)")
String dosagePerTime,

@Schema(description = "1일 복용 횟수")
Integer timesPerDay,

@Schema(description = "총 복용 일수 (없으면 null)")
Integer totalDays,

@Schema(description = "복용 시작일")
LocalDate startDate,

@Schema(description = "복용 종료일 (없으면 null)")
LocalDate endDate,

@Schema(description = "처방 날짜 (없으면 null)")
LocalDate prescriptionDate,

@Schema(description = "병원명 (없으면 null)")
String hospitalName,

@Schema(description = "복용법 + 보관법 — DrugInfo 연결 시에만 채워짐, 없으면 null")
String usageStorageInfo,

@Schema(description = "사용자 자유 입력 메모 (없으면 null)")
String memo,

@Schema(description = "복용 중 여부 — false면 종료된 약")
Boolean isActive,

@Schema(description = "연결된 DrugInfo ID — 재등록 시 drugInfoId 필드에 그대로 사용 (없으면 null)")
Long drugInfoId
) {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.piuda.callcare.domain.medication.service.query;

import com.piuda.callcare.domain.medication.converter.MedicationConverter;
import com.piuda.callcare.domain.medication.dto.response.MedicationDetailResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationGroupItemResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationNoteGroupResponse;
import com.piuda.callcare.domain.medication.dto.response.MedicationNoteItemResponse;
Expand Down Expand Up @@ -28,6 +29,16 @@ public class MedicationQueryService {
private final SeniorRepository seniorRepository;
private final MedicationConverter medicationConverter;

// 약 단건 상세 조회 — 재등록 화면 프리필용
public MedicationDetailResponse getDetail(Long userId, Long medicationId) {
if (userId == null) throw new CallCareException(ErrorCode.FORBIDDEN);
Medication medication = medicationRepository.findById(medicationId)
.orElseThrow(() -> new CallCareException(ErrorCode.MEDICATION_NOT_FOUND));
seniorRepository.findByIdAndUser_Id(medication.getSenior().getId(), userId)
.orElseThrow(() -> new CallCareException(ErrorCode.FORBIDDEN));
return medicationConverter.toDetailResponse(medication);
}

// 병원+처방일 그룹의 약 상세 목록 조회
public List<MedicationGroupItemResponse> getGroup(Long userId, Long seniorId, String hospitalName, LocalDate prescriptionDate) {
if (userId == null) {
Expand Down