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); }