public void saveNewPatient(PatientDTO dto, HttpServletRequest request) throws Exception { Patient patient = dto.getPatient(); if (dto.isUpdatePassword()) { if (testPassword(patient.getCred().getPassword()) == false) { dto.setResult(false); dto.setErrorMsg("Insufficient Password"); dto.setReturnCode(RETURN_CODE_INVALID_PASSWORD); return; } String salt = UUID.randomUUID().toString(); patient.getCred().setSalt(salt); String encodedPassword = OneWayPasswordEncoder.getInstance().encode(patient.getCred().getPassword(), salt); patient.getCred().setPassword(encodedPassword); } if (dto.isUpdateEmail()) { if (appDAO.checkEmail(DataEncryptor.encrypt(patient.getCred().getEmail())) == false) { dto.setResult(false); dto.setErrorMsg("Email already in system"); dto.setReturnCode(RETURN_CODE_DUP_EMAIL); return; } } Demographics demo = patient.getDemo(); demo.setEthnicity(appDAO.findEthnicityById(demo.getEthnicity().getId())); demo.setMaritalStatus(appDAO.findMaritalStatusById(demo.getMaritalStatus().getId())); if (demo.getUsState() != null) { demo.setUsState(appDAO.findUSStateById(demo.getUsState().getId())); } demo.setRace(appDAO.findRaceById(demo.getRace().getId())); appDAO.update(patient); decrypt(patient); String patientFullName = patient.getCred().getFirstName() + " " + patient.getCred().getLastName(); String title = patientFullName + ", welcome to the Pleasantville Medical Patient Portal"; String templatePath = context.getRealPath("/WEB-INF/email_templates"); StringTemplateGroup group = new StringTemplateGroup("underwebinf", templatePath, DefaultTemplateLexer.class); StringTemplate st = group.getInstanceOf("portal_signup_confirmation"); String from = Core.mailFrom; st.setAttribute("patient", patientFullName); st.setAttribute("email", patient.getCred().getEmail()); st.setAttribute("phone", patient.getDemo().getPrimaryPhone()); MailHandler handler = new MailHandler(); boolean isHtml = true; String stString = st.toString(); activityLogService.logViewPatient(patient.getId(), null, patient.getId(), "SaveNewPatient"); handler.sendMimeMessage(patient.getCred().getEmail(), from, stString, title, isHtml); }
public void decrypt(Patient patient) throws Exception { log.info("decrypt()"); if (patient == null || patient.isEncrypted() == false) { return; } Credentials cred = patient.getCred(); Demographics demo = patient.getDemo(); if (cred.getUsername() != null) { cred.setUsername(DataEncryptor.decrypt(cred.getUsername())); } if (cred.getMrn() != null) { cred.setMrn(DataEncryptor.decrypt(cred.getMrn())); } if (cred.getFirstName() != null) { cred.setFirstName(DataEncryptor.decrypt(cred.getFirstName())); } if (cred.getMiddleName() != null) { cred.setMiddleName(DataEncryptor.decrypt(cred.getMiddleName())); } if (cred.getLastName() != null) { cred.setLastName(DataEncryptor.decrypt(cred.getLastName())); } if (cred.getAdditionalName() != null) { cred.setAdditionalName(DataEncryptor.decrypt(cred.getAdditionalName())); } if (cred.getEmail() != null) { cred.setEmail(DataEncryptor.decrypt(cred.getEmail())); } if (cred.getGovtId() != null) { cred.setGovtId(DataEncryptor.decrypt(cred.getGovtId())); } if (demo.getPrimaryPhone() != null) { demo.setPrimaryPhone(DataEncryptor.decrypt(demo.getPrimaryPhone())); } if (demo.getSecondaryPhone() != null) { demo.setSecondaryPhone(DataEncryptor.decrypt(demo.getSecondaryPhone())); } if (demo.getStreetAddress1() != null) { demo.setStreetAddress1(DataEncryptor.decrypt(demo.getStreetAddress1())); } if (demo.getStreetAddress2() != null) { demo.setStreetAddress2(DataEncryptor.decrypt(demo.getStreetAddress2())); } if (demo.getCity() != null) { demo.setCity(DataEncryptor.decrypt(demo.getCity())); } if (demo.getPostalCode() != null) { demo.setPostalCode(DataEncryptor.decrypt(demo.getPostalCode())); } if (demo.getEmployer() != null) { demo.setEmployer(DataEncryptor.decrypt(demo.getEmployer())); } if (demo.getSchoolName() != null) { demo.setSchoolName(DataEncryptor.decrypt(demo.getSchoolName())); } patient.setCred(cred); patient.setDemo(demo); patient.setEncrypted(false); }