Exemplo n.º 1
0
 public static SYS_MedicalEntity GetDoctorEntity(IObjectSet<SYS_MedicalEntity> dbSet, Doctor doctor)
 {
     var result = doctor == null ? null
         : (dbSet.FirstOrDefault(me => me.Name == doctor.MedicalEntityName && me.Code == doctor.MedicalEntityCode)
         ?? dbSet.FirstOrDefault(me => me.Name == doctor.MedicalEntityName)
         ?? dbSet.FirstOrDefault(me => me.Code == doctor.MedicalEntityCode));
     return result;
 }
Exemplo n.º 2
0
 public static SYS_MedicalSpecialty GetDoctorSpecialty(IObjectSet<SYS_MedicalSpecialty> dbSet, Doctor doctor)
 {
     var result = doctor == null ? null
         : (dbSet.FirstOrDefault(ms => ms.Name == doctor.MedicalSpecialtyName && ms.Code == doctor.MedicalSpecialtyCode)
         ?? dbSet.FirstOrDefault(ms => ms.Name == doctor.MedicalSpecialtyName)
         // Note: Code has dupplicates in the database.
         ?? dbSet.FirstOrDefault(ms => ms.Code == doctor.MedicalSpecialtyCode));
     return result;
 }
Exemplo n.º 3
0
        public void InitDoctor()
        {
            if (this.wasInitDoctorCalled)
                return;

            this.wasInitDoctorCalled = true;

            // the URL's doctor identifier (doctor's name)
            var doctorIdentifier = this.RouteData.Values["doctor"] as string;

            // Getting list of all doctors in this practice.
            var allDoctors = this.db.Doctors
                .Include("Users")
                .Include("Users.Person")
                .ToList();

            // Resolved: uniqueness of UrlIdentifier is ensured.
            // issue: 2 doctors with the same name would cause this query to fail
            // the doctor being visualized (not the user as a doctor)
            var doctor = allDoctors
                .FirstOrDefault(d => d.UrlIdentifier == doctorIdentifier);

            Debug.Assert(doctor != null, "doctor must not be null");
            //if (doctor == null)
            //    return;

            this.Doctor = doctor;

            var doctorViewModels = allDoctors.Select(doc => new DoctorViewModel
                {
                    Id = doc.Id,
                    Name = doc.Users.ElementAt(0).Person.FullName,
                    UrlIdentifier = doc.UrlIdentifier,
                    ImageUrl = GravatarHelper.GetGravatarUrl(doc.Users.ElementAt(0).Person.EmailGravatarHash, GravatarHelper.Size.s32),
                    CRM = doc.CRM,
                    MedicalSpecialty = doc.MedicalSpecialtyName,
                    IsScheduleConfigured = doc.CFG_Schedule != null,
                    MedicalEntity = string.Format(
                        string.IsNullOrEmpty(doc.MedicalEntityJurisdiction) ? "{0}" : "{0}-{1}",
                        doc.MedicalEntityCode,
                        doc.MedicalEntityJurisdiction),
                })
                .ToList();

            this.ViewBag.Doctor = doctorViewModels.FirstOrDefault(doc => doc.Id == doctor.Id);

            this.ViewBag.AllDoctors = doctorViewModels;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fills a new doctor with common useful data: default medical-certificates and a default health-insurance.
        /// </summary>
        /// <param name="doctor">The new doctor to receive some useful objects to work with.</param>
        public static void FillNewDoctorUtilityBelt(Doctor doctor)
        {
            {
                var medicalCertificate = new ModelMedicalCertificate
                {
                    Name = "Comparecimento em consulta",
                    Text = "O paciente <%Paciente%> compareceu a uma consulta no horário de <%HoraInicio%> até <%HoraFim%>.",
                    PracticeId = doctor.PracticeId,
                };
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "HoraInicio", PracticeId = doctor.PracticeId, });
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "HoraFim", PracticeId = doctor.PracticeId, });

                doctor.ModelMedicalCertificates.Add(medicalCertificate);
            }

            {
                var medicalCertificate = new ModelMedicalCertificate
                {
                    Name = "Paciente necessita repouso",
                    Text = "O paciente <%Paciente%> necessita de repouso do dia <%DiaInicio%> até o dia <%DiaFim%>.",
                    PracticeId = doctor.PracticeId,
                };
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "DiaInicio", PracticeId = doctor.PracticeId, });
                medicalCertificate.Fields.Add(new ModelMedicalCertificateField { Name = "DiaFim", PracticeId = doctor.PracticeId, });

                doctor.ModelMedicalCertificates.Add(medicalCertificate);
            }

            doctor.HealthInsurances.Add(new HealthInsurance
            {
                Name = "Particular",
                IsParticular = true,
                IsActive = true,
                PracticeId = doctor.PracticeId,
                ReturnTimeInterval = 30,
            });
        }
Exemplo n.º 5
0
        private static bool ValidateTime(
            CerebelloEntitiesAccessFilterWrapper db,
            Doctor doctor,
            DateTime localDate,
            string startTimeText,
            string endTimeText,
            ModelStateDictionary modelState,
            ModelStateDictionary inconsistencyMessages,
            DateTime localNow)
        {
            if (string.IsNullOrEmpty(startTimeText) || string.IsNullOrEmpty(endTimeText))
                return false;

            var hasError = false;

            var startRegexMatch = TimeDataTypeAttribute.Regex.Match(startTimeText);
            var endRegexMatch = TimeDataTypeAttribute.Regex.Match(endTimeText);

            var integerHourStart = int.Parse(startRegexMatch.Groups[1].Value) * 100 + int.Parse(startRegexMatch.Groups[2].Value);
            var integerHourEnd = int.Parse(endRegexMatch.Groups[1].Value) * 100 + int.Parse(endRegexMatch.Groups[2].Value);

            var monthAndDay = localDate.Month * 100 + localDate.Day;

            // Validation: cannot be holliday.
            var isHolliday = db.SYS_Holiday.Any(h => h.MonthAndDay == monthAndDay);
            if (isHolliday)
            {
                inconsistencyMessages.AddModelError<AppointmentViewModel>(
                    model => model.LocalDateTime,
                    "O campo '{0}' é inválido. Este dia é um feriado.");
                hasError = true;
            }

            //var doctor = this.Doctor;

            // Validation: cannot be day-off.
            var isDayOff = db.CFG_DayOff
                             .Where(d => d.DoctorId == doctor.Id).Any(d => d.Date == localDate.Date);

            if (isDayOff)
            {
                inconsistencyMessages.AddModelError<AppointmentViewModel>(
                    model => model.LocalDateTime,
                    "O campo '{0}' é inválido. Este dia está no intervalo de dias sem expediente do médico.");
                hasError = true;
            }

            // Validation: cannot set an appointment date to the past.
            var localStartDate = localDate.Date + DateTimeHelper.GetTimeSpan(startTimeText);
            if (localStartDate < localNow)
            {
                inconsistencyMessages.AddModelError<AppointmentViewModel>(
                    model => model.LocalDateTime,
                    "A data e hora indicadas estão no passado.");
                hasError = true;
            }

            // Validation: end time cannot be the same as start time.
            if (integerHourStart == integerHourEnd)
            {
                modelState.AddModelError<AppointmentViewModel>(
                    model => model.End,
                    "O campo '{0}' não pode ser igual ao horário de início.");
                hasError = true;
            }

            // Validation: end time must come after the start time.
            else if (integerHourStart > integerHourEnd)
            {
                modelState.AddModelError<AppointmentViewModel>(
                    model => model.End,
                    "O campo '{0}' não pode ser menor que o horário de início.");
                hasError = true;
            }

            Action<string, string, string, string> checkModelTimingError = (workdayStart, workdayEnd, lunchStart, lunchEnd) =>
            {
                if (string.IsNullOrEmpty(workdayStart) || string.IsNullOrEmpty(workdayEnd))
                {
                    modelState.AddModelError<AppointmentViewModel>(
                        model => model.LocalDateTime,
                        "O campo '{0}' é inválido. Não existem configurações de horário para esta data.");
                    hasError = true;
                }
                else
                {
                    // Verify the lunch time.
                    // lunch time can only be a problem when it's set, because it's optional
                    // when the start time is set, so it is the end time
                    // I'm checking both here but it could be just one
                    if (!string.IsNullOrEmpty(lunchStart) && !string.IsNullOrEmpty(lunchEnd))
                    {
                        var lunchStartInteger = GetTimeAsInteger(lunchStart);
                        var lunchEndInteger = GetTimeAsInteger(lunchEnd);

                        bool lunchIsAfter = integerHourStart < lunchStartInteger && integerHourEnd <= lunchStartInteger;
                        bool lunchIsBefore = integerHourStart >= lunchEndInteger && integerHourEnd > lunchEndInteger;

                        if (lunchIsAfter == lunchIsBefore)
                        {
                            inconsistencyMessages.AddModelError<AppointmentViewModel>(
                                model => model.LocalDateTime,
                                "A data e hora marcada está no horário de almoço do médico.");
                            hasError = true;
                        }
                    }

                    // Verify the work time.
                    {
                        var workdayStartInteger = GetTimeAsInteger(workdayStart);
                        var workdayEndInteger = GetTimeAsInteger(workdayEnd);

                        if (integerHourStart < workdayStartInteger)
                        {
                            modelState.AddModelError<AppointmentViewModel>(
                                model => model.Start,
                                "O campo '{0}' não é um horário válido devido às configurações de horário de trabalho.");
                            hasError = true;
                        }

                        if (integerHourEnd > workdayEndInteger)
                        {
                            modelState.AddModelError<AppointmentViewModel>(
                                model => model.End,
                                "O campo '{0}' não é um horário válido devido às configurações de horário de trabalho.");
                            hasError = true;
                        }
                    }
                }
            };

            switch (localDate.Date.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.SundayWorkdayStartTime,
                        doctor.CFG_Schedule.SundayWorkdayEndTime,
                        doctor.CFG_Schedule.SundayLunchStartTime,
                        doctor.CFG_Schedule.SundayLunchEndTime);
                    break;
                case DayOfWeek.Monday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.MondayWorkdayStartTime,
                        doctor.CFG_Schedule.MondayWorkdayEndTime,
                        doctor.CFG_Schedule.MondayLunchStartTime,
                        doctor.CFG_Schedule.MondayLunchEndTime);
                    break;
                case DayOfWeek.Tuesday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.TuesdayWorkdayStartTime,
                        doctor.CFG_Schedule.TuesdayWorkdayEndTime,
                        doctor.CFG_Schedule.TuesdayLunchStartTime,
                        doctor.CFG_Schedule.TuesdayLunchEndTime);
                    break;
                case DayOfWeek.Wednesday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.WednesdayWorkdayStartTime,
                        doctor.CFG_Schedule.WednesdayWorkdayEndTime,
                        doctor.CFG_Schedule.WednesdayLunchStartTime,
                        doctor.CFG_Schedule.WednesdayLunchEndTime);
                    break;
                case DayOfWeek.Thursday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.ThursdayWorkdayStartTime,
                        doctor.CFG_Schedule.ThursdayWorkdayEndTime,
                        doctor.CFG_Schedule.ThursdayLunchStartTime,
                        doctor.CFG_Schedule.ThursdayLunchEndTime);
                    break;
                case DayOfWeek.Friday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.FridayWorkdayStartTime,
                        doctor.CFG_Schedule.FridayWorkdayEndTime,
                        doctor.CFG_Schedule.FridayLunchStartTime,
                        doctor.CFG_Schedule.FridayLunchEndTime);
                    break;
                case DayOfWeek.Saturday:
                    checkModelTimingError(
                        doctor.CFG_Schedule.SaturdayWorkdayStartTime,
                        doctor.CFG_Schedule.SaturdayWorkdayEndTime,
                        doctor.CFG_Schedule.SaturdayLunchStartTime,
                        doctor.CFG_Schedule.SaturdayLunchEndTime);
                    break;
            }

            return !hasError;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the series of all day slots ordered.
        /// </summary>
        /// <param name="localDateTime"></param>
        /// <param name="doctor"></param>
        /// <returns></returns>
        private static IEnumerable<Tuple<DateTime, DateTime>> GetDaySlotsInLocalTime(DateTime localDateTime, Doctor doctor)
        {
            if (localDateTime.Kind != DateTimeKind.Unspecified)
                throw new ArgumentException("'localDateTime' must be expressed in local practice time-zone.", "localDateTime");

            string workdayStartTimeAsString = null;
            string workdayEndTimeAsString = null;
            string lunchStartTimeAsString = null;
            string lunchEndTimeAsString = null;

            if (doctor.CFG_Schedule == null)
                throw new Exception("You should have checked to see if 'doctor.CFG_Schedule' is null before calling this method.");

            switch (localDateTime.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    if (!doctor.CFG_Schedule.Sunday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.SundayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.SundayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.SundayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.SundayLunchEndTime;
                    break;
                case DayOfWeek.Monday:
                    if (!doctor.CFG_Schedule.Monday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.MondayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.MondayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.MondayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.MondayLunchEndTime;
                    break;
                case DayOfWeek.Tuesday:
                    if (!doctor.CFG_Schedule.Tuesday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.TuesdayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.TuesdayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.TuesdayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.TuesdayLunchEndTime;
                    break;
                case DayOfWeek.Wednesday:
                    if (!doctor.CFG_Schedule.Wednesday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.WednesdayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.WednesdayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.WednesdayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.WednesdayLunchEndTime;
                    break;
                case DayOfWeek.Thursday:
                    if (!doctor.CFG_Schedule.Thursday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.ThursdayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.ThursdayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.ThursdayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.ThursdayLunchEndTime;
                    break;
                case DayOfWeek.Friday:
                    if (!doctor.CFG_Schedule.Friday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.FridayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.FridayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.FridayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.FridayLunchEndTime;
                    break;
                case DayOfWeek.Saturday:
                    if (!doctor.CFG_Schedule.Saturday)
                        return new List<Tuple<DateTime, DateTime>>();
                    workdayStartTimeAsString = doctor.CFG_Schedule.SaturdayWorkdayStartTime;
                    workdayEndTimeAsString = doctor.CFG_Schedule.SaturdayWorkdayEndTime;
                    lunchStartTimeAsString = doctor.CFG_Schedule.SaturdayLunchStartTime;
                    lunchEndTimeAsString = doctor.CFG_Schedule.SaturdayLunchEndTime;
                    break;
            }

            DateTime todayBeginning = localDateTime.Date;
            var workdayStartTime = todayBeginning + DateTimeHelper.GetTimeSpan(workdayStartTimeAsString);
            var workdayEndTime = todayBeginning + DateTimeHelper.GetTimeSpan(workdayEndTimeAsString);
            var lunchStartTime = !string.IsNullOrEmpty(lunchStartTimeAsString) ? todayBeginning + DateTimeHelper.GetTimeSpan(lunchStartTimeAsString) : (DateTime?)null;
            var lunchEndTime = !string.IsNullOrEmpty(lunchEndTimeAsString) ? todayBeginning + DateTimeHelper.GetTimeSpan(lunchEndTimeAsString) : (DateTime?)null;

            // ok. Now with all the info we need, let' start building these slots

            var result = new List<Tuple<DateTime, DateTime>>();

            var time = workdayStartTime;
            var appointmentTimeSpan = new TimeSpan(0, doctor.CFG_Schedule.AppointmentTime, 0);

            while (true)
            {
                var timeEnd = time + appointmentTimeSpan;

                // the time computation depends on whether or not theres a lunch time configured

                // when there's lunch time
                if (lunchStartTime.HasValue)
                {
                    if ((time >= workdayStartTime && timeEnd <= lunchStartTime) || (time >= lunchEndTime && timeEnd <= workdayEndTime))
                    {
                        // in this case this span (time to timeEnd) is absolutely valid and we must add it to the slots
                        result.Add(new Tuple<DateTime, DateTime>(time, timeEnd));
                        time = time + appointmentTimeSpan;
                    }

                    else if (time >= workdayStartTime && timeEnd > lunchStartTime && timeEnd < workdayEndTime)
                    {
                        // this is an exception case in which the appointment would end in the middle of the lunch time
                        Debug.Assert(lunchEndTime != null, "lunchEndTime != null");

                        // the time is restarted after lunch
                        time = lunchEndTime.Value;
                    }
                    else
                        // in this case we're getting an inconsistent time and the time slots for the day are over
                        break;
                }
                // when there's no lunch time
                else
                {
                    if (time >= workdayStartTime && timeEnd <= workdayEndTime)
                    {
                        // in this case this span (time to timeEnd) is absolutely valid and we must add it to the slots
                        result.Add(new Tuple<DateTime, DateTime>(time, timeEnd));
                        time = time + appointmentTimeSpan;
                    }
                    // in this case we're getting an inconsistent time and the time slots for the day are over
                    else
                        break;
                }

            }

            return result;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns the next free time of a doctor, in local practice time-zone.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="doctor"></param>
        /// <param name="startingFromLocalTime">
        /// The date and time to start scanning for free times.
        /// This must be a time in the practice time-zone.
        /// </param>
        /// <returns></returns>
        public static Tuple<DateTime, DateTime> FindNextFreeTimeInPracticeLocalTime(
            CerebelloEntitiesAccessFilterWrapper db,
            Doctor doctor,
            DateTime startingFromLocalTime)
        {
            if (startingFromLocalTime.Kind != DateTimeKind.Unspecified)
                throw new ArgumentException("'startingFromLocalTime' must be expressed in local practice time-zone.", "startingFromLocalTime");

            var practice = doctor.Users.FirstOrDefault().Practice;

            var currentDateStartLocal = startingFromLocalTime.Date;
            while (true)
            {
                // getting a list of valid dates to look for slots
                // - days-off are invalid
                DateTime[] validLocalDates;
                {
                    var currentDateEndLocal = currentDateStartLocal.AddDays(30.0);

                    while (true)
                    {
                        var daysOffDates = db.CFG_DayOff
                            .Where(df => df.DoctorId == doctor.Id)
                            .Where(df => df.Date >= currentDateStartLocal && df.Date < currentDateEndLocal)
                            .Select(df => df.Date)
                            .ToArray();

                        validLocalDates = DateTimeHelper.Range(currentDateStartLocal, 30, d => d.AddDays(1.0)).ToArray();
                        validLocalDates = validLocalDates.Except(daysOffDates).ToArray();

                        if (validLocalDates.Length > 0)
                            break;

                        currentDateStartLocal = currentDateEndLocal;
                    }
                }

                // For each valid date, we look inside them for available slots.
                foreach (var eachValidLocalDate in validLocalDates)
                {
                    var currentDateStartUtc = ConvertToUtcDateTime(practice, eachValidLocalDate);
                    var currentDateEndUtc = ConvertToUtcDateTime(practice, eachValidLocalDate.AddDays(1.0).AddTicks(-1));

                    // take all appointments of that day
                    var appointments = db.Appointments
                        .Where(a => a.DoctorId == doctor.Id)
                        .Where(a => a.End >= currentDateStartUtc && a.Start <= currentDateEndUtc)
                        .OrderBy(a => a.Start)
                        .ToList();

                    var slots = GetDaySlotsInLocalTime(eachValidLocalDate, doctor)
                        .Where(s => s.Item1 >= startingFromLocalTime)
                        .Select(s => new
                        {
                            StartUtc = ConvertToUtcDateTime(practice, s.Item1),
                            EndUtc = ConvertToUtcDateTime(practice, s.Item2)
                        })
                        .ToList();

                    // Looking for available slots of time in the current day.
                    foreach (var slot in slots)
                    {
                        if (!IsTimeAvailableUtc(slot.StartUtc, slot.EndUtc, appointments))
                            continue;

                        return Tuple.Create(
                            ConvertToLocalDateTime(practice, slot.StartUtc),
                            ConvertToLocalDateTime(practice, slot.EndUtc));
                    };
                }
            }
        }
Exemplo n.º 8
0
        private Tuple<DateTime, DateTime> FindNextFreeValidTimeInPracticeLocalTime(Doctor doctor, DateTime localNow, DateTime localStartingFrom)
        {
            var localStartingFrom2 = localStartingFrom;

            while (true)
            {
                var slot = FindNextFreeTimeInPracticeLocalTime(this.db, doctor, localStartingFrom2);

                var vm = new AppointmentViewModel
                {
                    LocalDateTime = slot.Item1.Date,
                    Start = slot.Item1.ToString("HH:mm"),
                    End = slot.Item2.ToString("HH:mm"),
                };

                this.DoDateAndTimeValidation(vm, localNow, null);

                if (vm.DateAndTimeValidationState == DateAndTimeValidationState.Passed)
                {
                    return slot;
                }

                localStartingFrom2 = slot.Item2;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates and saves the given number of fake patients
        /// </summary>
        public static List<Patient> CreateFakePatients(Doctor doctor, CerebelloEntities db, int count)
        {
            var maleFirstNames = new[]
                {
                    "André",
                    "Anderson",
                    "Alan",
                    "Artur",
                    "Bruno",
                    "Carlos",
                    "Daniel",
                    "Danilo",
                    "Ernani",
                    "Fabiano",
                    "Fábio",
                    "Guilherme",
                    "Hélcio",
                    "Jorge",
                    "Leonardo",
                    "Marcelo",
                    "Miguel", // po cara! eu tb! // blz! haha
                    "Nelson",
                    "Osvaldo",
                    "Patrício",
                    "Roberto",
                    "Ronan",
                    "Thiago"
                };

            var femaleFirstNames = new[]
                {
                    "Alice",
                    "Aline",
                    "Bianca",
                    "Bruna",
                    "Carla",
                    "Daniela",
                    "Elaine",
                    "Fabíola",
                    "Fabiana",
                    "Giovana",
                    "Íngridi",
                    "Jaqueline",
                    "Larissa",
                    "Marcela",
                    "Natália",
                    "Paula",
                    "Quelen",
                    "Renata",
                    "Silvana",
                    "Tatiana",
                    "Valquíria",
                    "Zilá"
                };

            var middleNames = new[]
                {
                    "Albuquerque",
                    "Almeida",
                    "Bastos",
                    "Queiróz",
                    "Teixeira",
                    "Silva",
                    "Rodrigues",
                    "Santos",
                    "Pena",
                    "Bicudo",
                    "Gonçalves",
                    "Machado",
                    "Vianna",
                    "Souza",
                    "Moreira",
                    "Vieira",
                    "Correia",
                    "Reis",
                    "Delgado"
                };

            var professions = new[]
                {
                    "Pedreiro(a)",
                    "Arquiteto(a)",
                    "Programador(a)",
                    "Economista",
                    "Engenheiro(a)",
                    "Padeiro(a)",
                    "Eletricista",
                    "Vendedor(a)",
                    "Consultor(a)",
                    "Biólogo(a)",
                    "Carpinteiro(a)",
                    "Advogado(a)"
                };

            using (var rc = RandomContext.Create())
            {
                var random = rc.Random;
                var result = new List<Patient>();

                for (var i = 0; i < count; i++)
                {
                    // gender (random upper bound is exclusive)
                    var gender = random.Next(0, 2);

                    // first name
                    var possibleFirstNames = gender == 0 ? maleFirstNames : femaleFirstNames;
                    var firstName = possibleFirstNames[random.Next(possibleFirstNames.Length)];

                    // middle names
                    var chosenMiddleNames = new string[random.Next(2, 4)];
                    for (var j = 0; j < chosenMiddleNames.Length; j++)
                        chosenMiddleNames[j] = middleNames[random.Next(middleNames.Length)];

                    var birthDate = new DateTime(
                        random.Next(1950, 2000),
                        random.Next(1, 13),
                        random.Next(1, 29),
                        00,
                        00,
                        000,
                        DateTimeKind.Utc);

                    var patient = new Patient
                        {
                            Person = new Person
                                {
                                    FullName = firstName + " " + string.Join(" ", chosenMiddleNames),
                                    Gender = (short)gender,
                                    DateOfBirth = birthDate,
                                    MaritalStatus = (short?)random.Next(0, 4),
                                    BirthPlace = "Brasileiro(a)",
                                    CPF = "87324128910",
                                    Profession = professions[random.Next(professions.Length)],
                                    CreatedOn = Firestarter.UtcNow,
                                    PracticeId = doctor.PracticeId,
                                },

                            Doctor = doctor,
                            PracticeId = doctor.PracticeId,
                        };

                    // it's important do remove diacritics because StmpClient crashes on non-ascii characters
                    patient.Person.Email =  StringHelper.RemoveDiacritics((firstName + string.Join("", chosenMiddleNames)).ToLower() + "@fakemail.com");
                    Debug.Assert(!patient.Person.Addresses.Any());
                    patient.Person.Addresses.Add(
                        new Address
                            {
                                CEP = random.Next(36000000, 37000000).ToString(CultureInfo.InvariantCulture),
                                StateProvince = "MG",
                                City = "Juiz de Fora",
                                Neighborhood = "Centro",
                                Street =
                                    "Rua " + middleNames[random.Next(middleNames.Length)] + " " +
                                    middleNames[random.Next(middleNames.Length)],
                                Complement = "",
                                PracticeId = doctor.PracticeId,
                            });

                    result.Add(patient);
                    db.Patients.AddObject(patient);
                }

                db.SaveChanges();
                return result;
            }
        }
 /// <summary>
 /// Create a new Doctor object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="cRM">Initial value of the CRM property.</param>
 /// <param name="urlIdentifier">Initial value of the UrlIdentifier property.</param>
 /// <param name="medicalEntityCode">Initial value of the MedicalEntityCode property.</param>
 /// <param name="medicalEntityName">Initial value of the MedicalEntityName property.</param>
 /// <param name="medicalSpecialtyCode">Initial value of the MedicalSpecialtyCode property.</param>
 /// <param name="medicalSpecialtyName">Initial value of the MedicalSpecialtyName property.</param>
 /// <param name="practiceId">Initial value of the PracticeId property.</param>
 public static Doctor CreateDoctor(global::System.Int32 id, global::System.String cRM, global::System.String urlIdentifier, global::System.String medicalEntityCode, global::System.String medicalEntityName, global::System.String medicalSpecialtyCode, global::System.String medicalSpecialtyName, global::System.Int32 practiceId)
 {
     Doctor doctor = new Doctor();
     doctor.Id = id;
     doctor.CRM = cRM;
     doctor.UrlIdentifier = urlIdentifier;
     doctor.MedicalEntityCode = medicalEntityCode;
     doctor.MedicalEntityName = medicalEntityName;
     doctor.MedicalSpecialtyCode = medicalSpecialtyCode;
     doctor.MedicalSpecialtyName = medicalSpecialtyName;
     doctor.PracticeId = practiceId;
     return doctor;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Doctors EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDoctors(Doctor doctor)
 {
     base.AddObject("Doctors", doctor);
 }
Exemplo n.º 12
0
 public void DelDoctor(Doctor doctor)
 {
     this.DelUser(doctor.Users.Single());
 }
Exemplo n.º 13
0
 internal static void FillDoctorViewModel(User user, SYS_MedicalEntity medicalEntity, SYS_MedicalSpecialty medicalSpecialty, UserViewModel viewModel, Doctor doctor)
 {
     viewModel.MedicCRM = doctor.CRM;
     viewModel.MedicalSpecialtyId = medicalSpecialty != null ? medicalSpecialty.Id : (int?)null;
     viewModel.MedicalSpecialtyName = medicalSpecialty != null ? medicalSpecialty.Name : null;
     viewModel.MedicalEntityId = medicalEntity != null ? medicalEntity.Id : (int?)null;
     viewModel.MedicalEntityName = medicalEntity != null ? medicalEntity.Name : null;
     viewModel.MedicalEntityJurisdiction = (int)(TypeEstadoBrasileiro)Enum.Parse(
         typeof(TypeEstadoBrasileiro),
         user.Doctor.MedicalEntityJurisdiction);
 }