/// <summary>
        /// Get patient by PIN
        /// </summary>
        /// <param name="pin"></param>
        /// <returns></returns>
        public Patient GetPatient(string pin)
        {
            Patient patinet = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(pin))
                {
                    response = ServiceHelper.GetPOSTResponse(
                        new Uri(SvcUrls.urlGetPatientByPIN), UtilityLibrary.GetValueString(pin));
                }
                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    patinet = JsonConvert.DeserializeObject <Patient>(response.ResponseMessage);
                }
                else
                {
                    patinet = null;
                }
                return(patinet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// validate login credentials of staff member
 /// </summary>
 /// <param name="credentials"></param>
 /// <returns>StaffID</returns>
 public int CheckStaffLogin(Credentials credentials)
 {
     try
     {
         string data = JsonConvert.SerializeObject(credentials);
         response = ServiceHelper.GetPOSTResponse(
             new Uri(SvcUrls.urlCheckStaffLogin), UtilityLibrary.GetValueString(data));
         if (response.HttpStatusCode == HttpStatusCode.OK)
         {
             int resp = JsonConvert.DeserializeObject <int>(response.ResponseMessage);
             if (resp > 0)
             {
                 return(resp);
             }
             else
             {
                 return(0);
             }
         }
         else
         {
             throw new NullReferenceException();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Get patient by PIN
        /// </summary>
        /// <param name="pin"></param>
        /// <returns></returns>
        public Patient GetPatientByPin(string pin)
        {
            Patient result = null;

            try
            {
                response = ServiceHelper.GetPOSTResponse(
                    new Uri(SvcUrls.urlGetPatientByPin), UtilityLibrary.GetValueString(pin));
                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    result = JsonConvert.DeserializeObject <Patient>(response.ResponseMessage);
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// Get Next patient ID
 /// </summary>
 /// <param name="pin"></param>
 /// <returns></returns>
 private int GetNextPatientID()
 {
     try
     {
         response = ServiceHelper.GetPOSTResponse(
             new Uri(SvcUrls.urlGetNextPatientID), string.Empty);
         if (response.HttpStatusCode == HttpStatusCode.OK)
         {
             return(JsonConvert.DeserializeObject <int>(response.ResponseMessage));
         }
         else
         {
             return(0);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 /// <summary>
 /// Get Patient Collection
 /// </summary>
 /// <returns></returns>
 public List <Patient> GetPatientCollection()
 {
     try
     {
         response = ServiceHelper.GetPOSTResponse(
             new Uri(SvcUrls.urlGetPatientCollection), UtilityLibrary.GetValueString(""));
         if (response.HttpStatusCode == HttpStatusCode.OK)
         {
             return(JsonConvert.DeserializeObject <List <Patient> >(response.ResponseMessage));
         }
         else
         {
             throw new NullReferenceException();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Insert/Update patinet and return full atient objact
        /// </summary>
        /// <param name="patient"></param>
        /// <returns></returns>
        public Patient SavePatient(Patient patient)
        {
            Patient result = null;

            try
            {
                string data = JsonConvert.SerializeObject(patient);
                response = ServiceHelper.GetPOSTResponse(
                    new Uri(SvcUrls.urlSavePatient), UtilityLibrary.GetValueString(data));
                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    result = JsonConvert.DeserializeObject <Patient>(response.ResponseMessage);
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Insert new patinet and return full atient objact
        /// </summary>
        /// <param name="patient"></param>
        /// <returns></returns>
        private Patient InsertPatient(Patient patient)
        {
            Patient _patinet = null;

            try
            {
                patient.PatientId = GetNextPatientID();
                patient.PIN       = string.Format("P{0}", UtilityLibrary.GetValueString(patient.PatientId).PadLeft(9, '0'));
                Genaralizepatient(patient);

                if (patient.PatientId > 0)
                {
                    string msg = JsonConvert.SerializeObject(patient);
                    response = ServiceHelper.GetPOSTResponse(
                        new Uri(SvcUrls.urlInsertPatient), UtilityLibrary.GetValueString(msg));
                    if (response.HttpStatusCode == HttpStatusCode.OK)
                    {
                        string result = JsonConvert.DeserializeObject <string>(response.ResponseMessage);
                        if (result == CommonUnit.oSuccess)
                        {
                            _patinet = GetPatient(patient.PatientId);
                        }
                    }
                    else
                    {
                        _patinet = null;
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }

                return(_patinet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        public static ServiceResponseBE GetPOSTResponse(Uri uri, string data)
        {
            ServiceResponseBE respMsg = new ServiceResponseBE();

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

                request.Method      = "POST";
                request.ContentType = "application/json;charset=utf-8";

                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                byte[] bytes = encoding.GetBytes(data);

                request.ContentLength = bytes.Length;

                using (Stream requestStream = request.GetRequestStream())
                {
                    // Send the data.
                    requestStream.Write(bytes, 0, bytes.Length);
                }

                request.BeginGetResponse((x) =>
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(x))
                    {
                        respMsg.HttpStatusCode  = response.StatusCode;
                        Stream responseStream   = response.GetResponseStream();
                        StreamReader sr         = new StreamReader(responseStream);
                        respMsg.ResponseMessage = sr.ReadToEnd();
                    }
                }, null);
            }
            catch (Exception ex)
            {
                respMsg.Error = ex.Message;
            }
            return(respMsg);
        }
        /// <summary>
        /// Deactivate patient
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public bool DeletePatient(int patientId)
        {
            bool deleted = false;

            try
            {
                response = ServiceHelper.GetPOSTResponse(
                    new Uri(SvcUrls.urlDeletePatient), UtilityLibrary.GetValueString(patientId));
                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    string resp = JsonConvert.DeserializeObject <string>(response.ResponseMessage);
                    if (resp == CommonUnit.oSuccess)
                    {
                        deleted = true;
                    }
                }
                return(deleted);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Update patient
        /// </summary>
        /// <param name="patient"></param>
        /// <returns></returns>
        private Patient UpdatePatient(Patient patient)
        {
            try
            {
                Genaralizepatient(patient);

                string msg = JsonConvert.SerializeObject(patient);
                response = ServiceHelper.GetPOSTResponse(
                    new Uri(SvcUrls.urlUpdatePatient), UtilityLibrary.GetValueString(msg));
                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    return(GetPatient(patient.PatientId));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }