Repository navigation
[Refactor] OCR 처방일 파싱 및 약물노트 그룹화 기준 전환 - #62
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
처방일 키워드("처방일", "처방일자", "처방전발행일") 우선 파싱
없으면 조제일("조제일", "조제일자") fallback
YYYY.MM.DD / YYYY-MM-DD / YYYY년MM월DD일 포맷 지원
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
OcrResultConverter — prescriptionDate 파라미터 추가 OcrCommandService — parseResult.prescriptionDate() 전달 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
startDate → prescriptionDate (처방일 파싱 성공 시 처방일, 실패 시 startDate fallback) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
prescriptionDate가 있으면 우선 사용, 없으면 startDate fallback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughOCR 파서에 처방일/조제일 추출 로직이 추가되고, 추출된 날짜가 OcrParseResult → OcrResultConverter/OcrCommandService → OcrResultResponse 경로로 전달된다. 약물노트 그룹화 기준(MedicationQueryService, MedicationNoteGroupResponse)이 startDate에서 prescriptionDate(없으면 startDate 폴백)로 변경되었다. ChangesOCR 처방일 파싱 및 약물노트 그룹화 기준 전환
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant OcrParser
participant OcrParseResult
participant OcrCommandService
participant OcrResultConverter
participant OcrResultResponse
OcrParser->>OcrParser: extractPrescriptionDate(rawText)
OcrParser->>OcrParseResult: new OcrParseResult(rawText, parsedDrugs, prescriptionDate)
OcrCommandService->>OcrResultConverter: toResponse(saved, parsedDrugs, parseResult.prescriptionDate())
OcrResultConverter->>OcrResultResponse: new OcrResultResponse(..., prescriptionDate)
sequenceDiagram
participant MedicationQueryService
participant Medication
participant MedicationNoteGroupResponse
MedicationQueryService->>Medication: getPrescriptionDate()
alt prescriptionDate 존재
MedicationQueryService->>MedicationQueryService: groupDate = prescriptionDate
else null
MedicationQueryService->>Medication: getStartDate()
MedicationQueryService->>MedicationQueryService: groupDate = startDate
end
MedicationQueryService->>MedicationNoteGroupResponse: build(groupDate, ...)
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/java/com/piuda/callcare/domain/ocrresult/service/OcrParser.java (1)
475-495: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
catch (Exception e)대신 구체적인 예외 타입 사용을 권장합니다.
tryExtractDate에서catch (Exception e)는 의도치 않은 런타임 예외까지 포괄합니다.LocalDate.of()에서 발생하는DateTimeException과Integer.parseInt()에서 발생할 수 있는NumberFormatException만 명시적으로 처리하는 것이 예외 처리 의도를 더 명확히 전달합니다.As per coding guidelines,
src/main/java/**/*.java경로는 예외 처리에 중점을 둡니다.♻️ 제안하는 리팩터링
private LocalDate tryExtractDate(Pattern pattern, String text) { Matcher m = pattern.matcher(text); if (!m.find()) return null; try { int year = Integer.parseInt(m.group(1)); int month = Integer.parseInt(m.group(2).trim()); int day = Integer.parseInt(m.group(3).trim()); return LocalDate.of(year, month, day); - } catch (Exception e) { + } catch (DateTimeException | NumberFormatException e) { return null; } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/piuda/callcare/domain/ocrresult/service/OcrParser.java` around lines 475 - 495, In OcrParser.tryExtractDate, replace the broad catch block with specific handling for the exceptions actually expected from parsing and date construction. Update the exception handling around Integer.parseInt and LocalDate.of to catch only NumberFormatException and DateTimeException, keeping the fallback behavior in extractPrescriptionDate unchanged.Source: Path instructions
src/main/java/com/piuda/callcare/domain/medication/service/query/MedicationQueryService.java (1)
66-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick wingroupDate 계산을 헬퍼로 묶고, 목록 조회 설명도 실제 기준에 맞춰주세요
MedicationQueryService.toNoteGroupResponses()안에서prescriptionDate -> startDate폴백이 두 번 반복됩니다. 헬퍼로 분리하면 DRY해지고, 이후 기준 변경도 한 곳만 수정하면 됩니다.MedicationController.getNoteList()의@Operation설명은 현재 동작과 다릅니다."복용 시작일 + 병원 기준"대신"처방일 + 병원 기준 (fallback: 복용 시작일)"로 맞춰주세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/piuda/callcare/domain/medication/service/query/MedicationQueryService.java` around lines 66 - 77, The groupDate fallback logic is duplicated in MedicationQueryService.toNoteGroupResponses(), so extract the prescriptionDate-or-startDate selection into a helper and reuse it both when building the grouping key and when creating MedicationNoteGroupResponse. Also update MedicationController.getNoteList()’s `@Operation` description to match the actual grouping rule, changing it from “복용 시작일 + 병원 기준” to “처방일 + 병원 기준 (fallback: 복용 시작일)”.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@src/main/java/com/piuda/callcare/domain/medication/service/query/MedicationQueryService.java`:
- Around line 66-77: The groupDate fallback logic is duplicated in
MedicationQueryService.toNoteGroupResponses(), so extract the
prescriptionDate-or-startDate selection into a helper and reuse it both when
building the grouping key and when creating MedicationNoteGroupResponse. Also
update MedicationController.getNoteList()’s `@Operation` description to match the
actual grouping rule, changing it from “복용 시작일 + 병원 기준” to “처방일 + 병원 기준
(fallback: 복용 시작일)”.
In `@src/main/java/com/piuda/callcare/domain/ocrresult/service/OcrParser.java`:
- Around line 475-495: In OcrParser.tryExtractDate, replace the broad catch
block with specific handling for the exceptions actually expected from parsing
and date construction. Update the exception handling around Integer.parseInt and
LocalDate.of to catch only NumberFormatException and DateTimeException, keeping
the fallback behavior in extractPrescriptionDate unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cad03e55-2a45-4f68-beb8-cd6afd550e16
📒 Files selected for processing (7)
src/main/java/com/piuda/callcare/domain/medication/dto/response/MedicationNoteGroupResponse.javasrc/main/java/com/piuda/callcare/domain/medication/service/query/MedicationQueryService.javasrc/main/java/com/piuda/callcare/domain/ocrresult/converter/OcrResultConverter.javasrc/main/java/com/piuda/callcare/domain/ocrresult/dto/OcrParseResult.javasrc/main/java/com/piuda/callcare/domain/ocrresult/dto/response/OcrResultResponse.javasrc/main/java/com/piuda/callcare/domain/ocrresult/service/OcrParser.javasrc/main/java/com/piuda/callcare/domain/ocrresult/service/command/OcrCommandService.java
🔍️ 작업 내용
✨ 상세 설명
OCR 처방일 파싱
OcrParser—extractPrescriptionDate()추가, "처방일/처방일자/처방전발행일" 우선 파싱, 없으면 "조제일/조제일자" fallback (정규식 기반,YYYY년MM월DD일/YYYY.MM.DD/YYYY-MM-DD등 포맷 대응)OcrParseResult—LocalDate prescriptionDate필드 추가 (파싱 실패 시 null)OcrResultResponse— 프론트에 처방일 반환OcrResultConverter/OcrCommandService— 파싱된 처방일을 응답까지 연결약물노트 그룹화 기준 전환
startDate단독 → **prescriptionDate ?? startDate**로 변경 (처방일 파싱 성공 시 우선 사용, 실패 시 복용 시작일 fallback)MedicationNoteGroupResponse필드명startDate→prescriptionDate로 변경, 스키마 설명 업데이트MedicationQueryService.toNoteGroupResponses()그룹핑 로직 반영🛠️ 추후 리팩토링 및 고도화 계획
📸 스크린샷 (선택)
💬 리뷰 요구사항
startDate로 fallback되는 케이스가 실제로 얼마나 되는지, 이 fallback 전략이 적절한지 확인 부탁Summary by CodeRabbit