95 lines
4.5 KiB
Plaintext
95 lines
4.5 KiB
Plaintext
package com.healthcare.ohctech.service.impl;
|
|
|
|
import com.healthcare.ohctech.dto.BioMedicalWasteDto;
|
|
import com.healthcare.ohctech.entity.BioMedicalWaste;
|
|
import com.healthcare.ohctech.entity.DisposalAgency;
|
|
import com.healthcare.ohctech.entity.OhcType;
|
|
import com.healthcare.ohctech.repository.BioMedicalWasteRepo;
|
|
import com.healthcare.ohctech.repository.DisposalAgencyRepo;
|
|
import com.healthcare.ohctech.repository.OhcTypeRepo;
|
|
import com.healthcare.ohctech.service.BioMedicalWasteService;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@Service
|
|
public class BioMedicalWasteServiceImpl implements BioMedicalWasteService {
|
|
|
|
private final BioMedicalWasteRepo bioMedicalWasteRepo;
|
|
private final DisposalAgencyRepo disposalAgencyRepo;
|
|
private final OhcTypeRepo ohcTypeRepo;
|
|
|
|
public BioMedicalWasteServiceImpl(BioMedicalWasteRepo bioMedicalWasteRepo,
|
|
DisposalAgencyRepo disposalAgencyRepo,
|
|
OhcTypeRepo ohcTypeRepo) {
|
|
this.bioMedicalWasteRepo = bioMedicalWasteRepo;
|
|
this.disposalAgencyRepo = disposalAgencyRepo;
|
|
this.ohcTypeRepo = ohcTypeRepo;
|
|
}
|
|
|
|
@Override
|
|
public BioMedicalWaste getBioMedicalWasteById(Long id) {
|
|
return bioMedicalWasteRepo.findById(id)
|
|
.orElseThrow(() -> new RuntimeException("BioMedicalWaste not found for ID: " + id));
|
|
}
|
|
|
|
@Override
|
|
public Page<BioMedicalWaste> getAllBioMedicalWastes(Pageable pageable) {
|
|
return bioMedicalWasteRepo.findAll(pageable);
|
|
}
|
|
|
|
@Override
|
|
public void addBioMedicalWaste(BioMedicalWasteDto bioMedicalWasteDto, Long userId) {
|
|
BioMedicalWaste bioMedicalWaste = convertToEntity(new BioMedicalWaste(), bioMedicalWasteDto);
|
|
bioMedicalWaste.setModifiedBy(userId);
|
|
bioMedicalWasteRepo.save(bioMedicalWaste);
|
|
}
|
|
|
|
@Override
|
|
public void updateBioMedicalWaste(BioMedicalWasteDto bioMedicalWasteDto, Long userId) {
|
|
Long id = bioMedicalWasteDto.id();
|
|
BioMedicalWaste bioMedicalWaste = bioMedicalWasteRepo.findById(id)
|
|
.orElseThrow(() -> new RuntimeException("BioMedicalWaste not found for ID: " + id));
|
|
|
|
convertToEntity(bioMedicalWaste, bioMedicalWasteDto);
|
|
bioMedicalWaste.setModifiedBy(userId);
|
|
bioMedicalWasteRepo.save(bioMedicalWaste);
|
|
}
|
|
|
|
@Override
|
|
public void deleteBioMedicalWaste(Long id) {
|
|
BioMedicalWaste bioMedicalWaste = bioMedicalWasteRepo.findById(id)
|
|
.orElseThrow(() -> new RuntimeException("BioMedicalWaste not found for ID: " + id));
|
|
bioMedicalWasteRepo.delete(bioMedicalWaste);
|
|
}
|
|
|
|
private BioMedicalWaste convertToEntity(BioMedicalWaste bioMedicalWaste, BioMedicalWasteDto bioMedicalWasteDto) {
|
|
bioMedicalWaste.setWasteGenDate(bioMedicalWasteDto.wasteGenDate());
|
|
bioMedicalWaste.setPlantYellowQty(bioMedicalWasteDto.plantYellowQty());
|
|
bioMedicalWaste.setYellowBags(bioMedicalWasteDto.yellowBags());
|
|
bioMedicalWaste.setPlantWhiteQty(bioMedicalWasteDto.plantWhiteQty());
|
|
bioMedicalWaste.setWhiteBags(bioMedicalWasteDto.whiteBags());
|
|
bioMedicalWaste.setPlantBlueQty(bioMedicalWasteDto.plantBlueQty());
|
|
bioMedicalWaste.setBlueBags(bioMedicalWasteDto.blueBags());
|
|
bioMedicalWaste.setPlantRedQty(bioMedicalWasteDto.plantRedQty());
|
|
bioMedicalWaste.setRedBags(bioMedicalWasteDto.redBags());
|
|
bioMedicalWaste.setForwardStatus(bioMedicalWasteDto.forwardStatus());
|
|
bioMedicalWaste.setCollectedBy(bioMedicalWasteDto.collectedBy());
|
|
bioMedicalWaste.setVehicleNo(bioMedicalWasteDto.vehicleNo());
|
|
bioMedicalWaste.setChallanNo(bioMedicalWasteDto.challanNo());
|
|
bioMedicalWaste.setApprovedBy(bioMedicalWasteDto.approvedBy());
|
|
bioMedicalWaste.setSurveillanceBy(bioMedicalWasteDto.surveillanceBy());
|
|
bioMedicalWaste.setApprovalStatus(bioMedicalWasteDto.approvalStatus());
|
|
|
|
DisposalAgency disposalAgency = disposalAgencyRepo.findById(bioMedicalWasteDto.disposalAgencyId())
|
|
.orElseThrow(() -> new RuntimeException("Disposal Agency not found for ID: " + bioMedicalWasteDto.disposalAgencyId()));
|
|
bioMedicalWaste.setDisposalAgency(disposalAgency);
|
|
|
|
OhcType ohcType = ohcTypeRepo.findById(bioMedicalWasteDto.ohcTypeId())
|
|
.orElseThrow(() -> new RuntimeException("OHC Type not found for ID: " + bioMedicalWasteDto.ohcTypeId()));
|
|
bioMedicalWaste.setOhcType(ohcType);
|
|
|
|
return bioMedicalWaste;
|
|
}
|
|
}
|