150 lines
6.2 KiB
Plaintext
150 lines
6.2 KiB
Plaintext
package com.healthcare.ohctech.service.impl;
|
|
|
|
import com.healthcare.ohctech.dto.PatientDto;
|
|
import com.healthcare.ohctech.entity.*;
|
|
import com.healthcare.ohctech.repository.*;
|
|
import com.healthcare.ohctech.service.PatientService;
|
|
import com.healthcare.ohctech.util.PatientSearchAndSortUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Base64;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@Service
|
|
public class PatientServiceImpl implements PatientService {
|
|
|
|
@Autowired
|
|
private PatientRepo patientRepo;
|
|
@Autowired
|
|
private PatientCategoryRepo patientCategoryRepo;
|
|
@Autowired
|
|
private EmployerContractorRepo employerContractorRepo;
|
|
@Autowired
|
|
private BusinessUnitRepo businessUnitRepo;
|
|
@Autowired
|
|
private DepartmentRepo departmentRepo;
|
|
@Autowired
|
|
private OhcTypeRepo ohcTypeRepo;
|
|
@Autowired
|
|
private DesignationRepo designationRepo;
|
|
@Autowired
|
|
private BloodGroupRepo bloodGroupRepo;
|
|
|
|
@Override
|
|
public Patient getPatientById(Long patientId) {
|
|
return patientRepo.findById(patientId)
|
|
.orElseThrow(() -> new RuntimeException("Patient not found for ID: " + patientId));
|
|
}
|
|
|
|
@Override
|
|
public Page<Patient> getAllPatients(Pageable pageable) {
|
|
return patientRepo.findAll(pageable);
|
|
}
|
|
|
|
@Override
|
|
public void addPatient(PatientDto patientDto,Long userId) {
|
|
Patient patient = mapDtoToEntity(new Patient(), patientDto);
|
|
patient.setModifiedBy(userId);
|
|
patientRepo.save(patient);
|
|
}
|
|
|
|
@Override
|
|
public void updatePatient(PatientDto patientDto,Long userId) {
|
|
Long patientId = patientDto.id();
|
|
Patient patient = patientRepo.findById(patientId)
|
|
.orElseThrow(() -> new RuntimeException("Patient not found for ID: " + patientId));
|
|
|
|
patient.setModifiedBy(userId);
|
|
mapDtoToEntity(patient, patientDto);
|
|
patientRepo.save(patient);
|
|
}
|
|
|
|
@Override
|
|
public void deletePatient(Long patientId) {
|
|
Patient patient = patientRepo.findById(patientId)
|
|
.orElseThrow(() -> new RuntimeException("Patient not found for ID: " + patientId));
|
|
patientRepo.delete(patient);
|
|
}
|
|
|
|
private Patient mapDtoToEntity(Patient patient, PatientDto patientDto) {
|
|
patient.setPatientName(patientDto.patientName());
|
|
// patient.setPhoto(patientDto.photo());
|
|
patient.setEmpPhoto(patientDto.empPhoto());
|
|
patient.setEmpImageType(patientDto.empImageType());
|
|
patient.setFatherName(patientDto.fatherName());
|
|
patient.setEmpCode(patientDto.empCode());
|
|
patient.setDob(patientDto.dob());
|
|
patient.setGender(patientDto.gender());
|
|
patient.setLeavingDate(patientDto.leavingDate());
|
|
patient.setAadharNo(patientDto.aadharNo());
|
|
patient.setPrimaryPhone(patientDto.primaryPhone());
|
|
patient.setPersonalPhone(patientDto.personalPhone());
|
|
patient.setEmailId(patientDto.emailId());
|
|
patient.setStatus(patientDto.status());
|
|
patient.setIsOHCStaff(patientDto.isOHCStaff());
|
|
patient.setIdentity(patientDto.identity());
|
|
patient.setVillage(patientDto.village());
|
|
patient.setPost(patientDto.post());
|
|
patient.setDistrict(patientDto.district());
|
|
patient.setState(patientDto.state());
|
|
// patient.setPs(patientDto.ps());
|
|
// patient.setTehsil(patientDto.tehsil());
|
|
// patient.setPinCode(patientDto.pinCode());
|
|
// patient.setPrimaryContactPerson(patientDto.primaryContactPerson());
|
|
// patient.setPrimaryContactNo(patientDto.primaryContactNo());
|
|
// patient.setSecondaryContactPerson(patientDto.secondaryContactPerson());
|
|
// patient.setSecondaryContactNo(patientDto.secondaryContactNo());
|
|
|
|
if (patientDto.patientCatId() != null) {
|
|
PatientCategory patientCategory = patientCategoryRepo.findById(patientDto.patientCatId())
|
|
.orElseThrow(() -> new RuntimeException("Patient Category not found for ID: " + patientDto.patientCatId()));
|
|
patient.setPatientCategory(patientCategory);
|
|
}
|
|
|
|
if (patientDto.employerContractorId() != null) {
|
|
EmployerContractor employerContractor = employerContractorRepo.findById(patientDto.employerContractorId())
|
|
.orElseThrow(() -> new RuntimeException("Employer Contractor not found for ID: " + patientDto.employerContractorId()));
|
|
patient.setEmployerContractor(employerContractor);
|
|
}
|
|
|
|
if (patientDto.buId() != null) {
|
|
BusinessUnit businessUnit = businessUnitRepo.findById(patientDto.buId())
|
|
.orElseThrow(() -> new RuntimeException("Business Unit not found for ID: " + patientDto.buId()));
|
|
patient.setBusinessUnit(businessUnit);
|
|
}
|
|
|
|
if (patientDto.deptId() != null) {
|
|
Department department = departmentRepo.findById(patientDto.deptId())
|
|
.orElseThrow(() -> new RuntimeException("Department not found for ID: " + patientDto.deptId()));
|
|
patient.setDepartment(department);
|
|
}
|
|
|
|
if (patientDto.designationId() != null) {
|
|
Designation designation = designationRepo.findById(patientDto.designationId())
|
|
.orElseThrow(() -> new RuntimeException("Designation not found for ID: " + patientDto.designationId()));
|
|
patient.setDesignation(designation);
|
|
}
|
|
|
|
if (patientDto.ohcTypeId() != null) {
|
|
OhcType ohcType = ohcTypeRepo.findById(patientDto.ohcTypeId())
|
|
.orElseThrow(() -> new RuntimeException("OHC Type not found for ID: " + patientDto.ohcTypeId()));
|
|
patient.setOhcType(ohcType);
|
|
}
|
|
|
|
if (patientDto.bloodGroupId() != null) {
|
|
BloodGroup bloodGroup = bloodGroupRepo.findById(patientDto.bloodGroupId())
|
|
.orElseThrow(() -> new RuntimeException("OHC Type not found for ID: " + patientDto.bloodGroupId()));
|
|
patient.setBloodGroup(bloodGroup);
|
|
}
|
|
|
|
return patient;
|
|
}
|
|
|
|
}
|