Skip to content

Commit

Permalink
Fix: 상담 저장시 consultId를 return하도록 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
suminiee authored May 6, 2024
2 parents 3cb3138 + 47a0484 commit a323a95
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.medicare.neulpeum.Repository;

import com.medicare.neulpeum.controller.ConsultController;
import com.medicare.neulpeum.domain.entity.ConsultContentInfo;
import com.medicare.neulpeum.domain.entity.PatientInfo;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.medicare.neulpeum.Repository;

import com.medicare.neulpeum.domain.entity.ProvidedDrugInfo;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ProvidedDrugRepository extends JpaRepository<ProvidedDrugInfo, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.medicare.neulpeum.dto;


import com.medicare.neulpeum.domain.entity.ConsultContentInfo;
import com.medicare.neulpeum.domain.entity.DrugInfo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class ProvidedDrugRequestDto {
private ConsultContentInfo consultId;
private DrugInfo drugId;
private Long providedAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public interface ConsultService {
void save(ConsultRequestDto consultRequestDto);
Long save(ConsultRequestDto consultRequestDto);

List<ConsultResponseDto> findAllByPatientId(PatientInfo patientId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,41 @@ public class ConsultServiceImpl implements ConsultService{


@Override
public void save(ConsultRequestDto consultReq) {
public Long save(ConsultRequestDto consultReq) {
try {
PatientInfo patientId = patientRepository.findById(consultReq.getPatientId()).get();
PatientInfo patientId = patientRepository.findById(consultReq.getPatientId()).orElse(null);
if (patientId == null) {
throw new IllegalArgumentException("환자를 찾을 수 없습니다. ID: " + consultReq.getPatientId());
}

ConsultContentInfo consultContentInfo = ConsultContentInfo.builder()
.patientId(patientId)
.providerName(consultReq.getProviderName())
.takingDrug(consultReq.getTakingDrug())
.consultContent(consultReq.getConsultContent())
.build();
consultRepository.save(consultContentInfo);

ConsultContentInfo savedConsult = consultRepository.save(consultContentInfo);
// log.info("*********************" + savedConsult.getConsultId());
return savedConsult.getConsultId();

} catch (Exception e) {
log.error("ConsultContentInfo 저장 중 오류 발생: {}", e.getMessage());
throw new RuntimeException("ConsultContentInfo 저장 중 오류 발생: " + e.getMessage());
}

// try {
// PatientInfo patientId = patientRepository.findById(consultReq.getPatientId()).get();
// ConsultContentInfo consultContentInfo = ConsultContentInfo.builder()
// .patientId(patientId)
// .providerName(consultReq.getProviderName())
// .takingDrug(consultReq.getTakingDrug())
// .consultContent(consultReq.getConsultContent())
// .build();
// consultRepository.save(consultContentInfo);
// } catch (Exception e) {
// log.error("ConsultContentInfo 저장 중 오류 발생: {}", e.getMessage());
// }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.medicare.neulpeum.Repository.DrugRepository;
import com.medicare.neulpeum.domain.entity.DrugInfo;
import com.medicare.neulpeum.dto.DrugNameAndAmountResponseDto;
import com.medicare.neulpeum.dto.DrugRequestDto;
import com.medicare.neulpeum.dto.DrugResponseDto;
import com.medicare.neulpeum.dto.DrugUpdateRequestDto;
import com.medicare.neulpeum.dto.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -102,6 +99,9 @@ public void updateUsedDrug(List<DrugUpdateRequestDto> drugUpdateRequestDtoList)
if (usableAmount >= remainingAmount) {
drug.setUsableAmount(usableAmount - remainingAmount);
drugRepository.save(drug);

//ProvidedDrugInfo 테이블에 저장

break;
} else {
//사용 가능한 개수가 사용하려는 개수보다 적은 경우 약 재고를 0개로 변경 후
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.medicare.neulpeum.service;

import com.medicare.neulpeum.dto.ProvidedDrugRequestDto;

public interface ProvidedDrugService {
void saveProvidedDrug(ProvidedDrugRequestDto providedDrugRequestDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.medicare.neulpeum.service;

import com.medicare.neulpeum.dto.ProvidedDrugRequestDto;

public class ProvidedDrugServiceImpl implements ProvidedDrugService{
@Override
public void saveProvidedDrug(ProvidedDrugRequestDto providedDrugRequestDto) {
}
}

0 comments on commit a323a95

Please sign in to comment.