Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.11 KB | None | 0 0
  1. package com.itel.nsweb.business.cuprecall_asltaranto;
  2.  
  3. import com.google.gson.Gson;
  4. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.ReserveAppointmentRequest;
  5. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.AvailabilityListAppointmentsRequest;
  6.  
  7. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.DeleteReservationRequest;
  8. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.ElectronicPrescriptionRequest;
  9. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.NewDateAppointmentRequest;
  10. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.PatientAppointmentsRequest;
  11. import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.ReplaceAppointmentRequest;
  12. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.AvailabilityListAppointmentsResponse;
  13. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.DeleteReservationResponse;
  14. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.ElectronicPrescriptionResponse;
  15. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.LoginResponse;
  16. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.NewDateAppointmentResponse;
  17. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.PatientAppointmentsResponse;
  18. import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.ReplaceAppointmentResponse;
  19. import com.itel.nsweb.business.cuprecall_asltaranto.enums.PrescriptionType;
  20. import com.itel.nsweb.business.cuprecall_asltaranto.modeldata.medicalexamination_nre.ElectronicPrescription;
  21. import com.itel.nsweb.business.cuprecall_asltaranto.modeldata.medicalexamination_nre.NreAppointment;
  22. import com.itel.nsweb.core.common.apps.AppConfigManagement;
  23. import com.itel.nsweb.core.common.apps.communication.response.BaseResponse;
  24. import com.itel.nsweb.core.common.apps.enumeration.ResponseStatus;
  25. import com.itel.nsweb.core.common.apps.session.AppSession;
  26. import com.itel.nsweb.core.cuprecall.communication.response.SyncDataResponse;
  27. import com.itel.nsweb.core.cuprecall.enumeration.UserType;
  28. import com.itel.nsweb.core.cuprecall.modeldata.Patient;
  29. import com.itel.nsweb.core.cuprecall.modeldata.User;
  30. import com.itel.nsweb.core.cuprecall.enumeration.GradientType;
  31. import com.itel.nsweb.core.cuprecall.enumeration.LoginType;
  32. import com.itel.nsweb.core.cuprecall.modeldata.Company;
  33. import com.itel.nsweb.core.cuprecall.modeldata.style.CompanyStyle;
  34. import com.itel.nsweb.core.cuprecall.modeldata.style.Gradient;
  35. import com.itel.smartsuite.tools.datetime.DateTimeFunctions;
  36. import com.itel.smartsuite.tools.xmlloading.GlobalVars;
  37.  
  38. import com.rsp.toolbox.tools.LogEx;
  39. import com.rsp.toolbox.tools.WebEx;
  40. import java.io.IOException;
  41.  
  42. import java.text.ParseException;
  43. import java.text.SimpleDateFormat;
  44. import java.util.ArrayList;
  45. import java.util.Date;
  46. import java.util.Enumeration;
  47. import java.util.HashMap;
  48. import java.util.List;
  49. import java.util.Locale;
  50. import java.util.Map;
  51. import java.util.logging.Level;
  52. import java.util.logging.Logger;
  53.  
  54. import javax.servlet.http.HttpServletRequest;
  55. import javax.servlet.http.HttpServletResponse;
  56. import org.apache.http.HttpEntity;
  57. import org.apache.http.HttpResponse;
  58. import org.apache.http.HttpVersion;
  59. import org.apache.http.client.config.RequestConfig;
  60. import org.apache.http.client.methods.HttpGet;
  61. import org.apache.http.client.methods.HttpPatch;
  62. import org.apache.http.entity.StringEntity;
  63. import org.apache.http.impl.client.CloseableHttpClient;
  64. import org.apache.http.impl.client.HttpClients;
  65. import org.apache.http.params.BasicHttpParams;
  66. import org.apache.http.params.HttpParams;
  67. import org.apache.http.util.EntityUtils;
  68. import org.json.JSONException;
  69. import org.json.JSONObject;
  70.  
  71. /**
  72. * Classe per le richieste provenienti dalle app
  73. *
  74. * @author Mirko Budano
  75. * @author Matteo Gramellini
  76. *
  77. * "http://localhost:8084/voipsmartsuite/wgate?typereq=apprequest&classname=com.itel.nsweb.business.cuprecall_asltaranto.AppReq&requestnumber=301"
  78. *
  79. * #GET APPUNTAMENTI
  80. * "http://localhost:8084/voipsmartsuite/wgate?typereq=apprequest&classname=com.itel.nsweb.business.cuprecall_asltaranto.AppReq&requestnumber=310&codiceAssistito=GVNFNC68D14A662T"
  81. *
  82. * #GET NUOVA DATA APPUNTAMENTO
  83. * "http://localhost:8084/voipsmartsuite/wgate?typereq=apprequest&classname=com.itel.nsweb.business.cuprecall_asltaranto.AppReq&requestnumber=311&codCoupon=385836&anno=2015&datanascita=14/04/1968"
  84. *
  85. * #SOSTITUISCI APPUNTAMENTO
  86. * "http://localhost:8084/voipsmartsuite/wgate?typereq=apprequest&classname=com.itel.nsweb.business.cuprecall_asltaranto.AppReq&requestnumber=312&idDisponibilita=&codCoupon=385836&anno=2015&datanascita=14/04/1968"
  87. *
  88. *
  89. */
  90. public class AppReq extends com.itel.nsweb.core.cuprecall.AppReq {
  91.  
  92. /**
  93. * modulo xml dove recuperare i parametri di comunicazione con il sistema
  94. * esterno
  95. */
  96. protected String confFileName = "module_business_app_cuprecall.xml";
  97. /**
  98. * elenco delle variabili di configurazione dell'app caricate da xml
  99. */
  100. protected List<HashMap<String, HashMap<String, String>>> appConfig = null;
  101. /**
  102. * indica se è stato inizializzato correttamente
  103. */
  104. private boolean isInitialized = false;
  105.  
  106. private final static String ITALIAN_DATE_PATTERN = "dd/MM/yyyy";
  107.  
  108. public AppReq() {
  109. super();
  110.  
  111. appConfig = AppConfigManagement.getAppConfig(confFileName);
  112. if (appConfig != null) {
  113. isInitialized = true;
  114. }
  115. }
  116.  
  117. public boolean isInitialized() {
  118. return isInitialized;
  119. }
  120.  
  121. @Override
  122. protected String executeCustomRequest(int requestNumber, HttpServletRequest request) {
  123. String res;
  124. switch (requestNumber) {
  125. case 300: // sincronizza i dati di configurazione dell'app
  126. res = syncData(request);
  127. break;
  128. case 301: //metodo per effettuare il login
  129. res = login(request);
  130. break;
  131. case 310: //recupera gli appuntamenti dell'assistito
  132. res = getPatientAppointments(request);
  133. break;
  134. case 311: //cancella una prenotazione
  135. res = deleteReservation(request);
  136. break;
  137. case 320: // recupura una nuova disponibilità per l'appuntamento
  138. res = getNewDateAppointment(request);
  139. break;
  140. case 321: // sostituisce la vecchia data di un appuntamento con una nuova disponibile
  141. res = replaceAppointment(request);
  142. break;
  143. case 322: //Ritorna la prestazione elettronica associata alla ricetta
  144. res = getElectronicPrescription(request);
  145. break;
  146. case 323: //Ritorna la disponibilità degli appuntamenti
  147. res = getAvailabilityAppointmens(request);
  148. break;
  149. case 324: //Conferma una prenotazione
  150. res = confirmReservation(request);
  151. break;
  152. case 999: //Utilizzato per i test
  153. res = testLogin();
  154. break;
  155.  
  156. default:
  157. res = super.executeCustomRequest(requestNumber, request);
  158. }
  159. return res;
  160. }
  161.  
  162. /**
  163. * questo metodo viene chiamato dopo aver chiamato il metodo trig per
  164. * settare il tipo di contenuto inviato come risposta. Di default usa
  165. * text/xml;charset=UTF-8
  166. *
  167. * @param response
  168. */
  169. @Override
  170. public void setResponseContentType(HttpServletResponse response) {
  171. response.setContentType("text/html;charset=UTF-8");
  172. }
  173.  
  174. /**
  175. * metodo invocato per la sincronizzazione dei dati di configurazione
  176. * dell'app
  177. *
  178. * @param request
  179. * @return risultato della richiesta di sincronizzazione dei dati
  180. */
  181. @Override
  182. protected String syncData(HttpServletRequest request) {
  183. SyncDataResponse syncDataResponse;
  184. if (!isInitialized) {
  185. LogEx.trace(3, "syncData", "Errore durante l'inizializzazione delle variabili da " + confFileName);
  186. syncDataResponse = new SyncDataResponse();
  187. syncDataResponse.setResponseDescription("Errore durante l'inizializzazione dell'app");
  188. return getNewGson().toJson(syncDataResponse);
  189. }
  190. try {
  191. List<Company> companies = new ArrayList<>();
  192. for (HashMap<String, HashMap<String, String>> company : appConfig) {
  193. CompanyStyle companyStyle = null;
  194. HashMap<String, String> style = company.get("style");
  195. if (style != null && style.size() > 0) {
  196. String sGradientType = style.get("gradient_type");
  197. int iGradientType = 0; // setto di default il gradient linear
  198. if (sGradientType != null) {
  199. iGradientType = Integer.valueOf(sGradientType);
  200. }
  201. GradientType gradientType = GradientType.getFromInt(iGradientType);
  202. Gradient gradient = new Gradient(style.get("start_color"), style.get("center_Color"), style.get("end_color"), gradientType);
  203. companyStyle = new CompanyStyle(style.get("color_primary"), style.get("color_primary_dark"), style.get("color_primary_light"), style.get("color_secondary"), style.get("color_accent"), style.get("text_color_primary"), style.get("text_color_secondary"), style.get("text_color_secondary_light"), gradient);
  204. }
  205.  
  206. HashMap<String, String> data = company.get("data");
  207. if (data != null && data.size() > 0) {
  208. String companyCode = data.get("company_code");
  209. String companyName = data.get("company_name");
  210. String loginUrl = data.get("login_url");
  211. String logoUrl = data.get("logo_url");
  212.  
  213. String sLoginType = data.get("login_type");
  214. int iLoginType = 0; // setto di default il login local
  215. if (sLoginType != null) {
  216. iLoginType = Integer.valueOf(sLoginType);
  217. }
  218. LoginType loginType = LoginType.getFromInt(iLoginType);
  219.  
  220. companies.add(new Company(companyCode, companyName, logoUrl, loginUrl, loginType, companyStyle));
  221. }
  222. }
  223.  
  224. if (companies.size() > 0) {
  225. syncDataResponse = new SyncDataResponse(companies);
  226. syncDataResponse.setStatus(ResponseStatus.OK);
  227. } else {
  228. syncDataResponse = new SyncDataResponse();
  229. syncDataResponse.setResponseDescription("Errore durante il caricamento dei dati di configurazione");
  230. }
  231. } catch (NumberFormatException e) {
  232. syncDataResponse = new SyncDataResponse();
  233. syncDataResponse.setResponseDescription("Errore durante il recupero dei dati di configurazione");
  234. LogEx.error(e, "Errore durante il recupero dei dati di configurazione");
  235. }
  236.  
  237. return getNewGson().toJson(syncDataResponse);
  238. }
  239.  
  240. /**
  241. * metodo invocato dopo il login fatto con shibboleth
  242. *
  243. * @param request
  244. * @return pagina html con la 'response' della chiamata
  245. */
  246. @Override
  247. public String login(HttpServletRequest request) {
  248. Gson g = getNewGson();
  249. String ret;
  250. String javascript = "<script type=\"text/javascript\">function getMobileOperatingSystem(){var userAgent=navigator.userAgent||navigator.vendor||window.opera;if(/windows phone/i.test(userAgent)){return\"Windows Phone\";}\n"
  251. + "if(/android/i.test(userAgent)){return\"Android\";}\n"
  252. + "if(/iPad|iPhone|iPod/.test(userAgent)&&!window.MSStream){return\"iOS\";}\n"
  253. + "return\"unknown\";}\n"
  254. + "function sendResult(result){var os=getMobileOperatingSystem();if(os==\"Android\"){Android.getResult(result);}"
  255. + "else if(os==\"iOS\"){var resultToLogin={'result':result};window.webkit.messageHandlers.callbackHandler.postMessage(resultToLogin);}}</script>";
  256.  
  257. LoginResponse response = new LoginResponse();
  258. try {
  259. //uso questa stringa per stampare le coppie chiave-valore dell'header nel caso in cui il login non abbia successo
  260. String headerLog = "";
  261. //loggo tutti gli header che mi arrivano per DEBUG
  262. Enumeration headerNames = request.getHeaderNames();
  263. while (headerNames.hasMoreElements()) {
  264. String key = (String) headerNames.nextElement();
  265. String value = request.getHeader(key);
  266. headerLog += key + ":" + value + ";";//aggiungo la coppia chiave:valore alla stringa di log
  267. LogEx.trace(6, "ng", "AppReq::login() Header - " + key + ": " + value);
  268. }
  269. //flag che indica se sono loggato con successo
  270. boolean loginOk = false;
  271. //provo a recuperare lo spincode
  272. String spinCode = request.getHeader("spidcode");
  273. //definisco taxCode, name, birthday, email
  274. String taxCode = "", name = "", email = "";
  275. Date birthday = null;
  276. //se spinCode non è null ed è valorizzato allora il login è con SPID
  277. if (spinCode != null && !spinCode.isEmpty()) {
  278. //AUTENTICAZIONE CON IDP
  279. //prendo il codice fiscale
  280. taxCode = WebEx.StringToHTTPParam(request.getHeader("fiscalnumber"));
  281. //per sicurezza aggiungo un controllo, se mi arriva un trattino prendo la seconda parte (durante i test mi è arrivato come codice fiscale TINIT-STTRLI70A01F205L)
  282. if (taxCode.contains("-")) {
  283. //se per sbaglio ho un trattino faccio lo split e prendo la seconda parte
  284. taxCode = taxCode.split("-")[1];
  285. }
  286. //prendo cognome e nome del paziente
  287. name = WebEx.StringToHTTPParam(request.getHeader("familyname")) + " " + WebEx.StringToHTTPParam(request.getHeader("name"));
  288. //prendo la data di nascita
  289. birthday = DateTimeFunctions.getDateFromString(WebEx.StringToHTTPParam(request.getHeader("dateofbirth")), "yyyy-MM-dd");
  290. //prendo l'email
  291. email = WebEx.StringToHTTPParam(request.getHeader("mail"));
  292. //setto il flag loginOk a true
  293. loginOk = true;
  294. } else if ("TRUE".equalsIgnoreCase(request.getHeader("useridentified")) && "TRUE".equalsIgnoreCase(request.getHeader("userenabled"))) {
  295. //AUTENTICAZIONE CON IDP (Portale Regionale Puglia)
  296. //prendo il codice fiscale
  297. taxCode = WebEx.StringToHTTPParam(request.getHeader("codicefiscale"));
  298. //prendo nome cognome
  299. name = WebEx.StringToHTTPParam(request.getHeader("cognome")) + " " + WebEx.StringToHTTPParam(request.getHeader("nome"));
  300. //prendo la data di nascita
  301. birthday = DateTimeFunctions.getDateFromString(WebEx.StringToHTTPParam(request.getHeader("datanascita")), ITALIAN_DATE_PATTERN);
  302. //prendo l'email
  303. email = WebEx.StringToHTTPParam(request.getHeader("mail"));
  304. //setto il flag loginOk a true
  305. loginOk = true;
  306. } else {
  307. //stampo un log basso con i valori ricevuti nella response
  308. LogEx.trace(1, "ng", "AppReq::login() Utente non abilitato. Coppie chiave:valore ricevute nella response " + headerLog);
  309. response.setResponseDescription("Utente non abilitato ad accedere ai servizi");
  310. }
  311.  
  312. //se loginOk è true
  313. if (loginOk) {
  314. //creo la sessione(nel costruttore la aggiunge anche alla lista delle sessioni)
  315. AppSession session = new AppSession(name);
  316. //mi viene passato un solo paziente
  317. Patient patient = new Patient(taxCode, name, birthday, email);
  318.  
  319. List<Patient> patientsAssociated = new ArrayList<>();
  320. patientsAssociated.add(patient);
  321. //creo User
  322. User user = new User(session.getSid(), UserType.REGISTERED, patientsAssociated);
  323. //setto id di sessione nella response
  324. response.setUser(user);
  325. response.setStatus(ResponseStatus.OK);
  326. LogEx.trace(5, "ng", "AppReq::login() Login effettuato con successo, codice fiscale ricevuto: " + taxCode);
  327. }
  328. } catch (Exception e) {
  329. LogEx.error(e, "AppReq::login() Errore durante il parse del risultato ottenuto da shibboleth");
  330. response.setResponseDescription("Errore di sistema. Contattare l'assistenza");
  331. } finally {
  332. ret = "<!DOCTYPE html><html><head>" + javascript + "</head><body onload='sendResult(\"" + g.toJson(response).replace("\"", "\\\"") + "\")'></body></html>";
  333. }
  334. return ret;
  335. }
  336.  
  337. public String testLogin() {
  338. LoginResponse response = new LoginResponse();
  339. //creo la sessione(nel costruttore la aggiunge anche alla lista delle sessioni)
  340. AppSession session = new AppSession("prova");
  341. //mi viene passato un solo paziente
  342. Patient patient = new Patient("PNTLNZ89B17G479T", "Lorenzo", new Date(), "prova@libero.it");
  343.  
  344. List<Patient> patientsAssociated = new ArrayList<>();
  345. patientsAssociated.add(patient);
  346. //creo User
  347. User user = new User(session.getSid(), UserType.REGISTERED, patientsAssociated);
  348. //setto id di sessione nella response
  349. LogEx.trace(5, "ng", "AppReq::testLogin() Login effettuato con successo");
  350.  
  351. response.setUser(user);
  352.  
  353. return getNewGson().toJson(response);
  354. }
  355.  
  356. /**
  357. * metodo che ritorna gli appuntamenti dell'assistito
  358. *
  359. * @param request
  360. * @return l'oggetto contenente l'elenco degli appuntamenti associati
  361. * all'assistito
  362. */
  363. @Override
  364. protected String getPatientAppointments(HttpServletRequest request) {
  365. PatientAppointmentsResponse response;
  366. try {
  367. String receivedObject = request.getParameter("json");
  368. PatientAppointmentsRequest patientAppointmentsRequest = getNewGson().fromJson(receivedObject, PatientAppointmentsRequest.class);
  369. if (patientAppointmentsRequest == null) {
  370. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo PatientAppointmentsRequest");
  371. }
  372. //recupero la sessione utente
  373. /*BaseResponse sessionResponse = checkSession(patientAppointmentsRequest.getSid());
  374. if (sessionResponse != null) {
  375. return getNewGson().toJson(sessionResponse);
  376. }*/
  377.  
  378. //prendo il codice fiscale dalla richiesta
  379. String taxCode = patientAppointmentsRequest.getTaxCode();
  380. //String taxCode = "CRVRRT68H20H147R";
  381. String startDate = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).format(patientAppointmentsRequest.getStartDate());
  382.  
  383. LogEx.trace(5, "ng", "AppReq::getPatientAppointments - taxCode: " + taxCode);
  384. LogEx.trace(5, "ng", "AppReq::getPatientAppointments - startDate: " + startDate);
  385. //creo il gestore dell'interazione con il ws
  386. WSHandler ws = new WSHandler();
  387. //chiamo il ws e gli passo codiceAssistito, dataInizio
  388. response = ws.getPatientAppointments(taxCode, startDate);
  389. } catch (Exception e) {
  390. response = new PatientAppointmentsResponse();
  391. response.setResponseDescription("Errore di sistema. Contattare l'assistenza");
  392. LogEx.error(e, "AppReq::getPatientAppointments() Errore durante il recupero degli appuntamenti per l'assistito");
  393. }
  394. return getNewGson().toJson(response);
  395. }
  396.  
  397. /**
  398. * metodo che cancella la prenotazione
  399. *
  400. * @param request
  401. * @return il risultato della cancellazione
  402. */
  403. @Override
  404. protected String deleteReservation(HttpServletRequest request) {
  405.  
  406. DeleteReservationResponse deleteReservationResponse;
  407. try {
  408. String receivedObject = request.getParameter("json");
  409. DeleteReservationRequest deleteReservationRequest = getNewGson().fromJson(receivedObject, DeleteReservationRequest.class);
  410. if (deleteReservationRequest == null) {
  411. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo DeleteReservationRequest");
  412. }
  413. // solo se l'utente è registrato
  414. if (deleteReservationRequest.getUserType() == UserType.REGISTERED) {
  415. //recupero la sessione utente
  416. BaseResponse sessionResponse = checkSession(deleteReservationRequest.getSid());
  417. if (sessionResponse != null) {
  418. return getNewGson().toJson(sessionResponse);
  419. }
  420. }
  421.  
  422. long reservationNumber = deleteReservationRequest.getReservationNumber();
  423. int cancellationReason = deleteReservationRequest.getCancellationReason();
  424. int reservationYear = deleteReservationRequest.getReservationYear();
  425. String taxCode = deleteReservationRequest.getTaxCode();
  426. //String taxCode = "CRVRRT68H20H147R";
  427. //Date birthday = deleteReservationRequest.getBirthday();
  428. Date birthday = getBirthdayFromTaxCode(taxCode);
  429.  
  430. LogEx.trace(5, "ng", "AppReq::deleteReservation - codCoupon: " + reservationNumber + ", anno: " + reservationYear + ", codice fiscale: " + taxCode);
  431. //creo il gestore dell'interazione con il ws
  432. WSHandler ws = new WSHandler();
  433. deleteReservationResponse = ws.deleteReservation(reservationNumber, cancellationReason, reservationYear, birthday);
  434. } catch (Exception e) {
  435. deleteReservationResponse = new DeleteReservationResponse();
  436. deleteReservationResponse.setResponseDescription("Errore di sistema. Contattare l'assistenza");
  437. LogEx.error(e, "Errore durante la cancellazione della prenotazione");
  438. }
  439. return getNewGson().toJson(deleteReservationResponse);
  440. }
  441.  
  442. /**
  443. * Metodo che ritorna una nuova data appuntamento per l'assistito
  444. *
  445. * @param request
  446. * @return un oggetto di tipo NewDateAppointmentResponse con la data di
  447. * nuova disponibilità
  448. */
  449. @Override
  450. protected String getNewDateAppointment(HttpServletRequest request) {
  451. NewDateAppointmentResponse newDateAppointmentResponse;
  452. try {
  453. String receivedObject = request.getParameter("json");
  454. NewDateAppointmentRequest newDateAppointmentRequest = getNewGson().fromJson(receivedObject, NewDateAppointmentRequest.class);
  455. if (newDateAppointmentRequest == null) {
  456. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo NewDateAppointmentRequest");
  457. }
  458. if (newDateAppointmentRequest.getUserType() == UserType.REGISTERED) {
  459. //recupero la sessione utente
  460. BaseResponse sessionResponse = checkSession(newDateAppointmentRequest.getSid());
  461. if (sessionResponse != null) {
  462. return getNewGson().toJson(sessionResponse);
  463. }
  464. }
  465.  
  466. long reservationNumber = newDateAppointmentRequest.getReservationNumber();
  467. int year = newDateAppointmentRequest.getReservationYear();
  468. //String birthday = "20/06/1968";//data di nascita corvaglia
  469. String birthday = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).format(getBirthdayFromTaxCode(newDateAppointmentRequest.getTaxCode()));
  470.  
  471. LogEx.trace(5, "ng", "AppReq::getNewDateAppointment - codCoupon: " + reservationNumber + ", anno: " + year + ", data nascita: " + birthday);
  472. //creo il gestore dell'interazione con il ws
  473. WSHandler ws = new WSHandler();
  474. //chiamo il ws e gli passo reservationNumber, year, birthday
  475. newDateAppointmentResponse = ws.getNewDateAppointment(reservationNumber, year, birthday);
  476. } catch (Exception e) {
  477. newDateAppointmentResponse = new NewDateAppointmentResponse();
  478. newDateAppointmentResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
  479. LogEx.error(e, "AppReq::getNewDateAppointment() Errore durante il recupero di una nuova data appuntamento");
  480. }
  481. return getNewGson().toJson(newDateAppointmentResponse);
  482. }
  483.  
  484. /**
  485. * Metodo che cambia l'appuntamento dell'assistito
  486. *
  487. * @param request
  488. * @return il nuovo appuntamento
  489. */
  490. @Override
  491. protected String replaceAppointment(HttpServletRequest request) {
  492. ReplaceAppointmentResponse replaceAppointmentResponse;
  493. try {
  494. String receivedObject = request.getParameter("json");
  495. ReplaceAppointmentRequest replaceAppointmentRequest = getNewGson().fromJson(receivedObject, ReplaceAppointmentRequest.class);
  496. if (replaceAppointmentRequest == null) {
  497. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo ReplaceAppointmentRequest");
  498. }
  499.  
  500. if (replaceAppointmentRequest.getUserType() == UserType.REGISTERED) {
  501. //recupero la sessione utente
  502. BaseResponse sessionResponse = checkSession(replaceAppointmentRequest.getSid());
  503. if (sessionResponse != null) {
  504. return getNewGson().toJson(sessionResponse);
  505. }
  506. }
  507. String availabilityId = replaceAppointmentRequest.getAvailabilityId();
  508. long reservationNumber = replaceAppointmentRequest.getReservationNumber();
  509. int year = replaceAppointmentRequest.getReservationYear();
  510. //String birthday = "20/06/1968";//data di nascita corvaglia
  511. String birthday = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).format(getBirthdayFromTaxCode(replaceAppointmentRequest.getTaxCode()));
  512.  
  513. LogEx.trace(5, "ng", "AppReq::replaceAppointment - idDisponibilita: " + availabilityId + ", codCoupon: " + reservationNumber + ", anno: " + year + ", data nascita: " + birthday);
  514. //creo il gestore dell'interazione con il ws
  515. WSHandler ws = new WSHandler();
  516. //chiamo il ws e gli passo availabilityId, reservationNumber, year, birthday
  517. replaceAppointmentResponse = ws.replaceAppointment(availabilityId, reservationNumber, year, birthday);
  518. } catch (Exception e) {
  519. LogEx.error(e, "AppReq::replaceAppointment() Errore durante lo spostamento prenotazione");
  520. replaceAppointmentResponse = new ReplaceAppointmentResponse();
  521. replaceAppointmentResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
  522. }
  523. return getNewGson().toJson(replaceAppointmentResponse);
  524. }
  525.  
  526. /**
  527. * Richiesta della ricetta elettronica a partire dal codice nre
  528. *
  529. * @param request
  530. * @return
  531. */
  532. protected String getElectronicPrescription(HttpServletRequest request) {
  533.  
  534. ElectronicPrescriptionResponse electronicPrescriptionResponse;
  535. try {
  536. String receivedObject = request.getParameter("json");
  537. ElectronicPrescriptionRequest electronicPrescriptionRequest = getNewGson().fromJson(receivedObject, ElectronicPrescriptionRequest.class);
  538. if (electronicPrescriptionRequest == null) {
  539. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo ElectronicPrescriptionRequest");
  540. }
  541.  
  542. /*if (electronicPrescriptionRequest.getUserType() == UserType.REGISTERED) {
  543. //recupero la sessione utente
  544. BaseResponse sessionResponse = checkSession(electronicPrescriptionRequest.getSid());
  545. if (sessionResponse != null) {
  546. return getNewGson().toJson(sessionResponse);
  547. }
  548. }*/
  549. //Recupero i parametri dalla richiesta
  550. String nreCode = electronicPrescriptionRequest.getNreCode();
  551. String taxCode = electronicPrescriptionRequest.getTaxCode();
  552. //Inizializzo il webservice per la richiesta
  553. WSHandlerPrenotazione handlerPrenotazione = new WSHandlerPrenotazione();
  554. //Invio la richiesta
  555. electronicPrescriptionResponse = handlerPrenotazione.getElectronicPrescription(nreCode, taxCode);
  556.  
  557. } catch (Exception e) {
  558. LogEx.error(e, "AppReq::getElectronicPrescription() - Errore durante la richiesta di prestazione elettronica.");
  559. electronicPrescriptionResponse = new ElectronicPrescriptionResponse();
  560. electronicPrescriptionResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
  561. }
  562. return getNewGson().toJson(electronicPrescriptionResponse);
  563. }
  564.  
  565. /**
  566. * Ritorna la lista di appuntamenti prenotabili a partire dalla ricetta nre
  567. *
  568. * @param request
  569. * @return
  570. */
  571. protected String getAvailabilityAppointmens(HttpServletRequest request) {
  572. AvailabilityListAppointmentsResponse availabilityListAppointmentsResponse;
  573.  
  574. try {
  575. String receivedObject = request.getParameter("json");
  576. AvailabilityListAppointmentsRequest availabilityListAppointmentsRequest = getNewGson().fromJson(receivedObject, AvailabilityListAppointmentsRequest.class);
  577. if (availabilityListAppointmentsRequest == null) {
  578. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo availabilityAppointmens");
  579. }
  580.  
  581. /*if (availabilityListAppointmentsRequest.getUserType() == UserType.REGISTERED) {
  582. //recupero la sessione utente
  583. BaseResponse sessionResponse = checkSession(availabilityListAppointmentsRequest.getSid());
  584. if (sessionResponse != null) {
  585. return getNewGson().toJson(sessionResponse);
  586. }
  587. }*/
  588. //Recupero i parametri dalla richiesta
  589. String taxCode = availabilityListAppointmentsRequest.getTaxCode();
  590. String nreCode = availabilityListAppointmentsRequest.getNreCode();
  591. PrescriptionType prescriptionType = availabilityListAppointmentsRequest.getPrescriptionType();
  592. ElectronicPrescription selectedElectronicPrescription = availabilityListAppointmentsRequest.getSelectedElectronicPrescription();
  593. //Inizializzo il webservice per la richiesta
  594. WSHandlerPrenotazione handlerPrenotazione = new WSHandlerPrenotazione();
  595. //Invio la richiesta
  596. availabilityListAppointmentsResponse = handlerPrenotazione.getAvailabilityList(nreCode, taxCode, selectedElectronicPrescription, prescriptionType);
  597.  
  598. } catch (Exception e) {
  599. LogEx.error(e, "AppReq::availabilityAppointmens() - Errore durante la richiesta di prestazione elettronica.");
  600. availabilityListAppointmentsResponse = new AvailabilityListAppointmentsResponse();
  601. availabilityListAppointmentsResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
  602. }
  603.  
  604. return getNewGson().toJson(availabilityListAppointmentsResponse);
  605. }
  606.  
  607. /**
  608. * Prenota l'appuntamento passato e ritorna l'appuntamento scelto la
  609. * prescrizione e informazioni relativamente il paziente che ha prenotato
  610. *
  611. * @param request
  612. * @return
  613. */
  614. @Override
  615. protected String confirmReservation(HttpServletRequest request) {
  616. BaseResponse response = new BaseResponse();
  617.  
  618. try {
  619. String receivedObject = request.getParameter("json");
  620. ReserveAppointmentRequest reserveAppointmentRequest = getNewGson().fromJson(receivedObject, ReserveAppointmentRequest.class);
  621. if (reserveAppointmentRequest == null) {
  622. throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo reserveAppointment");
  623. }
  624.  
  625. /*if (reserveAppointmentRequest.getUserType() == UserType.REGISTERED) {
  626. //recupero la sessione utente
  627. BaseResponse sessionResponse = checkSession(reserveAppointmentRequest.getSid());
  628. if (sessionResponse != null) {
  629. return getNewGson().toJson(sessionResponse);
  630. }
  631. }*/
  632. //Recupero i parametri dalla richiesta
  633. String taxCode = reserveAppointmentRequest.getTaxCode();
  634. NreAppointment selectedAppointment = reserveAppointmentRequest.getSelectedAppointement();
  635. ElectronicPrescription electronicPrescription = reserveAppointmentRequest.getElectronicPrescription();
  636. PrescriptionType prescriptionType = reserveAppointmentRequest.getPrescriptionType();
  637.  
  638. //Inizializzo il webservice per la richiesta
  639. WSHandlerPrenotazione handlerPrenotazione = new WSHandlerPrenotazione();
  640. //Invio la richiesta
  641. response = handlerPrenotazione.reserveAppointment(taxCode, electronicPrescription, selectedAppointment, prescriptionType);
  642.  
  643. } catch (Exception e) {
  644. LogEx.error(e, "AppReq::reserveAppointment() - Errore durante la richiesta di prenotazione.");
  645. response = new AvailabilityListAppointmentsResponse();
  646. response.setResponseDescription("Errore di sistema. Contattare l'amministratore");
  647. }
  648.  
  649. return getNewGson().toJson(response);
  650. }
  651.  
  652. /**
  653. * Estrae la data di nascita di un paziente dal codice fiscale
  654. *
  655. * @param taxCode codice fiscale paziente
  656. * @return la data di nascita estratta
  657. */
  658. private Date getBirthdayFromTaxCode(String taxCode) {
  659. Date birthday = null;
  660. try {
  661. taxCode = taxCode.toUpperCase();
  662.  
  663. Map<String, String> month = new HashMap<>();
  664.  
  665. month.put("A", "01");
  666. month.put("B", "02");
  667. month.put("C", "03");
  668. month.put("D", "04");
  669. month.put("E", "05");
  670. month.put("H", "06");
  671. month.put("L", "07");
  672. month.put("M", "08");
  673. month.put("P", "09");
  674. month.put("R", "10");
  675. month.put("S", "11");
  676. month.put("T", "12");
  677.  
  678. // Get Date
  679. String date = taxCode.substring(6, 11);
  680. Integer y = Integer.parseInt(date.substring(0, 2));
  681. String yy = ((y < 9) ? "20" : "19") + y.toString();
  682. String m = month.get(date.substring(2, 3));
  683. int d = Integer.parseInt(date.substring(3, 5));
  684. if (d > 31) {
  685. d -= 40;
  686. }
  687. String temp = d + "/" + m + "/" + yy;
  688. birthday = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).parse(temp);
  689. } catch (NumberFormatException | ParseException e) {
  690. LogEx.error(e, "AppReq::getBirthdatFromTaxCode() Errore durante l'estrazione della data nascita dal codice fiscale");
  691. }
  692. return birthday;
  693. }
  694.  
  695. /*private String test(HttpServletRequest request) {
  696. WSHandlerPrenotazione wss = new WSHandlerPrenotazione();
  697.  
  698. **
  699. * variabili globali lette dal file di configurazione
  700. *
  701. HashMap<String, String> globalVars;
  702. String taxCode = "";
  703. String nre = "";
  704. String prescriptionType = "";
  705.  
  706. try {
  707. globalVars = GlobalVars.loadGlobalVars("module_notification_result.xml");
  708. taxCode = globalVars.get("taxCode");
  709. nre = globalVars.get("nre");
  710. prescriptionType = globalVars.get("prescriptionType");
  711. } catch (IOException ex) {
  712. Logger.getLogger(AppReq.class.getName()).log(Level.SEVERE, null, ex);
  713. }
  714.  
  715. ElectronicPrescriptionResponse electronicPrescriptionResponse = wss.getElectronicPrescription(nre, taxCode);
  716. AvailabilityListAppointmentsResponse availabilityListAppointmentResponse = wss.getAvailabilityList(nre, taxCode, electronicPrescriptionResponse.getElectronicPrescription(), PrescriptionType.valueOf(prescriptionType));
  717.  
  718. BaseResponse response = new BaseResponse();
  719.  
  720. if (!availabilityListAppointmentResponse.getAppointments().isEmpty()) {
  721. ElectronicPrescription selectedPrescription = electronicPrescriptionResponse.getElectronicPrescription();
  722. selectedPrescription.setNreCode(nre);
  723.  
  724. //TODO: controllare questo
  725. selectedPrescription.setElectronicPrescriptionType(prescriptionType);
  726. NreAppointment selectedAppointment = availabilityListAppointmentResponse.getAppointments().get(0);
  727. response = wss.reserveAppointment(taxCode, selectedPrescription, selectedAppointment);
  728. }
  729.  
  730. return getNewGson().toJson(response);
  731. }*/
  732. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement