Skip to content

Commit 4e3ea4a

Browse files
fix(payments): add org-wide GET /api/payments/plans and /api/payments/ledger
The workspace Payments tab lists plans and ledger entries at the practice level, but the controller only exposed patient-scoped routes (/plans/patient/{id}, /ledger/patient/{id}). GET /api/payments/plans hit the POST-only /plans mapping (500 "method GET not supported") and GET /api/payments/ledger had no handler (500 "no endpoint"). Add org-wide list endpoints backed by new repository + service methods so the tab loads. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent aee244e commit 4e3ea4a

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/main/java/org/ciyex/ehr/payment/controller/PaymentController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ public ResponseEntity<ApiResponse<Map<String, Object>>> stats() {
191191

192192
// ── Payment Plans ────────────────────────────────────────────────────
193193

194+
@GetMapping("/plans")
195+
public ResponseEntity<ApiResponse<List<PaymentPlanDto>>> listAllPlans() {
196+
try {
197+
var plans = service.listAllPlans();
198+
return ResponseEntity.ok(ApiResponse.ok("Payment plans retrieved", plans));
199+
} catch (Exception e) {
200+
log.error("Failed to list payment plans", e);
201+
return ResponseEntity.ok(ApiResponse.error("Failed: " + e.getMessage()));
202+
}
203+
}
204+
194205
@GetMapping("/plans/patient/{patientId}")
195206
public ResponseEntity<ApiResponse<List<PaymentPlanDto>>> listPlans(@PathVariable Long patientId) {
196207
try {
@@ -245,6 +256,17 @@ public ResponseEntity<ApiResponse<PaymentPlanDto>> cancelPlan(@PathVariable Long
245256

246257
// ── Ledger ───────────────────────────────────────────────────────────
247258

259+
@GetMapping("/ledger")
260+
public ResponseEntity<ApiResponse<List<PatientLedgerDto>>> getAllLedger() {
261+
try {
262+
var ledger = service.getAllLedger();
263+
return ResponseEntity.ok(ApiResponse.ok("Ledger retrieved", ledger));
264+
} catch (Exception e) {
265+
log.error("Failed to get ledger", e);
266+
return ResponseEntity.ok(ApiResponse.error("Failed: " + e.getMessage()));
267+
}
268+
}
269+
248270
@GetMapping("/ledger/patient/{patientId}")
249271
public ResponseEntity<ApiResponse<List<PatientLedgerDto>>> getLedger(@PathVariable Long patientId) {
250272
try {

src/main/java/org/ciyex/ehr/payment/repository/PatientLedgerRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public interface PatientLedgerRepository extends JpaRepository<PatientLedger, Lo
1111

1212
List<PatientLedger> findByOrgAliasAndPatientIdOrderByCreatedAtDesc(String orgAlias, Long patientId);
1313

14+
List<PatientLedger> findByOrgAliasOrderByCreatedAtDesc(String orgAlias);
15+
1416
@Query("SELECT COALESCE(SUM(l.amount),0) FROM PatientLedger l WHERE l.orgAlias = :org AND l.patientId = :pid")
1517
BigDecimal sumByPatient(@Param("org") String orgAlias, @Param("pid") Long patientId);
1618

src/main/java/org/ciyex/ehr/payment/repository/PaymentPlanRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public interface PaymentPlanRepository extends JpaRepository<PaymentPlan, Long>
99

1010
List<PaymentPlan> findByOrgAliasAndPatientIdOrderByCreatedAtDesc(String orgAlias, Long patientId);
1111

12+
List<PaymentPlan> findByOrgAliasOrderByCreatedAtDesc(String orgAlias);
13+
1214
Optional<PaymentPlan> findByIdAndOrgAlias(Long id, String orgAlias);
1315

1416
List<PaymentPlan> findByOrgAliasAndStatusOrderByNextPaymentDateAsc(String orgAlias, String status);

src/main/java/org/ciyex/ehr/payment/service/PaymentService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ public List<PaymentPlanDto> listPlans(Long patientId) {
320320
.stream().map(this::toPlanDto).toList();
321321
}
322322

323+
@Transactional(readOnly = true)
324+
public List<PaymentPlanDto> listAllPlans() {
325+
return planRepo.findByOrgAliasOrderByCreatedAtDesc(orgAlias())
326+
.stream().map(this::toPlanDto).toList();
327+
}
328+
323329
@Transactional
324330
public PaymentPlanDto updatePlan(Long id, PaymentPlanDto dto) {
325331
var plan = planRepo.findByIdAndOrgAlias(id, orgAlias())
@@ -356,6 +362,12 @@ public List<PatientLedgerDto> getLedger(Long patientId) {
356362
.stream().map(this::toLedgerDto).toList();
357363
}
358364

365+
@Transactional(readOnly = true)
366+
public List<PatientLedgerDto> getAllLedger() {
367+
return ledgerRepo.findByOrgAliasOrderByCreatedAtDesc(orgAlias())
368+
.stream().map(this::toLedgerDto).toList();
369+
}
370+
359371
@Transactional(readOnly = true)
360372
public BigDecimal getBalance(Long patientId) {
361373
return ledgerRepo.sumByPatient(orgAlias(), patientId);

0 commit comments

Comments
 (0)