69 lines
2.8 KiB
Plaintext
69 lines
2.8 KiB
Plaintext
package com.healthcare.ohctech.service.impl;
|
|
|
|
import com.healthcare.ohctech.dto.AilmentSystemDto;
|
|
import com.healthcare.ohctech.entity.AilmentSystem;
|
|
import com.healthcare.ohctech.repository.AilmentSystemRepo;
|
|
import com.healthcare.ohctech.service.AilmentSystemService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Optional;
|
|
|
|
@Service
|
|
public class AilmentSystemServiceImpl implements AilmentSystemService {
|
|
|
|
@Autowired
|
|
private AilmentSystemRepo ailmentSystemRepo;
|
|
|
|
@Override
|
|
public AilmentSystem getAilmentSystemById(Long ailmentSysId) {
|
|
return ailmentSystemRepo.findById(ailmentSysId)
|
|
.orElseThrow(() -> new RuntimeException("Ailment System not found for ID: " + ailmentSysId));
|
|
}
|
|
|
|
@Override
|
|
public Page<AilmentSystem> getAllAilmentSystems(Pageable pageable) {
|
|
return ailmentSystemRepo.findAll(pageable);
|
|
}
|
|
|
|
@Override
|
|
public void addAilmentSystem(AilmentSystemDto ailmentSystemDto) {
|
|
AilmentSystem ailmentSystem = new AilmentSystem();
|
|
ailmentSystem.setAilmentSysName(ailmentSystemDto.ailmentSysName());
|
|
ailmentSystem.setAilmentSysCode(ailmentSystemDto.ailmentSysCode());
|
|
ailmentSystem.setAilmentSysDesc(ailmentSystemDto.ailmentSysDesc());
|
|
|
|
ailmentSystemRepo.save(ailmentSystem);
|
|
}
|
|
|
|
@Override
|
|
public void updateAilmentSystem(AilmentSystemDto ailmentSystemDto) {
|
|
Long ailmentSysId = ailmentSystemDto.id();
|
|
Optional<AilmentSystem> optionalAilmentSystem = ailmentSystemRepo.findById(ailmentSysId);
|
|
if (optionalAilmentSystem.isPresent()) {
|
|
AilmentSystem ailmentSystem = optionalAilmentSystem.get();
|
|
ailmentSystem.setAilmentSysName(ailmentSystemDto.ailmentSysName());
|
|
ailmentSystem.setAilmentSysCode(ailmentSystemDto.ailmentSysCode());
|
|
ailmentSystem.setAilmentSysDesc(ailmentSystemDto.ailmentSysDesc());
|
|
|
|
ailmentSystemRepo.save(ailmentSystem);
|
|
} else {
|
|
throw new RuntimeException("Ailment System not found for ID: " + ailmentSysId);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void deleteAilmentSystem(Long ailmentSysId) {
|
|
Optional<AilmentSystem> optionalAilmentSystem = ailmentSystemRepo.findById(ailmentSysId);
|
|
if (optionalAilmentSystem.isPresent()) {
|
|
AilmentSystem ailmentSystem = optionalAilmentSystem.get();
|
|
ailmentSystemRepo.delete(ailmentSystem);
|
|
} else {
|
|
throw new RuntimeException("Ailment System not found for ID: " + ailmentSysId);
|
|
}
|
|
}
|
|
}
|