-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT] 의료기록 CRUD api 구현 #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
a43cd91
624507a
2d50ef3
e463ce0
b098975
7e5aac7
51072a1
72e2764
feb9427
becc69d
743ba8d
8451132
a7c4f2c
2b19eff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.onebridge.ouch.apiPayload.code.error; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum VisitHistoryErrorCode implements ErrorCode { | ||
|
|
||
| VISIT_HISTORY_NOT_FOUND(HttpStatus.NOT_FOUND, "MEDICAL-RECORD401", "의료기록이 존재하지 않습니다."), | ||
| HOSPITAL_NOT_FOUND(HttpStatus.NOT_FOUND, "MEDICAL-RECORD402", "입력한 병원이 존재하지 않습니다."), | ||
| DEPARTMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "MEDICAL-RECORD403", "입력한 진료 과가 존재하지 않습니다."), | ||
| VISIT_HISTORY_USER_NOT_MATCH(HttpStatus.FORBIDDEN, "MEDICAL-RECORD404", "해당 사용자의 의료기록이 아닙니다."), | ||
| ; | ||
|
|
||
| private final HttpStatus httpStatus; | ||
| private final String code; | ||
| private final String message; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.onebridge.ouch.controller.visitHistory; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.onebridge.ouch.apiPayload.ApiResponse; | ||
| import com.onebridge.ouch.dto.visitHistory.request.VisitHistoryCreateRequest; | ||
| import com.onebridge.ouch.dto.visitHistory.request.VisitHistoryUpdateRequest; | ||
| import com.onebridge.ouch.dto.visitHistory.response.DateAndHospital; | ||
| import com.onebridge.ouch.dto.visitHistory.response.GetVisitHistoryResponse; | ||
| import com.onebridge.ouch.security.authorization.UserId; | ||
| import com.onebridge.ouch.service.visitHistory.VisitHistoryService; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Tag(name = "의료기록 API", description = "의료기록 API 입니다.") | ||
| @RestController | ||
| @RequestMapping("/medical-record") | ||
| @RequiredArgsConstructor | ||
| public class VisitHistoryController { | ||
|
|
||
| private final VisitHistoryService visitHistoryService; | ||
|
|
||
| // 의료기록 생성 | ||
| @Operation(summary = "의료기록 생성 API", description = "의료기록을 생성 API 입니다.") | ||
| @PostMapping | ||
| public ResponseEntity<ApiResponse<Void>> createVisitHistory( | ||
| @RequestBody @Valid VisitHistoryCreateRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| visitHistoryService.createVisitHistory(request, userId); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
|
|
||
| // 특정 의료기록 조회 | ||
| @Operation(summary = "의료기록 조회 API", description = "의료기록을 조회 API 입니다.") | ||
| @GetMapping("/{medicalRecordId}") | ||
| public ResponseEntity<ApiResponse<GetVisitHistoryResponse>> getVisitHistory(@PathVariable Long medicalRecordId, | ||
| @UserId Long userId | ||
| ) { | ||
| GetVisitHistoryResponse response = visitHistoryService.getVisitHistory(medicalRecordId, userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
|
||
| // 특정 사용자의 모든 의료기록 조회 (의료기록 메인 페이지용) | ||
| @Operation(summary = "특정 사용자의 모든 의료기록 조회 API", description = "특정 사용자의 모든 의료기록 조회 API 입니다.") | ||
| @GetMapping | ||
| public ResponseEntity<ApiResponse<List<DateAndHospital>>> getUsersAllVisitHistory( | ||
| @UserId Long userId | ||
| ) { | ||
| List<DateAndHospital> list = visitHistoryService.getUsersAllVisitHistory(userId); | ||
| return ResponseEntity.ok(ApiResponse.success(list)); | ||
| } | ||
|
|
||
| //특정 의료기록 삭제 | ||
| @Operation(summary = "의료기록 삭제 API", description = "의료기록을 삭제 API 입니다.") | ||
| @DeleteMapping("/{medicalRecordId}") | ||
| public ResponseEntity<ApiResponse<Void>> deleteVisitHistory(@PathVariable Long medicalRecordId, | ||
| @UserId Long userId | ||
| ) { | ||
| visitHistoryService.deleteVisitHistory(medicalRecordId, userId); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
|
|
||
| //특정 의료기록 수정 | ||
| @Operation(summary = "의료기록 수정 API", description = "의료기록을 수정 API 입니다.") | ||
| @PutMapping("/{medicalRecordId}") | ||
| public ResponseEntity<ApiResponse<Void>> updateVisitHistory( | ||
| @RequestBody @Valid VisitHistoryUpdateRequest request, | ||
| @PathVariable Long medicalRecordId, | ||
| @UserId Long userId | ||
| ) { | ||
| visitHistoryService.updateVisitHistory(request, medicalRecordId, userId); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메소드명에 2를 넣지말고 직관적으로 구분되게 지으면 좋겠습니다.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확인했습니다 :) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.onebridge.ouch.converter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.onebridge.ouch.domain.Summary; | ||
| import com.onebridge.ouch.domain.User; | ||
| import com.onebridge.ouch.domain.mapping.VisitHistory; | ||
| import com.onebridge.ouch.dto.visitHistory.request.VisitHistoryCreateRequest; | ||
| import com.onebridge.ouch.dto.visitHistory.request.VisitHistoryUpdateRequest; | ||
| import com.onebridge.ouch.dto.visitHistory.response.DateAndHospital; | ||
| import com.onebridge.ouch.dto.visitHistory.response.GetVisitHistoryResponse; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
|
|
||
| @Component | ||
| @AllArgsConstructor | ||
| public class VisitHistoryConverter { | ||
|
|
||
| public GetVisitHistoryResponse visitHistoryToGetVisitHistoryResponse(VisitHistory visitHistory) { | ||
| return new GetVisitHistoryResponse(visitHistory.getId(), visitHistory.getVisitDate().toString(), | ||
| visitHistory.getHospital(), | ||
| visitHistory.getDepartment(), visitHistory.getSymptoms(), | ||
| visitHistory.getSummary().getContents_summary()); | ||
| } | ||
|
|
||
| public List<DateAndHospital> visitHistoryToGetUsersAllVisitHistoryResponse(List<VisitHistory> visitHistory) { | ||
| List<DateAndHospital> list = new ArrayList<>(); | ||
| for (VisitHistory history : visitHistory) { | ||
| list.add(new DateAndHospital(history.getId(), history.getUpdatedAt().toString(), | ||
| history.getHospital())); | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| public VisitHistory visitHistoryCreateRequestToVisitHistory(VisitHistoryCreateRequest request, User user, | ||
| Summary summary) { | ||
| return VisitHistory.builder() | ||
| .user(user) | ||
| .visitDate(request.getVisitDate()) | ||
| .hospital(request.getVisitingHospital()) | ||
| .department(request.getMedicalSubject()) | ||
| .symptoms(request.getSymptoms()) | ||
| .summary(summary) | ||
| .build(); | ||
| } | ||
|
|
||
| public VisitHistory visitHistoryUpdateRequestToVisitHistory(VisitHistory visitHistory, | ||
| VisitHistoryUpdateRequest request, Summary summary) { | ||
| return visitHistory.toBuilder() | ||
| .visitDate(request.getVisitDate()) | ||
| .hospital(request.getVisitingHospital()) | ||
| .department(request.getMedicalSubject()) | ||
| .symptoms(request.getSymptoms()) | ||
| .summary(summary) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.onebridge.ouch.dto.visitHistory.request; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class VisitHistoryCreateRequest { | ||
|
|
||
| @NotNull(message = "Visit date is required.") | ||
| private LocalDate visitDate; | ||
|
|
||
| @NotBlank(message = "Visiting hospital is required.") | ||
| private String visitingHospital; | ||
|
|
||
| @NotBlank(message = "Medical subject is required.") | ||
| private String medicalSubject; | ||
|
|
||
| @NotBlank(message = "Symptoms are required.") | ||
| private String symptoms; | ||
|
|
||
| @NotBlank(message = "Treatment summary is required.") | ||
| private String treatmentSummary; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.onebridge.ouch.dto.visitHistory.request; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class VisitHistoryUpdateRequest { | ||
|
|
||
| @NotNull(message = "Visit date is required.") | ||
| private LocalDate visitDate; | ||
|
|
||
| @NotBlank(message = "Visiting hospital is required.") | ||
| private String visitingHospital; | ||
|
|
||
| @NotBlank(message = "Medical subject is required.") | ||
| private String medicalSubject; | ||
|
|
||
| @NotBlank(message = "Symptoms are required.") | ||
| private String symptoms; | ||
|
|
||
| @NotBlank(message = "Treatment summary is required.") | ||
| private String treatmentSummary; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.onebridge.ouch.dto.visitHistory.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class DateAndHospital { | ||
|
|
||
| private Long id; | ||
| private String date; | ||
| private String hospital; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.onebridge.ouch.dto.visitHistory.response; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class GetVisitHistoryResponse { | ||
|
|
||
| private Long id; | ||
| private String visitDate; | ||
| private String visitingHospital; | ||
| private String medicalSubject; | ||
| private String symptoms; | ||
| private String treatmentSummary; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.onebridge.ouch.repository.department; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.onebridge.ouch.domain.Department; | ||
|
|
||
| @Repository | ||
| public interface DepartmentRepository extends JpaRepository<Department, Long> { | ||
|
|
||
| Optional<Department> findByName(String name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 메소드 사용하는 곳 없으면 우선 지워주세요.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DepartmentRepository, HospitalRepository 삭제했습니다:) |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.onebridge.ouch.repository.hospital; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.onebridge.ouch.domain.Hospital; | ||
|
|
||
| @Repository | ||
| public interface HospitalRepository extends JpaRepository<Hospital, Long> { | ||
|
|
||
| Optional<Hospital> findByName(String name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 메소드 사용하는 곳 없으면 우선 지워주세요. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.onebridge.ouch.repository.summary; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.onebridge.ouch.domain.Summary; | ||
|
|
||
| @Repository | ||
| public interface SummaryRepository extends JpaRepository<Summary, Long> { | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api URI 전부 restful하게 변경해주세요.
/visit-history로 시작했으면 좋겠습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
figma 보면 medical record 가 의료기록(백엔드 테이블 이름은 visit history), health status 가 건강상태(백엔드 테이블 이름은 medical history)라 사용자나 프론트 개발자가 봤을 때 매칭되면 좋을 거 같아서 이렇게 했는데 바꾸는게 더 좋을까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
도연님 방식으로 바꾸는 거 좋은 것 같습니다. 다만 /create나 이런 건 없에는 게 좋을 것 같아요!