Skip to content
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

feat(#59) : 약 복용률 계산하는 메서드 추가, #61

Merged
merged 6 commits into from
May 20, 2024
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
@@ -1,9 +1,11 @@
package com.remind.api.connection.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "의사/센터가 환자의 관계 요청 응답을 수락하는 응답 객체")
public record AcceptConnectionResponseDto(
@Schema(description = "요청을 수락하며 생긴 커넥션의 아이디")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.remind.api.connection.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "환자 -> 의사/센터 관계 요청하는 응답 객체")
public record RequestConnectionResponseDto(
@Schema(description = "요청을 보내며 생긴 요청 row의 아이디")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.remind.api.member.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record CautionPatientDto(
@Schema(description = "환자 아이디")
Long memberId,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/remind/api/member/dto/PatientDto.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.remind.api.member.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;

@Builder
//@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public record PatientDto(
@Schema(description = "멤버 아이디")
Long memberId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.remind.api.member.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.api.member.dto.CautionPatientDto;
import com.remind.api.member.dto.PatientDto;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -8,6 +9,7 @@
import java.util.List;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "주의가 필요한 환자 목록 리스트")
public record CautionPatientsResponseDto(
@Schema(description = "관리중인 환자 목록 리스트")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.remind.api.member.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class KakaoGetMemberInfoResponse {
@JsonProperty("id")
private Long authId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.remind.api.member.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.core.domain.member.enums.RolesType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record KakaoLoginResponse(@Schema(description = "Remind의 리프레시 토큰")
String refreshToken,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.remind.api.member.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.core.domain.member.enums.RolesType;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record OnboardingResponseDto(Long userId, RolesType rolesType) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.remind.api.member.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.api.member.dto.PatientDto;
import com.remind.api.mood.dto.MoodChartDto;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -8,6 +9,7 @@
import java.util.List;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record PatientsResponseDto(
@Schema(description = "관리중인 환자 목록 리스트")
List<PatientDto> patientDtos,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.remind.api.member.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "토큰 응답 model")
public record TokenResponseDto(
@Schema(description = "access token 유효 기간: 30분")
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/com/remind/api/member/service/PatientService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.remind.api.member.service;

import com.remind.api.takingMedicine.service.TakingMedicineService;
import com.remind.core.domain.common.enums.MemberErrorCode;
import com.remind.core.domain.common.enums.PresciptionErrorCode;
import com.remind.core.domain.common.exception.MemberException;
import com.remind.core.domain.common.exception.PrescriptionException;
import com.remind.core.domain.member.Member;
import com.remind.core.domain.member.Patient;
import com.remind.core.domain.member.repository.MemberRepository;
import com.remind.core.domain.member.repository.PatientRepository;
import com.remind.core.domain.prescription.Prescription;
import com.remind.core.domain.prescription.repository.PrescriptionRepository;
import com.remind.core.domain.takingMedicine.enums.MedicinesType;
import com.remind.core.domain.takingMedicine.repository.TakingMedicineRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PatientService {
private final PrescriptionRepository prescriptionRepository;
private final PatientRepository patientRepository;
private final MemberRepository memberRepository;
private final TakingMedicineRepository takingMedicineRepository;

/**
* 환자id와 처방id로 복용률을 업데이트 하는 메서드
* @param patientId
* @param prescriptionId
*/
public void updateTakingMedicineRate(Long patientId, Long prescriptionId) {
Prescription prescription = prescriptionRepository.findById(prescriptionId)
.orElseThrow(() -> new PrescriptionException(PresciptionErrorCode.PRESCRIPTION_NOT_FOUND));
Patient patient = patientRepository.findById(patientId)
.orElseThrow(() -> new MemberException(MemberErrorCode.MEMBER_NOT_FOUND));
Member member = memberRepository.findById(patientId)
.orElseThrow(() -> new MemberException(MemberErrorCode.MEMBER_NOT_FOUND));

// 아침, 점심, 저녁 약 실제 복용 횟수
int realBreakfastCount = takingMedicineRepository.countByPrescriptionIdAndMedicinesType(prescriptionId, MedicinesType.BREAKFAST);
int realLunchCount = takingMedicineRepository.countByPrescriptionIdAndMedicinesType(prescriptionId, MedicinesType.LUNCH);
int realDinnerCount = takingMedicineRepository.countByPrescriptionIdAndMedicinesType(prescriptionId, MedicinesType.DINNER);
int realCount = realBreakfastCount + realLunchCount + realDinnerCount;

// 아침, 점심, 저녁에 먹어야하는 복용 횟수
int totalBreakfastCount = prescription.getBreakfastImportance() == 0 ? 0 : (prescription.getPeriod() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

비즈니스 로직이 만약 아침 약이 없으면 중요도 0으로 들어가고 아침 약이 존재하면 중요도가 무조건 >=1인거야?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어어 맞아. 중요도를 입력하지 않으면 해당 약이 없는거!

int totalLunchCount = prescription.getLunchImportance() == 0 ? 0 : (prescription.getPeriod() + 1);
int totalDinnerCount = prescription.getDinnerImportance() == 0 ? 0 : (prescription.getPeriod() + 1);
int totalCount = totalBreakfastCount + totalLunchCount + totalDinnerCount;


Double breakfastRate = totalBreakfastCount == 0 ? 0 : (double)realBreakfastCount / totalBreakfastCount;
Double lunchRate = totalLunchCount == 0 ? 0 : (double)realLunchCount / totalLunchCount;
Double dinnerRate = totalDinnerCount == 0 ? 0 : (double) realDinnerCount / totalDinnerCount;
Double totalRate = totalCount == 0 ? 0 : (double)realCount / totalCount;


patient.updateTakingMedicineRate(breakfastRate, lunchRate, dinnerRate, totalRate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ResponseEntity<ApiSuccessResponse<CreatePrescriptionResponseDto>> createP

@Operation(
summary = "특정 환자의 현재 처방 정보를 조회하는 api",
description = "특정 환자의 현재 처방 정보을 조회하는 api\n 내 처방 정보를 조회하고 싶으면 memberId = 0\n 오늘 해당되는 정보가 없으면 null "
description = "특정 환자의 현재 처방 정보을 조회하는 api<br> 내 처방 정보를 조회하고 싶으면 memberId = 0<br>\n 오늘 해당되는 정보가 없으면 null "
)
@GetMapping("")
public ResponseEntity<ApiSuccessResponse<PrescriptionInfoResponseDto>> getPrescriptionInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.remind.api.prescription.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import lombok.Builder;

import java.time.LocalDate;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "약 복용 정보 업데이트 응답 객체")
public record CreatePrescriptionResponseDto(
Long PrescriptionId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.remind.api.prescription.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.core.domain.takingMedicine.enums.MedicinesType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand All @@ -8,9 +9,12 @@
import java.util.List;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "환자 관리 페이지에서 약 처방 정보")
public record PrescriptionInfoResponseDto(

@Schema(description = "값 존재 여부")
Boolean isExist,
@Schema(description = "환자의 이름")
String name,
@Schema(description = "처방 날짜")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ public PrescriptionInfoResponseDto getPrescriptionInfo(UserDetailsImpl userDetai

//등록된 약이 없음!
if (optionalPrescription.isEmpty()) {
return null;
return PrescriptionInfoResponseDto.builder()
.isExist(false)

.build();
}

//오늘 필요한 약 처방 정보
Prescription prescription = optionalPrescription.get();

return PrescriptionInfoResponseDto.builder()
.isExist(true)
.name(patient.getName())
.prescriptionDate(prescription.getPrescriptionDate())
.period(prescription.getPeriod())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.remind.api.takingMedicine.dto.response.CreateTakingMedicineResponse;
import com.remind.api.takingMedicine.dto.response.DailyTakingMedicineInfoResponse;
import com.remind.api.takingMedicine.dto.response.MonthlyTakingMedicineInfoResponse;
import com.remind.api.takingMedicine.dto.response.TakingMedicineRateResponse;
import com.remind.api.takingMedicine.service.TakingMedicineService;
import com.remind.core.domain.common.response.ApiSuccessResponse;
import com.remind.core.domain.takingMedicine.enums.MedicinesType;
Expand All @@ -27,8 +28,9 @@
public class TakingMedicineController {
private final TakingMedicineService takingMedicineService;
@Operation(
summary = "memberId(), 날짜로 해당 날짜의 약 복용 정보를 조회하는 api",
description = "memberId(), 날짜로 해당 날짜의 약 복용 정보를 조회하는 api\n 나의 정보를 조회하는 경우에는 memberId = 0 을 넣어주세요"
summary = "memberId(), 날짜로 해당 날짜의 약 복용 정보를 조회하는 api\n",
description = "나의 정보를 조회하는 경우에는 memberId = 0 을 넣어주세요.\n" +
"date는 string으로, YYYY-MM-DD 형식으로 주세요."
)
@GetMapping("/daily")
public ResponseEntity<ApiSuccessResponse<DailyTakingMedicineInfoResponse>> getDailyTakingMedicineInfo(
Expand All @@ -40,8 +42,12 @@ public ResponseEntity<ApiSuccessResponse<DailyTakingMedicineInfoResponse>> getDa
}

@Operation(
summary = "memberId, year, month로 월 단위 약 복용 정보를 조회하는 api",
description = "memberId, year, month로 월 단위 약 복용 정보를 조회하는 api\n 나의 정보를 조회하는 경우에는 memberId = 0 을 넣어주세요\""
summary = "memberId, year, month로 월 단위 약 복용 정보를 조회하는 api <br> g",
description = "해당 월 1일부터 말일까지의 데이터가 모두 들어있습니다. <br> g" +
" needMedicine : false인 경우, 약을 복용하지 않아도 되는 날 <br> g" +
" 나의 정보를 조회하는 경우에는 memberId = 0 을 넣어주세요 <br> g" +
"taking level : 약 복용 정도(0 : 미복용, 1 : 부분 복용, 2 : 모두 복용 완료 <br> g" +
"taking count : 그 날 약 복용 횟수, 단순 참고용"
)
@GetMapping("/monthly")
public ResponseEntity<ApiSuccessResponse<MonthlyTakingMedicineInfoResponse>> getMonthlyTakingMedicineInfo(
Expand All @@ -56,7 +62,8 @@ public ResponseEntity<ApiSuccessResponse<MonthlyTakingMedicineInfoResponse>> get

@Operation(
summary = "특정 날짜의 약 복용 정보를 등록하는 api",
description = "특정 날짜의 약 복용 정보를 등록하는 api"
description = "medicineType : BREAKFAST, LUNCH, DINNER, ETC <br> " +
"약을 복용하지 않은 경우 notTakingReason을 비워두거나 빈 문자열"
)
@PostMapping("")
public ResponseEntity<ApiSuccessResponse<CreateTakingMedicineResponse>> createTakingMedicine(
Expand All @@ -66,4 +73,16 @@ public ResponseEntity<ApiSuccessResponse<CreateTakingMedicineResponse>> createTa
return ResponseEntity.ok(new ApiSuccessResponse<>(takingMedicineService.createTakingMedicine(userDetails, req)));
}


@Operation(
summary = "특정 멤버의 약 복용률을 반환하는 api",
description = "특정 날짜의 약 복용률 조회 api <br> 나의 정보를 조회하는 경우에는 memberId = 0 을 넣어주세요\""
)
@GetMapping("/rate")
public ResponseEntity<ApiSuccessResponse<TakingMedicineRateResponse>> getTakingMedicineRate(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam Long memberId
) {
return ResponseEntity.ok(new ApiSuccessResponse<>(takingMedicineService.getTakingMedicineRate(userDetails, memberId)));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.remind.api.takingMedicine.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.core.domain.takingMedicine.enums.MedicinesType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand All @@ -8,6 +9,7 @@
import java.time.format.DateTimeFormatter;

@Schema(description = "특정 날짜의 약 복용 정보를 반환할 dto")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
public record DailyTakingMedicineDto(
@Schema(description = "해당 약 처방 정보의 식별 id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.remind.api.takingMedicine.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.core.domain.takingMedicine.enums.MedicinesType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand All @@ -8,6 +9,7 @@
import java.time.LocalTime;

@Schema(description = "특정 월에서 일 단위의 약 복용 정보를 반환할 dto")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
public record MonthlyTakingMedicineDto(

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@Builder
public record CreateTakingMedicineRequest(
MedicinesType medicinesType,
LocalDate date,
Boolean isTaking,
String notTakingReason

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.remind.api.takingMedicine.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record CreateTakingMedicineResponse(
String notTakingReason,
Boolean isTaking
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.remind.api.takingMedicine.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.remind.api.takingMedicine.dto.DailyTakingMedicineDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.util.List;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "특정 날짜의 약 복용 정보를 반환할 dto list")
public record DailyTakingMedicineInfoResponse(
@Schema(description = "특정 날짜의 약 복용 정보를 반환할 리스트")
Expand Down
Loading
Loading