Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.itel.nsweb.business.cuprecall_asltaranto;
- import com.google.gson.Gson;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.ReserveAppointmentRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.AvailabilityListAppointmentsRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.DeleteReservationRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.ElectronicPrescriptionRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.NewDateAppointmentRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.PatientAppointmentsRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.request.ReplaceAppointmentRequest;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.AvailabilityListAppointmentsResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.DeleteReservationResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.ElectronicPrescriptionResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.LoginResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.NewDateAppointmentResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.PatientAppointmentsResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.communication.response.ReplaceAppointmentResponse;
- import com.itel.nsweb.business.cuprecall_asltaranto.enums.PrescriptionType;
- import com.itel.nsweb.business.cuprecall_asltaranto.modeldata.medicalexamination_nre.ElectronicPrescription;
- import com.itel.nsweb.business.cuprecall_asltaranto.modeldata.medicalexamination_nre.NreAppointment;
- import com.itel.nsweb.core.common.apps.AppConfigManagement;
- import com.itel.nsweb.core.common.apps.communication.response.BaseResponse;
- import com.itel.nsweb.core.common.apps.enumeration.ResponseStatus;
- import com.itel.nsweb.core.common.apps.session.AppSession;
- import com.itel.nsweb.core.cuprecall.communication.response.SyncDataResponse;
- import com.itel.nsweb.core.cuprecall.enumeration.UserType;
- import com.itel.nsweb.core.cuprecall.modeldata.Patient;
- import com.itel.nsweb.core.cuprecall.modeldata.User;
- import com.itel.nsweb.core.cuprecall.enumeration.GradientType;
- import com.itel.nsweb.core.cuprecall.enumeration.LoginType;
- import com.itel.nsweb.core.cuprecall.modeldata.Company;
- import com.itel.nsweb.core.cuprecall.modeldata.style.CompanyStyle;
- import com.itel.nsweb.core.cuprecall.modeldata.style.Gradient;
- import com.itel.smartsuite.tools.datetime.DateTimeFunctions;
- import com.itel.smartsuite.tools.xmlloading.GlobalVars;
- import com.rsp.toolbox.tools.LogEx;
- import com.rsp.toolbox.tools.WebEx;
- import java.io.IOException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.HttpVersion;
- import org.apache.http.client.config.RequestConfig;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPatch;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.params.BasicHttpParams;
- import org.apache.http.params.HttpParams;
- import org.apache.http.util.EntityUtils;
- import org.json.JSONException;
- import org.json.JSONObject;
- /**
- * Classe per le richieste provenienti dalle app
- *
- * @author Mirko Budano
- * @author Matteo Gramellini
- *
- * "http://localhost:8084/voipsmartsuite/wgate?typereq=apprequest&classname=com.itel.nsweb.business.cuprecall_asltaranto.AppReq&requestnumber=301"
- *
- * #GET APPUNTAMENTI
- * "http://localhost:8084/voipsmartsuite/wgate?typereq=apprequest&classname=com.itel.nsweb.business.cuprecall_asltaranto.AppReq&requestnumber=310&codiceAssistito=GVNFNC68D14A662T"
- *
- * #GET NUOVA DATA APPUNTAMENTO
- * "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"
- *
- * #SOSTITUISCI APPUNTAMENTO
- * "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"
- *
- *
- */
- public class AppReq extends com.itel.nsweb.core.cuprecall.AppReq {
- /**
- * modulo xml dove recuperare i parametri di comunicazione con il sistema
- * esterno
- */
- protected String confFileName = "module_business_app_cuprecall.xml";
- /**
- * elenco delle variabili di configurazione dell'app caricate da xml
- */
- protected List<HashMap<String, HashMap<String, String>>> appConfig = null;
- /**
- * indica se è stato inizializzato correttamente
- */
- private boolean isInitialized = false;
- private final static String ITALIAN_DATE_PATTERN = "dd/MM/yyyy";
- public AppReq() {
- super();
- appConfig = AppConfigManagement.getAppConfig(confFileName);
- if (appConfig != null) {
- isInitialized = true;
- }
- }
- public boolean isInitialized() {
- return isInitialized;
- }
- @Override
- protected String executeCustomRequest(int requestNumber, HttpServletRequest request) {
- String res;
- switch (requestNumber) {
- case 300: // sincronizza i dati di configurazione dell'app
- res = syncData(request);
- break;
- case 301: //metodo per effettuare il login
- res = login(request);
- break;
- case 310: //recupera gli appuntamenti dell'assistito
- res = getPatientAppointments(request);
- break;
- case 311: //cancella una prenotazione
- res = deleteReservation(request);
- break;
- case 320: // recupura una nuova disponibilità per l'appuntamento
- res = getNewDateAppointment(request);
- break;
- case 321: // sostituisce la vecchia data di un appuntamento con una nuova disponibile
- res = replaceAppointment(request);
- break;
- case 322: //Ritorna la prestazione elettronica associata alla ricetta
- res = getElectronicPrescription(request);
- break;
- case 323: //Ritorna la disponibilità degli appuntamenti
- res = getAvailabilityAppointmens(request);
- break;
- case 324: //Conferma una prenotazione
- res = confirmReservation(request);
- break;
- case 999: //Utilizzato per i test
- res = testLogin();
- break;
- default:
- res = super.executeCustomRequest(requestNumber, request);
- }
- return res;
- }
- /**
- * questo metodo viene chiamato dopo aver chiamato il metodo trig per
- * settare il tipo di contenuto inviato come risposta. Di default usa
- * text/xml;charset=UTF-8
- *
- * @param response
- */
- @Override
- public void setResponseContentType(HttpServletResponse response) {
- response.setContentType("text/html;charset=UTF-8");
- }
- /**
- * metodo invocato per la sincronizzazione dei dati di configurazione
- * dell'app
- *
- * @param request
- * @return risultato della richiesta di sincronizzazione dei dati
- */
- @Override
- protected String syncData(HttpServletRequest request) {
- SyncDataResponse syncDataResponse;
- if (!isInitialized) {
- LogEx.trace(3, "syncData", "Errore durante l'inizializzazione delle variabili da " + confFileName);
- syncDataResponse = new SyncDataResponse();
- syncDataResponse.setResponseDescription("Errore durante l'inizializzazione dell'app");
- return getNewGson().toJson(syncDataResponse);
- }
- try {
- List<Company> companies = new ArrayList<>();
- for (HashMap<String, HashMap<String, String>> company : appConfig) {
- CompanyStyle companyStyle = null;
- HashMap<String, String> style = company.get("style");
- if (style != null && style.size() > 0) {
- String sGradientType = style.get("gradient_type");
- int iGradientType = 0; // setto di default il gradient linear
- if (sGradientType != null) {
- iGradientType = Integer.valueOf(sGradientType);
- }
- GradientType gradientType = GradientType.getFromInt(iGradientType);
- Gradient gradient = new Gradient(style.get("start_color"), style.get("center_Color"), style.get("end_color"), gradientType);
- 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);
- }
- HashMap<String, String> data = company.get("data");
- if (data != null && data.size() > 0) {
- String companyCode = data.get("company_code");
- String companyName = data.get("company_name");
- String loginUrl = data.get("login_url");
- String logoUrl = data.get("logo_url");
- String sLoginType = data.get("login_type");
- int iLoginType = 0; // setto di default il login local
- if (sLoginType != null) {
- iLoginType = Integer.valueOf(sLoginType);
- }
- LoginType loginType = LoginType.getFromInt(iLoginType);
- companies.add(new Company(companyCode, companyName, logoUrl, loginUrl, loginType, companyStyle));
- }
- }
- if (companies.size() > 0) {
- syncDataResponse = new SyncDataResponse(companies);
- syncDataResponse.setStatus(ResponseStatus.OK);
- } else {
- syncDataResponse = new SyncDataResponse();
- syncDataResponse.setResponseDescription("Errore durante il caricamento dei dati di configurazione");
- }
- } catch (NumberFormatException e) {
- syncDataResponse = new SyncDataResponse();
- syncDataResponse.setResponseDescription("Errore durante il recupero dei dati di configurazione");
- LogEx.error(e, "Errore durante il recupero dei dati di configurazione");
- }
- return getNewGson().toJson(syncDataResponse);
- }
- /**
- * metodo invocato dopo il login fatto con shibboleth
- *
- * @param request
- * @return pagina html con la 'response' della chiamata
- */
- @Override
- public String login(HttpServletRequest request) {
- Gson g = getNewGson();
- String ret;
- 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"
- + "if(/android/i.test(userAgent)){return\"Android\";}\n"
- + "if(/iPad|iPhone|iPod/.test(userAgent)&&!window.MSStream){return\"iOS\";}\n"
- + "return\"unknown\";}\n"
- + "function sendResult(result){var os=getMobileOperatingSystem();if(os==\"Android\"){Android.getResult(result);}"
- + "else if(os==\"iOS\"){var resultToLogin={'result':result};window.webkit.messageHandlers.callbackHandler.postMessage(resultToLogin);}}</script>";
- LoginResponse response = new LoginResponse();
- try {
- //uso questa stringa per stampare le coppie chiave-valore dell'header nel caso in cui il login non abbia successo
- String headerLog = "";
- //loggo tutti gli header che mi arrivano per DEBUG
- Enumeration headerNames = request.getHeaderNames();
- while (headerNames.hasMoreElements()) {
- String key = (String) headerNames.nextElement();
- String value = request.getHeader(key);
- headerLog += key + ":" + value + ";";//aggiungo la coppia chiave:valore alla stringa di log
- LogEx.trace(6, "ng", "AppReq::login() Header - " + key + ": " + value);
- }
- //flag che indica se sono loggato con successo
- boolean loginOk = false;
- //provo a recuperare lo spincode
- String spinCode = request.getHeader("spidcode");
- //definisco taxCode, name, birthday, email
- String taxCode = "", name = "", email = "";
- Date birthday = null;
- //se spinCode non è null ed è valorizzato allora il login è con SPID
- if (spinCode != null && !spinCode.isEmpty()) {
- //AUTENTICAZIONE CON IDP
- //prendo il codice fiscale
- taxCode = WebEx.StringToHTTPParam(request.getHeader("fiscalnumber"));
- //per sicurezza aggiungo un controllo, se mi arriva un trattino prendo la seconda parte (durante i test mi è arrivato come codice fiscale TINIT-STTRLI70A01F205L)
- if (taxCode.contains("-")) {
- //se per sbaglio ho un trattino faccio lo split e prendo la seconda parte
- taxCode = taxCode.split("-")[1];
- }
- //prendo cognome e nome del paziente
- name = WebEx.StringToHTTPParam(request.getHeader("familyname")) + " " + WebEx.StringToHTTPParam(request.getHeader("name"));
- //prendo la data di nascita
- birthday = DateTimeFunctions.getDateFromString(WebEx.StringToHTTPParam(request.getHeader("dateofbirth")), "yyyy-MM-dd");
- //prendo l'email
- email = WebEx.StringToHTTPParam(request.getHeader("mail"));
- //setto il flag loginOk a true
- loginOk = true;
- } else if ("TRUE".equalsIgnoreCase(request.getHeader("useridentified")) && "TRUE".equalsIgnoreCase(request.getHeader("userenabled"))) {
- //AUTENTICAZIONE CON IDP (Portale Regionale Puglia)
- //prendo il codice fiscale
- taxCode = WebEx.StringToHTTPParam(request.getHeader("codicefiscale"));
- //prendo nome cognome
- name = WebEx.StringToHTTPParam(request.getHeader("cognome")) + " " + WebEx.StringToHTTPParam(request.getHeader("nome"));
- //prendo la data di nascita
- birthday = DateTimeFunctions.getDateFromString(WebEx.StringToHTTPParam(request.getHeader("datanascita")), ITALIAN_DATE_PATTERN);
- //prendo l'email
- email = WebEx.StringToHTTPParam(request.getHeader("mail"));
- //setto il flag loginOk a true
- loginOk = true;
- } else {
- //stampo un log basso con i valori ricevuti nella response
- LogEx.trace(1, "ng", "AppReq::login() Utente non abilitato. Coppie chiave:valore ricevute nella response " + headerLog);
- response.setResponseDescription("Utente non abilitato ad accedere ai servizi");
- }
- //se loginOk è true
- if (loginOk) {
- //creo la sessione(nel costruttore la aggiunge anche alla lista delle sessioni)
- AppSession session = new AppSession(name);
- //mi viene passato un solo paziente
- Patient patient = new Patient(taxCode, name, birthday, email);
- List<Patient> patientsAssociated = new ArrayList<>();
- patientsAssociated.add(patient);
- //creo User
- User user = new User(session.getSid(), UserType.REGISTERED, patientsAssociated);
- //setto id di sessione nella response
- response.setUser(user);
- response.setStatus(ResponseStatus.OK);
- LogEx.trace(5, "ng", "AppReq::login() Login effettuato con successo, codice fiscale ricevuto: " + taxCode);
- }
- } catch (Exception e) {
- LogEx.error(e, "AppReq::login() Errore durante il parse del risultato ottenuto da shibboleth");
- response.setResponseDescription("Errore di sistema. Contattare l'assistenza");
- } finally {
- ret = "<!DOCTYPE html><html><head>" + javascript + "</head><body onload='sendResult(\"" + g.toJson(response).replace("\"", "\\\"") + "\")'></body></html>";
- }
- return ret;
- }
- public String testLogin() {
- LoginResponse response = new LoginResponse();
- //creo la sessione(nel costruttore la aggiunge anche alla lista delle sessioni)
- AppSession session = new AppSession("prova");
- //mi viene passato un solo paziente
- Patient patient = new Patient("PNTLNZ89B17G479T", "Lorenzo", new Date(), "prova@libero.it");
- List<Patient> patientsAssociated = new ArrayList<>();
- patientsAssociated.add(patient);
- //creo User
- User user = new User(session.getSid(), UserType.REGISTERED, patientsAssociated);
- //setto id di sessione nella response
- LogEx.trace(5, "ng", "AppReq::testLogin() Login effettuato con successo");
- response.setUser(user);
- return getNewGson().toJson(response);
- }
- /**
- * metodo che ritorna gli appuntamenti dell'assistito
- *
- * @param request
- * @return l'oggetto contenente l'elenco degli appuntamenti associati
- * all'assistito
- */
- @Override
- protected String getPatientAppointments(HttpServletRequest request) {
- PatientAppointmentsResponse response;
- try {
- String receivedObject = request.getParameter("json");
- PatientAppointmentsRequest patientAppointmentsRequest = getNewGson().fromJson(receivedObject, PatientAppointmentsRequest.class);
- if (patientAppointmentsRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo PatientAppointmentsRequest");
- }
- //recupero la sessione utente
- /*BaseResponse sessionResponse = checkSession(patientAppointmentsRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }*/
- //prendo il codice fiscale dalla richiesta
- String taxCode = patientAppointmentsRequest.getTaxCode();
- //String taxCode = "CRVRRT68H20H147R";
- String startDate = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).format(patientAppointmentsRequest.getStartDate());
- LogEx.trace(5, "ng", "AppReq::getPatientAppointments - taxCode: " + taxCode);
- LogEx.trace(5, "ng", "AppReq::getPatientAppointments - startDate: " + startDate);
- //creo il gestore dell'interazione con il ws
- WSHandler ws = new WSHandler();
- //chiamo il ws e gli passo codiceAssistito, dataInizio
- response = ws.getPatientAppointments(taxCode, startDate);
- } catch (Exception e) {
- response = new PatientAppointmentsResponse();
- response.setResponseDescription("Errore di sistema. Contattare l'assistenza");
- LogEx.error(e, "AppReq::getPatientAppointments() Errore durante il recupero degli appuntamenti per l'assistito");
- }
- return getNewGson().toJson(response);
- }
- /**
- * metodo che cancella la prenotazione
- *
- * @param request
- * @return il risultato della cancellazione
- */
- @Override
- protected String deleteReservation(HttpServletRequest request) {
- DeleteReservationResponse deleteReservationResponse;
- try {
- String receivedObject = request.getParameter("json");
- DeleteReservationRequest deleteReservationRequest = getNewGson().fromJson(receivedObject, DeleteReservationRequest.class);
- if (deleteReservationRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo DeleteReservationRequest");
- }
- // solo se l'utente è registrato
- if (deleteReservationRequest.getUserType() == UserType.REGISTERED) {
- //recupero la sessione utente
- BaseResponse sessionResponse = checkSession(deleteReservationRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }
- }
- long reservationNumber = deleteReservationRequest.getReservationNumber();
- int cancellationReason = deleteReservationRequest.getCancellationReason();
- int reservationYear = deleteReservationRequest.getReservationYear();
- String taxCode = deleteReservationRequest.getTaxCode();
- //String taxCode = "CRVRRT68H20H147R";
- //Date birthday = deleteReservationRequest.getBirthday();
- Date birthday = getBirthdayFromTaxCode(taxCode);
- LogEx.trace(5, "ng", "AppReq::deleteReservation - codCoupon: " + reservationNumber + ", anno: " + reservationYear + ", codice fiscale: " + taxCode);
- //creo il gestore dell'interazione con il ws
- WSHandler ws = new WSHandler();
- deleteReservationResponse = ws.deleteReservation(reservationNumber, cancellationReason, reservationYear, birthday);
- } catch (Exception e) {
- deleteReservationResponse = new DeleteReservationResponse();
- deleteReservationResponse.setResponseDescription("Errore di sistema. Contattare l'assistenza");
- LogEx.error(e, "Errore durante la cancellazione della prenotazione");
- }
- return getNewGson().toJson(deleteReservationResponse);
- }
- /**
- * Metodo che ritorna una nuova data appuntamento per l'assistito
- *
- * @param request
- * @return un oggetto di tipo NewDateAppointmentResponse con la data di
- * nuova disponibilità
- */
- @Override
- protected String getNewDateAppointment(HttpServletRequest request) {
- NewDateAppointmentResponse newDateAppointmentResponse;
- try {
- String receivedObject = request.getParameter("json");
- NewDateAppointmentRequest newDateAppointmentRequest = getNewGson().fromJson(receivedObject, NewDateAppointmentRequest.class);
- if (newDateAppointmentRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo NewDateAppointmentRequest");
- }
- if (newDateAppointmentRequest.getUserType() == UserType.REGISTERED) {
- //recupero la sessione utente
- BaseResponse sessionResponse = checkSession(newDateAppointmentRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }
- }
- long reservationNumber = newDateAppointmentRequest.getReservationNumber();
- int year = newDateAppointmentRequest.getReservationYear();
- //String birthday = "20/06/1968";//data di nascita corvaglia
- String birthday = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).format(getBirthdayFromTaxCode(newDateAppointmentRequest.getTaxCode()));
- LogEx.trace(5, "ng", "AppReq::getNewDateAppointment - codCoupon: " + reservationNumber + ", anno: " + year + ", data nascita: " + birthday);
- //creo il gestore dell'interazione con il ws
- WSHandler ws = new WSHandler();
- //chiamo il ws e gli passo reservationNumber, year, birthday
- newDateAppointmentResponse = ws.getNewDateAppointment(reservationNumber, year, birthday);
- } catch (Exception e) {
- newDateAppointmentResponse = new NewDateAppointmentResponse();
- newDateAppointmentResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
- LogEx.error(e, "AppReq::getNewDateAppointment() Errore durante il recupero di una nuova data appuntamento");
- }
- return getNewGson().toJson(newDateAppointmentResponse);
- }
- /**
- * Metodo che cambia l'appuntamento dell'assistito
- *
- * @param request
- * @return il nuovo appuntamento
- */
- @Override
- protected String replaceAppointment(HttpServletRequest request) {
- ReplaceAppointmentResponse replaceAppointmentResponse;
- try {
- String receivedObject = request.getParameter("json");
- ReplaceAppointmentRequest replaceAppointmentRequest = getNewGson().fromJson(receivedObject, ReplaceAppointmentRequest.class);
- if (replaceAppointmentRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo ReplaceAppointmentRequest");
- }
- if (replaceAppointmentRequest.getUserType() == UserType.REGISTERED) {
- //recupero la sessione utente
- BaseResponse sessionResponse = checkSession(replaceAppointmentRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }
- }
- String availabilityId = replaceAppointmentRequest.getAvailabilityId();
- long reservationNumber = replaceAppointmentRequest.getReservationNumber();
- int year = replaceAppointmentRequest.getReservationYear();
- //String birthday = "20/06/1968";//data di nascita corvaglia
- String birthday = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).format(getBirthdayFromTaxCode(replaceAppointmentRequest.getTaxCode()));
- LogEx.trace(5, "ng", "AppReq::replaceAppointment - idDisponibilita: " + availabilityId + ", codCoupon: " + reservationNumber + ", anno: " + year + ", data nascita: " + birthday);
- //creo il gestore dell'interazione con il ws
- WSHandler ws = new WSHandler();
- //chiamo il ws e gli passo availabilityId, reservationNumber, year, birthday
- replaceAppointmentResponse = ws.replaceAppointment(availabilityId, reservationNumber, year, birthday);
- } catch (Exception e) {
- LogEx.error(e, "AppReq::replaceAppointment() Errore durante lo spostamento prenotazione");
- replaceAppointmentResponse = new ReplaceAppointmentResponse();
- replaceAppointmentResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
- }
- return getNewGson().toJson(replaceAppointmentResponse);
- }
- /**
- * Richiesta della ricetta elettronica a partire dal codice nre
- *
- * @param request
- * @return
- */
- protected String getElectronicPrescription(HttpServletRequest request) {
- ElectronicPrescriptionResponse electronicPrescriptionResponse;
- try {
- String receivedObject = request.getParameter("json");
- ElectronicPrescriptionRequest electronicPrescriptionRequest = getNewGson().fromJson(receivedObject, ElectronicPrescriptionRequest.class);
- if (electronicPrescriptionRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo ElectronicPrescriptionRequest");
- }
- /*if (electronicPrescriptionRequest.getUserType() == UserType.REGISTERED) {
- //recupero la sessione utente
- BaseResponse sessionResponse = checkSession(electronicPrescriptionRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }
- }*/
- //Recupero i parametri dalla richiesta
- String nreCode = electronicPrescriptionRequest.getNreCode();
- String taxCode = electronicPrescriptionRequest.getTaxCode();
- //Inizializzo il webservice per la richiesta
- WSHandlerPrenotazione handlerPrenotazione = new WSHandlerPrenotazione();
- //Invio la richiesta
- electronicPrescriptionResponse = handlerPrenotazione.getElectronicPrescription(nreCode, taxCode);
- } catch (Exception e) {
- LogEx.error(e, "AppReq::getElectronicPrescription() - Errore durante la richiesta di prestazione elettronica.");
- electronicPrescriptionResponse = new ElectronicPrescriptionResponse();
- electronicPrescriptionResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
- }
- return getNewGson().toJson(electronicPrescriptionResponse);
- }
- /**
- * Ritorna la lista di appuntamenti prenotabili a partire dalla ricetta nre
- *
- * @param request
- * @return
- */
- protected String getAvailabilityAppointmens(HttpServletRequest request) {
- AvailabilityListAppointmentsResponse availabilityListAppointmentsResponse;
- try {
- String receivedObject = request.getParameter("json");
- AvailabilityListAppointmentsRequest availabilityListAppointmentsRequest = getNewGson().fromJson(receivedObject, AvailabilityListAppointmentsRequest.class);
- if (availabilityListAppointmentsRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo availabilityAppointmens");
- }
- /*if (availabilityListAppointmentsRequest.getUserType() == UserType.REGISTERED) {
- //recupero la sessione utente
- BaseResponse sessionResponse = checkSession(availabilityListAppointmentsRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }
- }*/
- //Recupero i parametri dalla richiesta
- String taxCode = availabilityListAppointmentsRequest.getTaxCode();
- String nreCode = availabilityListAppointmentsRequest.getNreCode();
- PrescriptionType prescriptionType = availabilityListAppointmentsRequest.getPrescriptionType();
- ElectronicPrescription selectedElectronicPrescription = availabilityListAppointmentsRequest.getSelectedElectronicPrescription();
- //Inizializzo il webservice per la richiesta
- WSHandlerPrenotazione handlerPrenotazione = new WSHandlerPrenotazione();
- //Invio la richiesta
- availabilityListAppointmentsResponse = handlerPrenotazione.getAvailabilityList(nreCode, taxCode, selectedElectronicPrescription, prescriptionType);
- } catch (Exception e) {
- LogEx.error(e, "AppReq::availabilityAppointmens() - Errore durante la richiesta di prestazione elettronica.");
- availabilityListAppointmentsResponse = new AvailabilityListAppointmentsResponse();
- availabilityListAppointmentsResponse.setResponseDescription("Errore di sistema. Contattare l'amministratore");
- }
- return getNewGson().toJson(availabilityListAppointmentsResponse);
- }
- /**
- * Prenota l'appuntamento passato e ritorna l'appuntamento scelto la
- * prescrizione e informazioni relativamente il paziente che ha prenotato
- *
- * @param request
- * @return
- */
- @Override
- protected String confirmReservation(HttpServletRequest request) {
- BaseResponse response = new BaseResponse();
- try {
- String receivedObject = request.getParameter("json");
- ReserveAppointmentRequest reserveAppointmentRequest = getNewGson().fromJson(receivedObject, ReserveAppointmentRequest.class);
- if (reserveAppointmentRequest == null) {
- throw new Exception("Errore nella deserializzazione dell'oggetto json di tipo reserveAppointment");
- }
- /*if (reserveAppointmentRequest.getUserType() == UserType.REGISTERED) {
- //recupero la sessione utente
- BaseResponse sessionResponse = checkSession(reserveAppointmentRequest.getSid());
- if (sessionResponse != null) {
- return getNewGson().toJson(sessionResponse);
- }
- }*/
- //Recupero i parametri dalla richiesta
- String taxCode = reserveAppointmentRequest.getTaxCode();
- NreAppointment selectedAppointment = reserveAppointmentRequest.getSelectedAppointement();
- ElectronicPrescription electronicPrescription = reserveAppointmentRequest.getElectronicPrescription();
- PrescriptionType prescriptionType = reserveAppointmentRequest.getPrescriptionType();
- //Inizializzo il webservice per la richiesta
- WSHandlerPrenotazione handlerPrenotazione = new WSHandlerPrenotazione();
- //Invio la richiesta
- response = handlerPrenotazione.reserveAppointment(taxCode, electronicPrescription, selectedAppointment, prescriptionType);
- } catch (Exception e) {
- LogEx.error(e, "AppReq::reserveAppointment() - Errore durante la richiesta di prenotazione.");
- response = new AvailabilityListAppointmentsResponse();
- response.setResponseDescription("Errore di sistema. Contattare l'amministratore");
- }
- return getNewGson().toJson(response);
- }
- /**
- * Estrae la data di nascita di un paziente dal codice fiscale
- *
- * @param taxCode codice fiscale paziente
- * @return la data di nascita estratta
- */
- private Date getBirthdayFromTaxCode(String taxCode) {
- Date birthday = null;
- try {
- taxCode = taxCode.toUpperCase();
- Map<String, String> month = new HashMap<>();
- month.put("A", "01");
- month.put("B", "02");
- month.put("C", "03");
- month.put("D", "04");
- month.put("E", "05");
- month.put("H", "06");
- month.put("L", "07");
- month.put("M", "08");
- month.put("P", "09");
- month.put("R", "10");
- month.put("S", "11");
- month.put("T", "12");
- // Get Date
- String date = taxCode.substring(6, 11);
- Integer y = Integer.parseInt(date.substring(0, 2));
- String yy = ((y < 9) ? "20" : "19") + y.toString();
- String m = month.get(date.substring(2, 3));
- int d = Integer.parseInt(date.substring(3, 5));
- if (d > 31) {
- d -= 40;
- }
- String temp = d + "/" + m + "/" + yy;
- birthday = new SimpleDateFormat(ITALIAN_DATE_PATTERN, Locale.ITALY).parse(temp);
- } catch (NumberFormatException | ParseException e) {
- LogEx.error(e, "AppReq::getBirthdatFromTaxCode() Errore durante l'estrazione della data nascita dal codice fiscale");
- }
- return birthday;
- }
- /*private String test(HttpServletRequest request) {
- WSHandlerPrenotazione wss = new WSHandlerPrenotazione();
- **
- * variabili globali lette dal file di configurazione
- *
- HashMap<String, String> globalVars;
- String taxCode = "";
- String nre = "";
- String prescriptionType = "";
- try {
- globalVars = GlobalVars.loadGlobalVars("module_notification_result.xml");
- taxCode = globalVars.get("taxCode");
- nre = globalVars.get("nre");
- prescriptionType = globalVars.get("prescriptionType");
- } catch (IOException ex) {
- Logger.getLogger(AppReq.class.getName()).log(Level.SEVERE, null, ex);
- }
- ElectronicPrescriptionResponse electronicPrescriptionResponse = wss.getElectronicPrescription(nre, taxCode);
- AvailabilityListAppointmentsResponse availabilityListAppointmentResponse = wss.getAvailabilityList(nre, taxCode, electronicPrescriptionResponse.getElectronicPrescription(), PrescriptionType.valueOf(prescriptionType));
- BaseResponse response = new BaseResponse();
- if (!availabilityListAppointmentResponse.getAppointments().isEmpty()) {
- ElectronicPrescription selectedPrescription = electronicPrescriptionResponse.getElectronicPrescription();
- selectedPrescription.setNreCode(nre);
- //TODO: controllare questo
- selectedPrescription.setElectronicPrescriptionType(prescriptionType);
- NreAppointment selectedAppointment = availabilityListAppointmentResponse.getAppointments().get(0);
- response = wss.reserveAppointment(taxCode, selectedPrescription, selectedAppointment);
- }
- return getNewGson().toJson(response);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement