public BusinessLayer.Entities.FreeTimeSlot TranslateFreeTimeSlotGPToLocal(Generated.FreeTimeSlot2 freeSlotGP)
        {
            FreeTimeSlot freeSlotLocal = new FreeTimeSlot();

            try
            {
                if (freeSlotGP != null)
                {
                    freeSlotLocal.Begin           = freeSlotGP.StartDate.HasValue ? freeSlotGP.StartDate.Value : DateTime.Today; // necessario validar este campo..colocada data de hoje
                    freeSlotLocal.End             = freeSlotGP.EndDate.HasValue ? freeSlotGP.EndDate.Value : DateTime.Today;
                    freeSlotLocal.HumanResourceId = (int)freeSlotGP.HumanResourceId;
                    freeSlotLocal.Id = freeSlotGP.FreeTimeSlotId;
                    //freeSlotLocal.ClinicalServiceId = freeSlotGP.;
                    freeSlotLocal.MedicalActCode = freeSlotGP.MedicalActId.ToString();
                    freeSlotLocal.CabinetId      = freeSlotGP.LocalCabinetId;
                    freeSlotLocal.ScheduleId     = freeSlotGP.LocalScheduleId;
                    //freeSlotLocal.PersonnelNumber = freeSlotGP.;
                    freeSlotLocal.FacilityId = (int)freeSlotGP.FacilityId;
                    //freeSlotLocal.Group = freeSlotGP.;
                    freeSlotLocal.Duration      = freeSlotGP.Duration.HasValue ? freeSlotGP.Duration.Value : new DateTime();
                    freeSlotLocal.FirstTimeFlag = freeSlotGP.IsFirstTime.HasValue ? freeSlotGP.IsFirstTime.Value : false;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Erro a realizar o convert de FreeTimeSlot (GP) para FreeTimeSlot (local)");
            }

            return(freeSlotLocal);
        }
        public Generated.FreeTimeSlot2 TranslateFreeTimeSlotLocalToGP(BusinessLayer.Entities.FreeTimeSlot freeSlotLocal)
        {
            try
            {
                if (freeSlotLocal != null)
                {
                    Generated.FreeTimeSlot2 freeSlotGP = new Generated.FreeTimeSlot2()
                    {
                        Observations    = freeSlotLocal.Observations,
                        LocalScheduleId = freeSlotLocal.ScheduleId,
                    };

                    if (freeSlotLocal.Id != null && freeSlotLocal.Id != string.Empty)
                    {
                        freeSlotGP.FreeTimeSlotId = freeSlotLocal.Id.ToString();
                    }

                    if (freeSlotLocal.FacilityId != null && freeSlotLocal.FacilityId != 0)
                    {
                        freeSlotGP.FacilityId = (double)freeSlotLocal.FacilityId;
                    }

                    if (freeSlotLocal.FinancialEntityCode != null && freeSlotLocal.FinancialEntityCode != 0)
                    {
                        freeSlotGP.FinancialEntityId = (double)freeSlotLocal.FinancialEntityCode;
                    }

                    if (freeSlotLocal.HumanResourceId != null && freeSlotLocal.HumanResourceId != 0)
                    {
                        freeSlotGP.HumanResourceId = (double)freeSlotLocal.HumanResourceId;
                    }

                    if (!string.IsNullOrEmpty(freeSlotLocal.MedicalActCode))
                    {
                        freeSlotGP.MedicalActId = double.Parse(freeSlotLocal.MedicalActCode);
                    }

                    return(freeSlotGP);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Erro a realizar o convert de FreeTimeSlot (local) para FreeTimeSlot (GP)");
            }

            return(null);
        }
        public async Task <ServiceReturn <ScheduledAppointment> > ScheduleAppointmentForUniquePatientAsync(AuthenticationType tipoAuth, string userId, string facilityId, FreeTimeSlot freeTimeSlotLocal, DateTime efrExpDate, string efrCard, string successMessage = "", string errorMessage = "")
        {
            #region uimessage
            var uiMessages = new Dictionary <string, string>();
            if (!string.IsNullOrEmpty(errorMessage))
            {
                uiMessages.Add(ServiceReturnHandling.GenericMessageKey, errorMessage);
            }
            else
            {
                uiMessages.Add(ServiceReturnHandling.GenericMessageKey, "Não foi possível efetuar a marcação.");
            }
            if (!string.IsNullOrEmpty(successMessage))
            {
                uiMessages.Add(ServiceReturnHandling.SuccessMessageKey, successMessage);
            }
            #endregion

            ScheduledAppointment scheduledAppoint;

            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");

                Generated.AppointmentClient sc = new Generated.AppointmentClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                string group = Configuration.Instance.Configurations["GROUP"];
                Generated.FreeTimeSlot2 freeSlotGP = TranslateFreeTimeSlotLocalToGP(freeTimeSlotLocal);
                int operationTimeOut = 30;
                var res = await sc.ScheduleAppointmentForUniquePatientAsync(freeSlotGP, facilityId, userId, efrCard, efrExpDate, operationTimeOut, GetGPAppVersion());

                if (res != null)
                {
                    scheduledAppoint = TranslateScheduledAppointmentGPToLocal(res.First());
                }
                else
                {
                    throw new Exception();
                }

                return(ServiceReturnHandling.BuildSuccessCallReturn <ScheduledAppointment>(scheduledAppoint, uiMessages));
            }
            catch (Exception ex)
            {
                return(ServiceReturnHandling.HandleException <ScheduledAppointment>(ex, uiMessages));
            }
        }