// POST: api/Participant
        public IHttpActionResult PostPerson(ParticipantViewModel participant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Add HouseholdId
            if (participant.HouseholdId == null)
            {
                var household = new Household();
                household.AddressStreet     = participant.Street;
                household.AddressSuburb     = participant.Suburb;
                household.AddressPostcode   = participant.Postcode;
                household.AddressState      = participant.State;
                household.PhoneHome         = participant.PhoneHome;
                household.LastConfirmedBy   = participant.LastConfirmedBy;
                household.LastConfirmedWhen = participant.LastConfirmedWhen;
                household.AddresseeId       = participant.HouseholdAddressee;
                household.ActiveAddress     = household.ActiveAddress;
                db.Households.Add(household);
                db.SaveChanges();

                participant.HouseholdId = db.Households.Max(x => x.HouseholdId);
            }

            //Add Participant
            var mapper = new ParticipantMapper();
            var person = mapper.GetParticipantModel(participant);

            db.People.Add(person);
            db.SaveChanges();

            if (participant.StudyId != 0)
            {
                //Add in Linked Stuby Table
                var linkedStudy = new LinkSubjectsStudy();
                linkedStudy.PersonId = db.People.Max(x => x.PersonId);
                linkedStudy.StudyId  = participant.StudyId;
                db.LinkSubjectsStudies.Add(linkedStudy);
                db.SaveChanges();
            }

            //Add household members
            foreach (var member in participant.HouseholdMembers)
            {
                member.HouseholdId = participant.HouseholdId;
                member.Gender      = member.Gender == "M" ? "Male" : (member.Gender == "F" ? "Female" : "");
                var familyMember = mapper.GetParticipantModel(member);
                db.People.Add(familyMember);
                db.SaveChanges();
            }



            return(Ok(participant));
        }
        public IEnumerable <ParticipantViewModel> GetPeople()
        {
            var participants = new List <ParticipantViewModel>();

            var participantList = db.GetParticipantList();
            var mapper          = new ParticipantMapper();

            foreach (var p in participantList)
            {
                participants.Add(mapper.GetParticipantViewModel(p));
            }
            return(participants);
        }
        public IEnumerable <ParticipantViewModel> GetPeopleBystudyId(string studyId)
        {
            var Id           = Convert.ToInt32(studyId);
            var participants = new List <ParticipantViewModel>();

            var participantDetailList = from p in db.GetParticipantByStudyId(Id) select p;
            var participantList       = Mapper.Map <IEnumerable <ParticipantDetail>, IEnumerable <ParticipantById> >(participantDetailList);

            var mapper = new ParticipantMapper();

            foreach (var p in participantList)
            {
                participants.Add(mapper.GetParticipantViewModel(p));
                //add study Details
            }

            return(participants);
        }
Example #4
0
        private static void AddMatchData(List <Match> matches, RiotDataContext riotDb)
        {
            Console.WriteLine("Updating {0} matches.", matches.Count());

            foreach (var match in matches)
            {
                var matchData    = RiotService.MatchService(match.MatchId);
                var currentMatch = riotDb.Matches.First(m => m.MatchId == match.MatchId);
                currentMatch.AddMatchData(matchData);

                foreach (var participant in matchData.Participants)
                {
                    var stats = StatisticsMapper.MapParticipantStat(participant.Statistics);
                    currentMatch.Participants.Add(ParticipantMapper.MapParticipant(matchData, participant, stats));
                }

                foreach (var team in matchData.Teams)
                {
                    currentMatch.Teams.Add(TeamMapper.MapTeam(team));
                }

                riotDb.SubmitChanges();
            }
        }
Example #5
0
//

        public async Task <List <BLL.App.DTO.ParticipantNames> > GetAllParticipantAsync()
        {
            return((await Uow.Participant.GetAllParticipantAsync()).Select(e => ParticipantMapper.MapFromInternal(e)).ToList());
        }
Example #6
0
 public async Task <List <BLL.App.DTO.Participant> > AllForUserAsync(int userId)
 {
     return((await Uow.Participant.AllForUserAsync(userId)).Select(e => ParticipantMapper.MapFromInternal(e)).ToList());
 }
        public ParticipantViewModel GetPerson(int id, int studyId)
        {
            var participant  = new ParticipantViewModel();
            var mapper       = new ParticipantMapper();
            var personDetail = new ParticipantDetail();
            var person       = new ParticipantById();

            if (studyId == 0)
            {
                person = db.GetParticipantById(id).FirstOrDefault();
            }
            else
            {
                person = db.GetParticipantById(id).Where(s => s.StudyId == studyId).FirstOrDefault();
            }

            if (person != null)
            {
                participant = mapper.GetParticipantViewModel(person);

                //HouseholdMembers
                if (participant.HouseholdId != null)
                {
                    var participantList = GetPeople();
                    participant.HouseholdMembers = participantList.Where(p => p.HouseholdId == participant.HouseholdId).ToList();
                }
                if (studyId != 0)
                {
                    #region StudyParticipation
                    var ic = db.GetParticipantConsentById(participant.PersonId).Where(s => s.StudyId == participant.StudyId).ToArray();
                    var informedConsents = Mapper.Map <ParticipantConsentById[], IEnumerable <LinkedInformedConsentViewModel> >(ic);

                    foreach (var i in informedConsents)
                    {
                        if (i.WrittenConsentBy.HasValue)
                        {
                            i.WrittenConsenByName = db.uspGetStaffFullNameById(i.WrittenConsentBy.Value).FirstOrDefault();
                        }
                        if (i.VerbalConsentBy.HasValue)
                        {
                            i.VerbalConsentByName = db.uspGetStaffFullNameById(i.VerbalConsentBy.Value).FirstOrDefault();
                        }
                    }

                    participant.InformedConsents = informedConsents.ToList();


                    #endregion
                    //Corresponsdance
                    #region Corresponsdance
                    var userCorrespondance = db.Correspondences.Where(c => c.StudyId == studyId && c.PersonId == id).ToArray();

                    var correspondance = Mapper.Map <Correspondence[], IEnumerable <CorrespondanceViewModel> >(userCorrespondance);


                    foreach (var c in correspondance)
                    {
                        if (c.VtgStaffId.HasValue)
                        {
                            c.VtgStaff = db.uspGetStaffFullNameById(c.VtgStaffId.Value).FirstOrDefault();
                        }

                        if (c.FollowupStaff1.HasValue)
                        {
                            c.FollowupStaff = db.uspGetStaffFullNameById(c.FollowupStaff1.Value).FirstOrDefault();
                        }

                        if (c.FollowupStaff2.HasValue)
                        {
                            c.FollowupStaff = c.FollowupStaff + ',' + db.uspGetStaffFullNameById(c.FollowupStaff2.Value).FirstOrDefault();
                        }
                    }
                    participant.Correspondance = correspondance;
                    #endregion

                    #region Medical History
                    var medHistory = db.MedicalHistories.Where(m => m.PersonId == id).ToArray();

                    var medicalHistory = Mapper.Map <MedicalHistory[], IEnumerable <MedicalHistoryViewModel> >(medHistory);
                    foreach (var md in medicalHistory)
                    {
                    }
                    participant.MedicalHistory = medicalHistory;
                    #endregion
                }
                else
                {
                    #region Corresponsdance
                    var userCorrespondance = db.Correspondences.Where(c => c.StudyId == null && c.PersonId == id).ToArray();

                    var correspondance = Mapper.Map <Correspondence[], IEnumerable <CorrespondanceViewModel> >(userCorrespondance);


                    foreach (var c in correspondance)
                    {
                        if (c.VtgStaffId.HasValue)
                        {
                            c.VtgStaff = db.uspGetStaffFullNameById(c.VtgStaffId.Value).FirstOrDefault();
                        }

                        if (c.FollowupStaff1.HasValue)
                        {
                            c.FollowupStaff = db.uspGetStaffFullNameById(c.FollowupStaff1.Value).FirstOrDefault();
                        }

                        if (c.FollowupStaff2.HasValue)
                        {
                            c.FollowupStaff = c.FollowupStaff + ',' + db.uspGetStaffFullNameById(c.FollowupStaff2.Value).FirstOrDefault();
                        }
                    }
                    participant.Correspondance = correspondance;
                    #endregion
                }


                #region Practices/Doctors

                var linkedDocPractice   = db.LinkSubjectDoctorPractices.Where(d => d.PersonId == id).ToList();
                var linkedDocPracticeVM = Mapper.Map <List <LinkSubjectDoctorPractice>, IEnumerable <LinkedSubjectDoctorPracticeViewModel> >(linkedDocPractice);

                foreach (var link in linkedDocPracticeVM)
                {
                    var practiceDocs = db.LinkDoctorPractices.Where(p => p.DoctorPracticeLinkId == link.DoctorPracticeLinkId).FirstOrDefault();

                    //PracticeName
                    link.Practice   = db.Practices.Where(p => p.PracticeId == practiceDocs.PracticeId).Select(p => p.NamePractice).FirstOrDefault();
                    link.PracticeId = practiceDocs.PracticeId;
                    //Doctor Detail
                    var doctor = db.Doctors.Where(d => d.DoctorId == practiceDocs.DoctorId).FirstOrDefault();
                    link.DoctorId   = practiceDocs.DoctorId;
                    link.DoctorName = doctor.Fullname;
                    link.DoctorType = doctor.TypeDoctor;
                }
                participant.LinkedSubjectDoctorPractices = linkedDocPracticeVM;


                #endregion


                //Next of Kins
                //if (person.Nok1PersonId != null)
                //{
                //    participant.Nok1PersonId = person.Nok1PersonId;
                //    participant.Nok1Person = person.NoK1Person;
                //}
                //if (person.Nok2PersonId != null)
                //{
                //    participant.Nok2PersonId = person.Nok2PersonId;
                //    participant.Nok2Person = person.NoK2Person;
                //}
            }

            return(participant);
        }
        public IHttpActionResult PutPerson(int id, ParticipantViewModel participant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != participant.PersonId)
            {
                return(BadRequest());
            }
            var mapper = new ParticipantMapper();
            var person = mapper.GetParticipantModel(participant);

            if (participant.StudyId != 0)
            {
                var linkedStudy = db.LinkSubjectsStudies.Where(l => l.PersonId == participant.PersonId && l.StudyId == participant.StudyId).FirstOrDefault();
                //Study Detail
                linkedStudy.Status = participant.StudyParticipationStatus;
                linkedStudy.OfficialSubjectStudyNum = participant.OfficialSubjectStudyNum;
                linkedStudy.WithdrawnReason         = participant.Reason;
                linkedStudy.WithdrawnReasonOther    = participant.ReasonOther;
                linkedStudy.EffFrom = participant.EffectiveFrom;
                linkedStudy.EffTo   = participant.EffectiveTo;
                linkedStudy.OfficialSubjectStudyNum = participant.OfficialSubjectStudyNum;
                db.Entry(linkedStudy).State         = EntityState.Modified;
            }

            if (participant.HouseholdId.HasValue)
            {
                //Household Detail
                var household = db.Households.Where(h => h.HouseholdId == participant.HouseholdId).FirstOrDefault();
                household.AddressStreet     = participant.Street;
                household.AddressSuburb     = participant.Suburb;
                household.AddressPostcode   = participant.Postcode;
                household.AddressState      = participant.State;
                household.PhoneHome         = participant.PhoneHome;
                household.LastConfirmedBy   = participant.LastConfirmedBy;
                household.LastConfirmedWhen = participant.LastConfirmedWhen;
                household.AddresseeId       = participant.HouseholdAddressee;
                household.ActiveAddress     = participant.ActiveAddress?1:0;
                db.Entry(household).State   = EntityState.Modified;
            }


            db.Entry(person).State = EntityState.Modified;



            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }