PageRenderTime 152ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/app/vHMS/Facade/PatientRegistrationService.java

https://gitlab.com/MaheshDe/VHMS
Java | 729 lines | 460 code | 82 blank | 187 comment | 80 complexity | dfbd9397be2eec19d677d80fc0f52f35 MD5 | raw file
  1. /**
  2. *
  3. */
  4. package vHMS.Facade;
  5. import java.lang.reflect.Type;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.regex.Pattern;
  10. import org.apache.commons.beanutils.BeanUtilsBean;
  11. import org.apache.commons.lang3.RandomStringUtils;
  12. import org.modelmapper.ModelMapper;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import vHMS.Core.Models.Appointment;
  17. import vHMS.Core.Models.PatientRegistration;
  18. import vHMS.Core.ViewModels.NotificationViewModel;
  19. import vHMS.Core.ViewModels.PatientRegistrationViewModel;
  20. import vHMS.Core.ViewModels.Response;
  21. import vHMS.Core.ViewModels.ResponseViewModel;
  22. import Base.Data.IGenericMongoDao;
  23. import Base.Utilities.CommonUtils;
  24. import Base.Utilities.HelperUtil;
  25. import Base.Utilities.NullAwareBeanUtilsBean;
  26. import com.google.common.reflect.TypeToken;
  27. import com.google.gson.Gson;
  28. import com.google.gson.GsonBuilder;
  29. import com.mongodb.BasicDBList;
  30. import com.mongodb.BasicDBObject;
  31. import com.mongodb.DBObject;
  32. /**
  33. * The PatientRegistrationService is an implementation for
  34. * IPatientRegistrationService containing methods like create, update delete
  35. * etc.. related to patient management, and can be implemented by other classes.
  36. *
  37. * @author DivyaP
  38. * @version 1.0
  39. * @since 2015-07-17
  40. */
  41. @Service
  42. @Transactional
  43. public class PatientRegistrationService implements IPatientRegistrationService {
  44. // Created GenericDAO instance using DI
  45. @Autowired
  46. private IGenericMongoDao genericDAO;
  47. // Created HelperUtil instance.
  48. private HelperUtil helperUtil = new HelperUtil();
  49. // Created ModelMapper instance.
  50. private ModelMapper modelMapper = new ModelMapper();
  51. // Created NullAwareBeanUtilsBean instance.
  52. private BeanUtilsBean notNull = new NullAwareBeanUtilsBean();
  53. /**
  54. * This method is used to create or register a patient, it will not allow to
  55. * insert if the email id already exists in the table.
  56. *
  57. * @see vHMS.Facade.IPatientRegistrationService#create(vHMS.Core.Models.PatientRegistrationViewModel
  58. * )
  59. */
  60. @SuppressWarnings("unused")
  61. public Response create(PatientRegistrationViewModel viewModel) {
  62. Response response = new Response();
  63. ResponseViewModel responseViewModel = new ResponseViewModel();
  64. PatientRegistration patientexist = null;
  65. Map<String, Object> map = new HashMap<String, Object>();
  66. try {
  67. if (viewModel.uhId != null && viewModel.uhId.length()>0 ) {
  68. map.put("email", viewModel.email);
  69. map.put("uhId", viewModel.uhId);
  70. patientexist = genericDAO.findOneByAttribute(
  71. CommonUtils.getMessage("PatientRegistration"), map,
  72. PatientRegistration.class);
  73. if (null != patientexist) {
  74. // PatientRegistrationViewModel patientDetails =
  75. // modelMapper.map(patientexist,PatientRegistrationViewModel.class);
  76. responseViewModel.viewModel = modelMapper.map(patientexist,
  77. PatientRegistrationViewModel.class);
  78. response.ViewModel = responseViewModel;
  79. response.success = true;
  80. response.message = CommonUtils
  81. .getMessage("success.patientRegister.exist");
  82. } else {
  83. response.success = false;
  84. response.message = CommonUtils
  85. .getMessage("error.patientRegister.exists");
  86. }
  87. } else {
  88. // Before inserting check whether any entry is there in the DB
  89. // with
  90. // the same email id, to restrict duplication of data
  91. map.clear();
  92. map.put("email", viewModel.email);
  93. patientexist = genericDAO.findOneByAttribute(
  94. CommonUtils.getMessage("PatientRegistration"), map,
  95. PatientRegistration.class);
  96. // If entry already exist with the same mail id don't insert
  97. // send
  98. // response back with success as false.
  99. if (null != patientexist) {
  100. response.success = false;
  101. response.message = CommonUtils
  102. .getMessage("error.createPatientRegister.exists");
  103. } else {
  104. response.success = null;
  105. // Calling the helper class to set the mandatory properties
  106. // of the
  107. // view model
  108. viewModel = helperUtil.AttachCommonFields(viewModel,
  109. PatientRegistrationViewModel.class);
  110. // Generate random password
  111. String randomPassword = RandomStringUtils
  112. .randomAlphanumeric(6);
  113. // Encrypt the password to store
  114. String newPassword = CommonUtils.encryptor(randomPassword);
  115. viewModel.password = newPassword;
  116. // convert viewmodel object to model object before saving it
  117. // to DB
  118. PatientRegistration patientReg = modelMapper.map(viewModel,
  119. PatientRegistration.class);
  120. // Save the data with the fields in model and get the id for
  121. // the
  122. // saved item
  123. patientReg.setStatus(true);
  124. Object[] results = genericDAO.save(
  125. CommonUtils.getMessage("PatientRegistration"),
  126. patientReg);
  127. // Set the id back to the model.
  128. for (Object res : results) {
  129. patientReg.setId(String.valueOf(res));
  130. }
  131. // After saving if the returned id is not null then send the
  132. // response back as success
  133. if (null != patientReg.getId() && patientReg.getId() != ""
  134. && patientReg.getId().trim().length() > 0) {
  135. // Before sending it back convert it again to viewmodel
  136. // and
  137. // then send
  138. PatientRegistrationViewModel patientDetails = modelMapper
  139. .map(patientReg,
  140. PatientRegistrationViewModel.class);
  141. NotificationViewModel smsNotificationViewModel = new NotificationViewModel();
  142. smsNotificationViewModel
  143. .setNotificationType("sms");
  144. smsNotificationViewModel
  145. .setTo(patientDetails.contactNumber);
  146. smsNotificationViewModel.setBody(CommonUtils
  147. .getMessage("sms.message"));
  148. responseViewModel.smsNotificationViewModel = smsNotificationViewModel;
  149. NotificationViewModel notificationViewModel = new NotificationViewModel();
  150. notificationViewModel.setTo(patientDetails.email);
  151. notificationViewModel.setFrom(CommonUtils
  152. .getMessage("from"));
  153. notificationViewModel.setSubject(CommonUtils
  154. .getMessage("emailsubject"));
  155. // Get the email body content from the scala temapltes
  156. String body = views.html.emailtemplates.sendmail
  157. .render(patientDetails.firstName,
  158. patientDetails.email,
  159. patientDetails.uhId, randomPassword)
  160. .body();
  161. notificationViewModel.setBody(body);
  162. responseViewModel.notificationViewModel = notificationViewModel;
  163. responseViewModel.viewModel = modelMapper.map(
  164. patientDetails,
  165. PatientRegistrationViewModel.class);
  166. response.success = true;
  167. response.message = CommonUtils
  168. .getMessage("success.createPatientRegister");
  169. // Binding the created data to the view model in the
  170. // response
  171. response.ViewModel = responseViewModel;
  172. } else {
  173. // If the saved id is null send the response back with
  174. // success as false.
  175. response.success = false;
  176. response.message = CommonUtils
  177. .getMessage("error.createPatientRegister");
  178. }
  179. }
  180. }
  181. } catch (Exception e) {
  182. // return false if there is any database connection problem
  183. response.success = false;
  184. response.message = CommonUtils.getMessage("error.processfailure");
  185. if (null != e.getMessage()) {
  186. response.ExceptionMessage = e.getMessage();
  187. } else {
  188. response.ExceptionMessage = e.toString();
  189. }
  190. }
  191. return response;
  192. }
  193. /*
  194. * Implementation of interface IPatientRegistrationService all method which
  195. * returns a list of all Patients.
  196. *
  197. * @see
  198. *
  199. * @see vHMS.Facade.IPatientRegistrationService#all(vHMS.Core.Models.
  200. * PatientRegistrationViewModel
  201. */
  202. @SuppressWarnings("serial")
  203. public Response all(PatientRegistrationViewModel viewModel) {
  204. Response response = new Response();
  205. try {
  206. // Condition to check whether where attribute is empty
  207. // To check for search criteria
  208. if (viewModel.where != null) {
  209. // for appending the where and the like for search criteria
  210. viewModel.where = helperUtil
  211. .ConstructWhereClauseFromJson(viewModel.where);
  212. }
  213. List<PatientRegistration> list = null;
  214. if (viewModel != null) {
  215. list = genericDAO.all(viewModel.entityObject,
  216. PatientRegistration.class, viewModel.where,
  217. viewModel.limit, viewModel.skip);
  218. }
  219. // Checking whether the list is empty or not
  220. if (null != list && list.size() > 0) {
  221. // Define the target type
  222. Type targetListType = new TypeToken<List<PatientRegistrationViewModel>>() {
  223. }.getType();
  224. // Mapping the list with the target view model
  225. List<PatientRegistrationViewModel> lists = modelMapper.map(
  226. list, targetListType);
  227. response.success = true;
  228. response.message = CommonUtils
  229. .getMessage("success.fetchPatientdata");
  230. // appending the list to the response viewModels list to didplay
  231. // in the UI
  232. response.ViewModels = lists;
  233. } else {
  234. response.success = false;
  235. response.message = CommonUtils
  236. .getMessage("error.fetchPatientdata");
  237. }
  238. } catch (Exception e) {
  239. // error in the database or connection
  240. response.success = false;
  241. response.message = CommonUtils.getMessage("error.processfailure");
  242. if (null != e.getMessage()) {
  243. response.ExceptionMessage = e.getMessage();
  244. } else {
  245. response.ExceptionMessage = e.toString();
  246. }
  247. }
  248. return response;
  249. }
  250. /*
  251. * Implementation of interface IPatientRegistrationService findByCode method
  252. * which is used to find an patinets using code(primary key).
  253. *
  254. * @see vHMS.Facade.IPatientRegistrationService#findByCode(vHMS.Core.Models.
  255. * PatientRegistrationViewModel
  256. */
  257. public Response findByCode(PatientRegistrationViewModel viewModel)
  258. throws Exception {
  259. // TODO Auto-generated method stub
  260. Response response = new Response();
  261. try {
  262. // To find where the record exists
  263. PatientRegistration patientexist = null;
  264. Map<String, Object> map = new HashMap<String, Object>();
  265. if (viewModel != null) {
  266. map.put("code", viewModel.code);
  267. // get the patient object by passing code
  268. patientexist = genericDAO.findOneByAttribute(
  269. CommonUtils.getMessage("PatientRegistration"), map,
  270. PatientRegistration.class);
  271. }
  272. if (null != patientexist) {
  273. // ModelMapper modelMapper = new ModelMapper();
  274. PatientRegistrationViewModel catData = modelMapper.map(
  275. patientexist, PatientRegistrationViewModel.class);
  276. response.success = true;
  277. // if the record exists bind to the view model
  278. response.ViewModel = catData;
  279. response.message = CommonUtils
  280. .getMessage("success.findPatientdata");
  281. } else {
  282. response.success = false;
  283. response.message = CommonUtils
  284. .getMessage("error.findPatientdata");
  285. }
  286. } catch (Exception e) {
  287. // return false if there is any database connection problem
  288. response.success = false;
  289. response.message = CommonUtils.getMessage("error.processfailure");
  290. if (null != e.getMessage()) {
  291. response.ExceptionMessage = e.getMessage();
  292. } else {
  293. response.ExceptionMessage = e.toString();
  294. }
  295. }
  296. return response;
  297. }
  298. /*
  299. * Implementation of interface IPatientRegistrationService update method
  300. * which is used to update the IPatientRegistrationService details with the
  301. * given code.
  302. *
  303. * @see vHMS.Facade.IPatientRegistrationService#update(vHMS.Core.Models.
  304. * PatientRegistrationViewModel )
  305. */
  306. public Response update(PatientRegistrationViewModel viewModel)
  307. throws Exception {
  308. // TODO Auto-generated method stub
  309. Response response = new Response();
  310. try {
  311. // Mapping the viewmodel to class of type
  312. PatientRegistration patient = modelMapper.map(viewModel,
  313. PatientRegistration.class);
  314. // getting the id from the view model for updating for the specific
  315. // id
  316. Map<String, Object> map = new HashMap<String, Object>();
  317. map.put("code", patient.getCode());
  318. // get the patient object by passing code
  319. PatientRegistration patientexist = genericDAO.findOneByAttribute(
  320. CommonUtils.getMessage("PatientRegistration"), map,
  321. PatientRegistration.class);
  322. if (patientexist != null) {
  323. // override the old properties with new properties exists in the
  324. // right side object
  325. patient.setPassword(patientexist.getPassword());
  326. notNull.copyProperties(patientexist, patient);
  327. // Calling the helper class to set the mandatory properties of
  328. // the
  329. // view model
  330. viewModel = helperUtil.AttachCommonFields(viewModel,
  331. PatientRegistrationViewModel.class);
  332. // Updating the record by ID
  333. genericDAO.updateById(viewModel.entityObject, patientexist,
  334. patientexist.getId());
  335. // ModelMapper modelmapper = new ModelMapper();
  336. PatientRegistrationViewModel patientdata = modelMapper.map(
  337. patientexist, PatientRegistrationViewModel.class);
  338. response.success = true;
  339. response.message = CommonUtils
  340. .getMessage("success.updatePatientdata");
  341. // sending the response object as view model
  342. response.ViewModel = patientdata;
  343. } else {
  344. response.success = false;
  345. response.message = CommonUtils
  346. .getMessage("error.updatePatientdata");
  347. }
  348. } catch (Exception e) {
  349. response.success = false;
  350. response.message = CommonUtils.getMessage("error.processfailure");
  351. if (null != e.getMessage()) {
  352. response.ExceptionMessage = e.getMessage();
  353. } else {
  354. response.ExceptionMessage = e.toString();
  355. }
  356. }
  357. return response;
  358. }
  359. /*
  360. * Implementation of interface IPatientRegistrationService
  361. * findAllByAttributes method which fetches all the record with the given
  362. * criteria.
  363. *
  364. * @see
  365. * vHMS.Facade.IPatientRegistrationService#findAllByAttributes(vHMS.Core
  366. * .Models.PatientRegistrationViewModel
  367. */
  368. @SuppressWarnings("serial")
  369. public Response findAllByAttributes(PatientRegistrationViewModel viewModel)
  370. throws Exception {
  371. // TODO Auto-generated method stub
  372. Response response = new Response();
  373. int count = 0;
  374. try {
  375. if (viewModel != null) {
  376. // ModelMapper mapper = new ModelMapper();
  377. // Converting MasterViewModel object to MasterEntity Pojo
  378. PatientRegistration catData = modelMapper.map(viewModel,
  379. PatientRegistration.class);
  380. Gson gson = new GsonBuilder().setDateFormat(
  381. "yyyy-MM-dd HH:mm:ss").create();
  382. // Converting MasterEntity to a JSON string
  383. String master = gson.toJson(catData);
  384. // Converting JON string to a HashMap
  385. Map<String, Object> map = gson.fromJson(master,
  386. new TypeToken<HashMap<String, Object>>() {
  387. }.getType());
  388. BasicDBList ORList = new BasicDBList();
  389. if (map.containsKey("firstName")) {
  390. DBObject firstName = new BasicDBObject("firstName", java.util.regex.Pattern.compile(
  391. (String) catData.getFirstName(),
  392. Pattern.CASE_INSENSITIVE));
  393. map.remove("firstName");
  394. ORList.add(firstName);
  395. }
  396. if (map.containsKey("middleName")) {
  397. DBObject middleName = new BasicDBObject("middleName", java.util.regex.Pattern.compile(
  398. (String) catData.getFirstName(),
  399. Pattern.CASE_INSENSITIVE));
  400. map.remove("middleName");
  401. ORList.add(middleName);
  402. }
  403. if (map.containsKey("lastName")) {
  404. DBObject lastName = new BasicDBObject("lastName", java.util.regex.Pattern.compile(
  405. (String) catData.getFirstName(),
  406. Pattern.CASE_INSENSITIVE));
  407. map.remove("lastName");
  408. ORList.add(lastName);
  409. }
  410. if(ORList.size()>0)
  411. {
  412. map.put("$or", ORList);
  413. }
  414. // Getting the list of entity for the criteria and all the
  415. // records
  416. List<PatientRegistration> list = genericDAO
  417. .findAllByAttributes(viewModel.entityObject, map,
  418. PatientRegistration.class, viewModel.limit,
  419. viewModel.skip);
  420. // ModelMapper modelmapper = new ModelMapper();
  421. // Define the target type
  422. Type targetListType = new TypeToken<List<PatientRegistrationViewModel>>() {
  423. }.getType();
  424. // Mapping the list with the target view model
  425. List<PatientRegistrationViewModel> lists = modelMapper.map(
  426. list, targetListType);
  427. // get count of records based on the filter
  428. if (viewModel.limit != null && null != list && Integer.parseInt(viewModel.limit) >= list.size()) {
  429. count = genericDAO.count(viewModel.entityObject, map,
  430. PatientRegistration.class);
  431. }
  432. else {
  433. count = list.size();
  434. }
  435. // Checking whether the list is empty or not
  436. if (null != lists && lists.size() > 0) {
  437. response.success = true;
  438. response.message = CommonUtils
  439. .getMessage("success.fetchPatientdata");
  440. // appending the list to the response viewModels list to
  441. // didplay
  442. // in the UI
  443. response.ViewModels = lists;
  444. response.ViewModel = count;
  445. } else {
  446. // List is empty response is false
  447. response.success = false;
  448. response.message = CommonUtils
  449. .getMessage("error.fetchPatientdata");
  450. }
  451. } else {
  452. // List is empty response is false
  453. response.success = false;
  454. response.message = CommonUtils.getMessage("error.Invalid");
  455. }
  456. } catch (Exception e) {
  457. // error in the database or connection
  458. response.success = false;
  459. response.message = CommonUtils.getMessage("error.processfailure");
  460. if (null != e.getMessage()) {
  461. response.ExceptionMessage = e.getMessage();
  462. } else {
  463. response.ExceptionMessage = e.toString();
  464. }
  465. }
  466. return response;
  467. }
  468. /*
  469. * Implementation of interface IPatientRegistrationService Authenticate
  470. * method which is used to authenticate a patient with the given attributes.
  471. *
  472. * @see
  473. * vHMS.Facade.IPatientRegistrationService#Authenticate(vHMS.Core.ViewModels
  474. * . PatientRegistrationViewModel)
  475. */
  476. public Response Authenticate(PatientRegistrationViewModel viewModel)
  477. throws Exception {
  478. Response response = new Response();
  479. try {
  480. Map<String, Object> map = new HashMap<String, Object>();
  481. // storing email id of logging in user in map
  482. map.put("email", viewModel.email);
  483. map.put("password", CommonUtils.encryptor(viewModel.password));
  484. map.put("status", true);
  485. // Check if it is valid email by confirming its existence
  486. PatientRegistration patient = genericDAO.findOneByAttribute(
  487. CommonUtils.getMessage("PatientRegistration"), map,
  488. PatientRegistration.class);
  489. if (null != patient
  490. && patient.getPassword().equals(
  491. CommonUtils.encryptor(viewModel.password))) {
  492. // ModelMapper modelmapper = new ModelMapper();
  493. PatientRegistrationViewModel patientViewModel = modelMapper
  494. .map(patient, PatientRegistrationViewModel.class);
  495. // setting Token
  496. patientViewModel.authToken = userAuthToken(patient);
  497. // setting passwd as empty,so it won't be there in respose
  498. patientViewModel.password = "";
  499. response.success = true;
  500. response.message = CommonUtils
  501. .getMessage("login.patient.success");
  502. response.ViewModel = patientViewModel;
  503. } else {
  504. response.success = false;
  505. response.message = CommonUtils
  506. .getMessage("error.patient.login");
  507. }
  508. } catch (Exception e) {
  509. // Handling Exception
  510. response.success = false;
  511. response.message = CommonUtils.getMessage("error.patient.login");
  512. if (null != e.getMessage()) {
  513. response.ExceptionMessage = e.getMessage();
  514. } else {
  515. response.ExceptionMessage = e.toString();
  516. }
  517. }
  518. return response;
  519. }
  520. /*
  521. * Implementation of interface IPatientRegistrationService changePassword
  522. * method which is used to change the password when an User requests for the
  523. * same.
  524. *
  525. * @see
  526. * vHMS.Facade.IPatientRegistrationService#changePassword(vHMS.Core.ViewModels
  527. * . PatientRegistrationViewModel)
  528. */
  529. public Response changePassword(PatientRegistrationViewModel viewModel)
  530. throws Exception {
  531. Response response = new Response();
  532. // Get the emailId
  533. Map<String, Object> map = new HashMap<String, Object>();
  534. // puuting encrypted password into Map
  535. map.put("password", CommonUtils.encryptor(viewModel.password));
  536. map.put("email", viewModel.email);
  537. try {
  538. // Check if it is valid email by confirming its existence
  539. PatientRegistration patientRegistration = genericDAO
  540. .findOneByAttribute(
  541. CommonUtils.getMessage("PatientRegistration"), map,
  542. PatientRegistration.class);
  543. // Encrypt the password to store
  544. String newPassword = CommonUtils.encryptor(viewModel.newPassword);
  545. // If exists and valid, modify the password and send email
  546. if (null != patientRegistration) {
  547. // Update user password
  548. patientRegistration.setPassword(newPassword);
  549. genericDAO.updateById(
  550. CommonUtils.getMessage("PatientRegistration"),
  551. patientRegistration, patientRegistration.getId());
  552. response.success = true;
  553. response.message = CommonUtils
  554. .getMessage("success.passwordsuccess");
  555. } else {
  556. response.success = false;
  557. response.message = CommonUtils
  558. .getMessage("error.passworderror");
  559. }
  560. } catch (Exception e) {
  561. response.success = false;
  562. response.message = CommonUtils
  563. .getMessage("error.processfailurechangepwd");
  564. response.ExceptionMessage = e.getMessage();
  565. }
  566. return response;
  567. }
  568. /*
  569. * Implementation of interface IPatientRegistrationService forgotPassword
  570. * method which is used to get back user's password if User forgot his
  571. * password.
  572. *
  573. * @see
  574. * vHMS.Facade.IPatientRegistrationService#forgotPassword(vHMS.Core.ViewModels
  575. * . PatientRegistrationViewModel)
  576. */
  577. public Response forgotPassword(PatientRegistrationViewModel viewModel)
  578. throws Exception {
  579. Response response = new Response();
  580. // Get the emailId
  581. Map<String, Object> map = new HashMap<String, Object>();
  582. map.put("email", viewModel.email);
  583. try {
  584. // Check if it is valid email by confirming its existence
  585. PatientRegistration patientRegistration = genericDAO
  586. .findOneByAttribute(
  587. CommonUtils.getMessage("PatientRegistration"), map,
  588. PatientRegistration.class);
  589. // com.fasterxml.jackson.databind.node.ObjectNode result =
  590. // Json.newObject();
  591. // If exists and valid, modify the password and send email
  592. if (null != patientRegistration) {
  593. // Generate random password
  594. String randomPassword = RandomStringUtils.randomAlphanumeric(6);
  595. // Encrypt the password to store
  596. String newPassword = CommonUtils.encryptor(randomPassword);
  597. // Create a mail message t be send.
  598. // NotificationMessage message = new NotificationMessage();
  599. NotificationViewModel message = new NotificationViewModel();
  600. ResponseViewModel responseViewModel = new ResponseViewModel();
  601. message.setTo(patientRegistration.getEmail());
  602. message.setFrom(CommonUtils.getMessage("from"));
  603. message.setSubject(CommonUtils.getMessage("subject"));
  604. // Get the email body content from the scala temapltes
  605. String body = views.html.emailtemplates.forgotpassword.render(
  606. patientRegistration.getFirstName(),
  607. patientRegistration.getEmail(), randomPassword).body();
  608. message.setBody(body);
  609. // defaultEmailSender.send(message);
  610. // Update user password
  611. patientRegistration.setPassword(newPassword);
  612. genericDAO.updateById(
  613. CommonUtils.getMessage("PatientRegistration"),
  614. patientRegistration, patientRegistration.getId());
  615. responseViewModel.notificationViewModel = message;
  616. response.success = true;
  617. response.message = CommonUtils.getMessage("success.emailSent");
  618. response.ViewModel = responseViewModel;
  619. } else {
  620. response.success = false;
  621. response.message = CommonUtils
  622. .getMessage("error.notregistered");
  623. }
  624. } catch (Exception e) {
  625. response.success = false;
  626. response.message = CommonUtils.getMessage("error.processfailure");
  627. response.ExceptionMessage = e.getMessage();
  628. }
  629. return response;
  630. }
  631. /*
  632. * userAuthToken is a private method which is used to generate JWT token.
  633. */
  634. private String userAuthToken(PatientRegistration patientRegistration)
  635. throws Exception {
  636. if (patientRegistration != null) {
  637. // create a map and put the unique information for generating the
  638. // token.
  639. Map<String, Object> claims = new HashMap<String, Object>();
  640. claims.put("uid", patientRegistration.getId());
  641. claims.put("userName", patientRegistration.getFirstName());
  642. claims.put("userEmail", patientRegistration.getEmail());
  643. return HelperUtil.GenerateAuthToken(claims);
  644. }
  645. return null;
  646. }
  647. }