В моем коде есть обновление API пациента. Когда запускается прямой вызов API, он обновляет и вставляет зашифрованные данные в базу данных, НО если я вызываю метод update Patient напрямую, то он не шифрует записи пациентов, а только обновляет и сохраняет их в БД без шифрование.
Вот логика дешифрования шифрования в моем коде:
Код: Выделить всё
@Slf4j
@Component
public class PatientListener extends EntityEventListener {
@PrePersist
public void encryptRecord(Patient pc) {
if (pc.getIsEncrypted()) {
return;
}
EncryptDecryptService encryptDecryptService = determineEncryptionKey(pc);
pc.setFirstName(encryptDecryptService.encryptString(pc.getFirstName()));
...
pc.setIsEncrypted(true);
}
@PreUpdate
public void encryptRecordAfterUpdate(Patient pc) {
if (pc.getIsEncrypted()) {
return;
}
EncryptDecryptService encryptDecryptService = determineEncryptionKey(pc);
pc.setFirstName(encryptDecryptService.encryptString(pc.getFirstName()));
...
pc.setIsEncrypted(true);
}
@PostLoad
public void decryptRecord(Patient pc) {
if (pc.getIsDecrypted()) {
return;
}
EncryptDecryptService encryptDecryptService = determineEncryptionKey(pc);
pc.setFirstName(encryptDecryptService.decryptString(pc.getFirstName()));
...
pc.setIsDecrypted(true);
}
}
Код: Выделить всё
@Override
public CustomResponse updatePatient(RequestDto RequestDto) {
CustomResponse customResponse = new CustomResponse();
try {
.
.
.
if(Boolean.TRUE.equals(isMrgPatientUpdated.getFirst())) {
.
.
if(Boolean.TRUE.equals(isMrgPatientUpdated.getSecond())){
log.info("demographics are updated for the mrgPatientId : "+patientMrgId);
mrg2PatientService.updateByMrgDemographics(patientMrgId,RequestDto ,mrgId);
}
customResponse.setStatus(1);
}
} catch (Exception e) {
log.error("An unexpected error occurred: " + e.getMessage(), e);
throw new PatientServiceException("An unexpected error occurred: " + e.getMessage());
}
return customResponse;
}
Код: Выделить всё
@Override
public String updateByMrgPatient(UpdatePatientRequestDto updatePatientRequest, String patientId, int orgId, UpdateInitiatedTypeEnum updateInitiatedTypeEnum, String updateFrom){
List response = validateMandatoryFields(updatePatientRequest, orgId,updateFrom);
if (!response.isEmpty()) {
throw new PatientManagementException("Validation failed, fields missing or invalid: " + response);
}
Patient patient = patientRepo.findByPatientId(patientId);
if (Patient == null) {
throw new PatientManagementException("Patient with the given patientId is not found.");
}
updatePatient(updatePatientRequest, patient,orgId);
publishEvent(patient,updateInitiatedTypeEnum);
return patient.getPatientId();
}
@Transactional
private void updatePatient(UpdatePatientRequestDto updatePatientRequest, Patient patient, int orgId) {
boolean result = patientDetailsService.updatePatientDetails(updatePatientRequest, oasPatient);
if (result) {
patient.setUpdatedBy(updatePatientRequest.getUserId());
patient.setUpdatedByUserType(updatePatientRequest.getUserType());
}
patientContactService.updateContactDetails(updatePatientRequest, oasPatient, result);
}
Источник: https://stackoverflow.com/questions/781 ... springbbot