public ReportData ViewDetail(string PatID, string RecordID)
        {
            ReportData rdata = new ReportData();
            PatBasicInfor pt = context.PatBasicInforSet.Find(PatID);
            rdata.Name = pt.Name;
            rdata.Age = pt.Age;
            rdata.Sex = pt.Sex;
            rdata.Address = pt.Address;
            rdata.Education = pt.Education;
            rdata.Job = pt.Job;
            rdata.Phone = pt.Phone;
            rdata.ChiefDoctor = pt.ChiefDoctor;
            if (pt.SimilarFamily != null)
            {
                if (pt.SimilarFamily == true)
                {
                    rdata.SimilarFamily = true;
                }
                else
                {
                    rdata.SimilarFamily = false;
                }

            }

            if (pt.Lifestyle != null)
            {
                rdata.patlifestyle.SmokeState = pt.Lifestyle.SmokeState;
                rdata.patlifestyle.SmokeYear = pt.Lifestyle.SmokeYear;
                rdata.patlifestyle.SmokeStartAge = pt.Lifestyle.SmokeStartAge;
                rdata.patlifestyle.SmokeQuitYear = pt.Lifestyle.SmokeQuitYear;
                rdata.patlifestyle.CigarettesPerDay = pt.Lifestyle.CigarettesPerDay;
                rdata.patlifestyle.DrinkState = pt.Lifestyle.DrinkState;
                rdata.patlifestyle.DrinkStartAge = pt.Lifestyle.DrinkStartAge;
                rdata.patlifestyle.DrinkYear = pt.Lifestyle.DrinkYear;
                rdata.patlifestyle.DrinkQuitYear = pt.Lifestyle.DrinkQuitYear;
                rdata.patlifestyle.DrinkPerDay = pt.Lifestyle.DrinkPerDay;
                rdata.patlifestyle.DrinkCategory = pt.Lifestyle.DrinkCategory;
                rdata.patlifestyle.TeaPerDay = pt.Lifestyle.TeaPerDay;
                rdata.patlifestyle.CoffePerDay = pt.Lifestyle.CoffePerDay;
                rdata.patlifestyle.ExercisePerWeek = pt.Lifestyle.ExercisePerWeek;
                rdata.patlifestyle.ExerciseTime = pt.Lifestyle.ExerciseTime;
                rdata.patlifestyle.ExerciseDescription = pt.Lifestyle.ExerciseDescription;
                rdata.patlifestyle.WeightChange = pt.Lifestyle.WeightChange;
                rdata.patlifestyle.WeightChangeNote = pt.Lifestyle.WeightChangeNote;
                foreach (SpecialDiet d in pt.Lifestyle.SpecialDiet)
                {
                    rdata.patlifestyle.specialDiet.Add(d.Kind);
                }
            }

            //if (pt.SimilarFamily!=null)
            //{
            //    rdata.SimilarFamily = pt.SimilarFamily;
            //}
            foreach (HeadacheFamilyMember hfmember in pt.HeadacheFamilyMember)
            {
                rdata.Hfamilymember.Add(hfmember.Person);
            }
            foreach (OtherFamilyDisease ofdisease in pt.OtherFamilyDisease)
            {
                rdata.Ofamilydisease.Add(ofdisease.DiseaseName);
            }
            foreach (PreviousDrug pdrug in pt.PreviousDrug)
            {
                PDrug pd = new PDrug();
                ObjectMapper.CopyProperties(pdrug, pd);
                rdata.previousdrug.Add(pd);
            }
            foreach (PreviousExam pexam in pt.PreviousExam)
            {
                Exam exam = new Exam();
                ObjectMapper.CopyProperties(pexam, exam);
                rdata.previousexam.Add(exam);
            }
            if (RecordID != "")
            {

                var record = from p in context.VisitRecordSet.ToList()
                             where (p.PatBasicInfor.Id == PatID) && (p.Id == int.Parse(RecordID))
                             select p;
                VisitRecord vr = record.First();
                if (vr != null)
                {

                    rdata.VisitDate = vr.VisitDate;
                    rdata.CDSSDiagnosis1 = vr.CDSSDiagnosis1;
                    rdata.CDSSDiagnosis2 = vr.CDSSDiagnosis2;
                    rdata.CDSSDiagnosis3 = vr.CDSSDiagnosis3;
                    rdata.DiagnosisResult1 = vr.DiagnosisResult1;
                    rdata.DiagnosisResult2 = vr.DiagnosisResult2;
                    rdata.DiagnosisResult3 = vr.DiagnosisResult3;
                    rdata.Prescription = vr.Prescription;
                    rdata.ChiefComplaint = vr.ChiefComplaint;
                    foreach (SecondaryHeadacheSymptom ss in vr.SecondaryHeadacheSymptom)
                    {
                        rdata.secondaryheadachesymptom.Add(ss.Symptom);
                    }
                    foreach (MedicationAdvice madvice in vr.MecicationAdvice)
                    {
                        HMedicine hmedicine = new HMedicine();
                        hmedicine.DrugApplication = madvice.DrugApplication;
                        hmedicine.DrugCategory = madvice.DrugCategory;
                        hmedicine.DrugName = madvice.DrugName;
                        hmedicine.DrugDose = madvice.DrugDose;
                        rdata.medicationadvice.Add(hmedicine);
                    }

                    if (vr.PrimaryHeadachaOverView != null)
                    {
                        rdata.headacheoverview.HeadacheType = vr.PrimaryHeadachaOverView.HeadacheType;
                        rdata.headacheoverview.HeadacheDegree = vr.PrimaryHeadachaOverView.HeadacheDegree;
                        rdata.headacheoverview.HeadcheTime = vr.PrimaryHeadachaOverView.HeadcheTime;
                        rdata.headacheoverview.HeacheTimeUnit = vr.PrimaryHeadachaOverView.HeacheTimeUnit;
                        rdata.headacheoverview.FrequencyPerDay = vr.PrimaryHeadachaOverView.FrequencyPerDay;
                        rdata.headacheoverview.FrequencyPerMonth = vr.PrimaryHeadachaOverView.FrequencyPerMonth;
                        rdata.headacheoverview.OnsetFixedPeriod = vr.PrimaryHeadachaOverView.OnsetFixedPeriod;

                        rdata.headacheoverview.OnsetDate = vr.PrimaryHeadachaOverView.OnsetDate;
                        rdata.headacheoverview.OnsetAmount = vr.PrimaryHeadachaOverView.OnsetAmount;
                        rdata.headacheoverview.DailyAggravation = vr.PrimaryHeadachaOverView.DailyAggravation;
                        rdata.headacheoverview.FirstOnsetContinue = vr.PrimaryHeadachaOverView.FirstOnsetContinue;

                        foreach (HeadachePlace hp in vr.PrimaryHeadachaOverView.HeadachePlace)
                        {
                            string strPlace = hp.Position + hp.SpecificPlace;
                            rdata.headacheplace.Add(strPlace);
                        }
                        foreach (HeadacheProdrome hprodrome in vr.PrimaryHeadachaOverView.HeadacheProdrome)
                        {
                            rdata.headacheprodrome.Add(hprodrome.Prodrome);
                        }
                        foreach (MitigatingFactors mfactors in vr.PrimaryHeadachaOverView.MitigatingFactors)
                        {
                            rdata.mitigatingfactors.Add(mfactors.FactorName);
                        }
                        foreach (HeadacheAccompany haccompay in vr.PrimaryHeadachaOverView.HeadacheAccompany)
                        {
                            rdata.headacheaccompany.Add(haccompay.Symptom);
                        }
                        foreach (PrecipitatingFactor pfactor in vr.PrimaryHeadachaOverView.PrecipitatingFactor)
                        {
                            Factor f = new Factor();
                            f.FName = pfactor.FactorName;
                            f.FDetail = pfactor.FactorDetail;
                            rdata.precipitatingfactor.Add(f);
                        }
                    }
                }

            }
            else
            {
                rdata.VisitDate = DateTime.Now.Date;
                rdata.headacheoverview.OnsetDate = DateTime.Now.Date;
            }
            return rdata;
        }
        public ReportData ViewDetail(string PatID, string RecordID)
        {
            ReportData    rdata = new ReportData();
            PatBasicInfor pt    = context.PatBasicInforSet.Find(PatID);

            rdata.Name      = pt.Name;
            rdata.Age       = pt.Age.ToString();
            rdata.Sex       = pt.Sex;
            rdata.Address   = pt.Address;
            rdata.Education = pt.Education;
            rdata.Job       = pt.Job;
            rdata.Phone     = pt.Phone;
            rdata.Weight    = pt.Weight;
            rdata.Height    = pt.Height;
            if (pt.SimilarFamily != null)
            {
                if (pt.SimilarFamily == true)
                {
                    rdata.SimilarFamily = true;
                }
                else
                {
                    rdata.SimilarFamily = false;
                }
            }

            if (pt.Lifestyle != null)
            {
                rdata.patlifestyle.SmokeState = pt.Lifestyle.SmokeState;
                rdata.patlifestyle.SmokeYear  = pt.Lifestyle.SmokeYear;

                rdata.patlifestyle.DrinkState = pt.Lifestyle.DrinkState;

                rdata.patlifestyle.DrinkYear     = pt.Lifestyle.DrinkYear;
                rdata.patlifestyle.TeaPerDay     = pt.Lifestyle.TeaPerDay;
                rdata.patlifestyle.CoffePerDay   = pt.Lifestyle.CoffePerDay;
                rdata.patlifestyle.ExerciseOften = pt.Lifestyle.ExerciseOften;
            }

            //if (pt.SimilarFamily!=null)
            //{
            //    rdata.SimilarFamily = pt.SimilarFamily;
            //}
            foreach (HeadacheFamilyMember hfmember in pt.HeadacheFamilyMember)
            {
                rdata.Hfamilymember.Add(hfmember.Person);
            }
            foreach (OtherFamilyDisease ofdisease in pt.OtherFamilyDisease)
            {
                rdata.Ofamilydisease.Add(ofdisease.DiseaseName);
            }
            foreach (PreviousDrug pdrug in pt.PreviousDrug)
            {
                PDrug pd = new PDrug();
                ObjectMapper.CopyProperties(pdrug, pd);
                rdata.previousdrug.Add(pd);
            }
            foreach (PreviousExam pexam in pt.PreviousExam)
            {
                Exam exam = new Exam();
                ObjectMapper.CopyProperties(pexam, exam);
                rdata.previousexam.Add(exam);
            }
            if (RecordID != "")
            {
                var record = from p in context.VisitRecordSet.ToList()
                             where (p.PatBasicInfor.Id == PatID) && (p.Id == int.Parse(RecordID))
                             select p;
                VisitRecord vr = record.First();
                if (vr != null)
                {
                    rdata.VisitDate         = vr.VisitDate;
                    rdata.CDSSDiagnosis1    = vr.CDSSDiagnosis1;
                    rdata.CDSSDiagnosis2    = vr.CDSSDiagnosis2;
                    rdata.CDSSDiagnosis3    = vr.CDSSDiagnosis3;
                    rdata.DiagnosisResult1  = vr.DiagnosisResult1;
                    rdata.DiagnosisResult2  = vr.DiagnosisResult2;
                    rdata.DiagnosisResult3  = vr.DiagnosisResult3;
                    rdata.Prescription      = vr.Prescription;
                    rdata.ChiefComplaint    = vr.ChiefComplaint;
                    rdata.PreviousDiagnosis = vr.PreviousDiagnosis;
                    rdata.PrescriptionNote  = vr.PrescriptionNote;
                    foreach (SecondaryHeadacheSymptom ss in vr.SecondaryHeadacheSymptom)
                    {
                        rdata.secondaryheadachesymptom.Add(ss.Symptom);
                    }
                    foreach (MedicationAdvice madvice in vr.MedicationAdvice)
                    {
                        HMedicine hmedicine = new HMedicine();
                        hmedicine.DrugApplication = madvice.DrugApplication;
                        hmedicine.DrugCategory    = madvice.DrugCategory;
                        hmedicine.DrugName        = madvice.DrugName;
                        hmedicine.DrugDose        = madvice.DrugDose;
                        hmedicine.DrugDoseUnit    = madvice.DrugDoseUnit;
                        rdata.medicationadvice.Add(hmedicine);
                    }

                    if (vr.PrimaryHeadachaOverView != null)
                    {
                        rdata.headacheoverview.HeadacheType   = vr.PrimaryHeadachaOverView.HeadacheType;
                        rdata.headacheoverview.HeadacheDegree = vr.PrimaryHeadachaOverView.HeadacheDegree;
                        rdata.headacheoverview.HeadcheTime    = vr.PrimaryHeadachaOverView.HeadcheTime;
                        rdata.headacheoverview.HeacheTimeUnit = vr.PrimaryHeadachaOverView.HeacheTimeUnit;

                        rdata.headacheoverview.FrequencyPerMonth = vr.PrimaryHeadachaOverView.FrequencyPerMonth;
                        rdata.headacheoverview.OnsetFixedPeriod  = vr.PrimaryHeadachaOverView.OnsetFixedPeriod;

                        rdata.headacheoverview.OnsetDate          = vr.PrimaryHeadachaOverView.OnsetDate;
                        rdata.headacheoverview.OnsetAmount        = vr.PrimaryHeadachaOverView.OnsetAmount;
                        rdata.headacheoverview.DailyAggravation   = vr.PrimaryHeadachaOverView.DailyAggravation;
                        rdata.headacheoverview.FirstOnsetContinue = vr.PrimaryHeadachaOverView.FirstOnsetContinue;

                        foreach (HeadachePlace hp in vr.PrimaryHeadachaOverView.HeadachePlace)
                        {
                            string strPlace = hp.Position + hp.SpecificPlace;
                            rdata.headacheplace.Add(strPlace);
                        }
                        foreach (HeadacheProdrome hprodrome in vr.PrimaryHeadachaOverView.HeadacheProdrome)
                        {
                            rdata.headacheprodrome.Add(hprodrome.Prodrome);
                        }
                        foreach (MitigatingFactors mfactors in vr.PrimaryHeadachaOverView.MitigatingFactors)
                        {
                            rdata.mitigatingfactors.Add(mfactors.FactorName);
                        }
                        foreach (HeadacheAccompany haccompay in vr.PrimaryHeadachaOverView.HeadacheAccompany)
                        {
                            rdata.headacheaccompany.Add(haccompay.Symptom);
                        }
                        foreach (PrecipitatingFactor pfactor in vr.PrimaryHeadachaOverView.PrecipitatingFactor)
                        {
                            Factor f = new Factor();
                            f.FName   = pfactor.FactorName;
                            f.FDetail = pfactor.FactorDetail;
                            rdata.precipitatingfactor.Add(f);
                        }
                        foreach (PremonitorySymptom psymptom in vr.PrimaryHeadachaOverView.PremonitorySymptom)
                        {
                            rdata.premonitorsymptom.Add(psymptom.Symptom);
                        }
                    }

                    //add 2013/7/23
                    if (vr.GADQuestionaire != null)
                    {
                        ObjectMapper.CopyProperties(vr.GADQuestionaire, rdata.gdaquestionaire);
                    }
                    if (vr.PHQuestionaire != null)
                    {
                        ObjectMapper.CopyProperties(vr.PHQuestionaire, rdata.phquestionaire);
                    }
                    if (vr.SleepStatus != null)
                    {
                        ObjectMapper.CopyProperties(vr.SleepStatus, rdata.sleepconditon);
                    }
                    if (vr.DisabilityEvaluation != null)
                    {
                        ObjectMapper.CopyProperties(vr.DisabilityEvaluation, rdata.disablityevaluation);
                    }
                }
            }
            else
            {
                //rdata.VisitDate = DateTime.Now.Date;
                //rdata.headacheoverview.OnsetDate = DateTime.Now.Date;
                rdata.VisitDate = DateTime.Now;
                rdata.headacheoverview.OnsetDate = DateTime.Now;
            }
            return(rdata);
        }