public IEnumerable<Patient> GetPatients() {
            var patients = new List<Patient>();
            Exception taskException = null;

            string token = Token;

            var request = new UnityRequest
            {
                Action = "GETCHANGEDPATIENTS",
                Token = token,
                Appname = "web20",
                Parameter1 = "2010-01-01"
            };

            var task = this.PostAsJsonAsync(MagicUrl, request).ContinueWith(x =>
            {
                if (x.IsCanceled)
                    return;

                if (x.IsFaulted)
                {
                    taskException = x.Exception;
                }

                var result = x.Result;
                try
                {
                    result.EnsureSuccessStatusCode();

                    Stream jsonStream = result.Content.ReadAsStreamAsync().Result;
                    var reader = new StreamReader(jsonStream);
                    var jsonSerializer = new JsonSerializer();

                    var json = jsonSerializer.Deserialize<JArray>(new JsonTextReader(reader));
                    var jsonArrayProviders = json[0];
                    int index = 0;
                    foreach (var provider in jsonArrayProviders["getchangedpatientsinfo"]) {
                        if (index > 50)
                            break;
                        var patient = GetPatientDetail(int.Parse(provider.Value<string>("patientid")),
                            token);
                        patients.Add(patient);
                        ++index;
                    }
                }
                catch (Exception statusException)
                {
                    taskException = statusException;
                    throw taskException;
                }
            });

            Task.WaitAll(task);

            if (taskException != null)
                throw taskException;

            return patients;
        }
        public Patient GetPatientDetail(int personId, string token) {
            Patient p = null;

            Exception taskException = null;


            var request = new UnityRequest
            {
                Action = "GETPATIENT",
                Token = token,
                Appname = "web20",
                PatientId = personId.ToString(CultureInfo.InvariantCulture)
            };
            var task = this.PostAsJsonAsync(MagicUrl, request).ContinueWith(x =>
            {
                if (x.IsCanceled)
                    return;

                if (x.IsFaulted)
                {
                    taskException = x.Exception;
                }

                var result = x.Result;
                try
                {
                    result.EnsureSuccessStatusCode();

                    Stream jsonStream = result.Content.ReadAsStreamAsync().Result;
                    var reader = new StreamReader(jsonStream);
                    var jsonSerializer = new JsonSerializer();

                    var json = jsonSerializer.Deserialize<JArray>(new JsonTextReader(reader));
                    var jsonArrayProviders = json[0];
                    foreach (var provider in jsonArrayProviders["getpatientinfo"])
                    {
                        p = new Patient();
                        p.FirstName = provider.Value<string>("Firstname");
                        p.LastName = provider.Value<string>("LastName");
                        p.UnityPersonId = int.Parse(provider.Value<string>("ID"));
                    }
                }
                catch (Exception statusException)
                {
                    taskException = statusException;
                    throw taskException;
                }
            });

            Task.WaitAll(task);

            if (taskException != null)
                throw taskException;

            return p;
        }
        public IEnumerable<Doctor> GetDoctors() {
            var doctors = new List<Doctor>();

            Exception taskException = null;

            var request = new UnityRequest {
                Action = "GETPROVIDERS",
                Token = Token,
                Appname = "web20"
            };

            var task = this.PostAsJsonAsync(MagicUrl, request).ContinueWith(x => {
                if (x.IsCanceled)
                    return;

                if (x.IsFaulted) {
                    taskException = x.Exception;
                }

                var result = x.Result;
                try {
                    result.EnsureSuccessStatusCode();

                    Stream jsonStream = result.Content.ReadAsStreamAsync().Result;
                    var reader = new StreamReader(jsonStream);
                    var jsonSerializer = new JsonSerializer();

                    var json = jsonSerializer.Deserialize<JArray>(new JsonTextReader(reader));
                    var jsonArrayProviders = json[0];
                    foreach (var provider in jsonArrayProviders["getprovidersinfo"])
                    {
                        var doctor = new Doctor();
                        doctor.FirstName = provider.Value<string>("FirstName");
                        doctor.UnityPersonId = provider.Value<int>("personid");
                        doctors.Add(doctor);
                    }
                }
                catch (Exception statusException) {
                    taskException = statusException;
                    throw taskException;
                } 
            });

            Task.WaitAll(task);

            if (taskException != null)
                throw taskException;

            return doctors;
        }