コード例 #1
0
 public static void Open(int id)
 {
     using (MedicineContext db = new MedicineContext())
     {
         VMP = db.VMPs.Include(x => x.Patient)
               .Include(x => x.Patient.Disability)
               .Include(x => x.GeneralHistory)
               .Include(x => x.Eyes)
               .Include(x => x.AdditionalResearch)
               .Include(x => x.AdditionalResearch.GeneralBloodAnalysis)
               .Include(x => x.AdditionalResearch.ChemistryBloodAnalysis)
               .Include(x => x.AdditionalResearch.MP)
               .Include(x => x.AdditionalResearch.GeneralUrineAnalysis)
               .Include(x => x.AdditionalResearch.Feces)
               .Include(x => x.AdditionalResearch.ECG)
               .Include(x => x.AdditionalResearch.OtherResearches)
               .Include(x => x.SpecialistInspections)
               .Include(x => x.Diagnos)
               .FirstOrDefault(x => x.Id == id);
         if (VMP.Eyes.Count == 0)
         {
             VMP.Eyes = null;
         }
         if (VMP.AdditionalResearch != null && VMP.AdditionalResearch.OtherResearches.Count == 0)
         {
             VMP.AdditionalResearch.OtherResearches = null;
         }
         if (VMP.SpecialistInspections.Count == 0)
         {
             VMP.SpecialistInspections = null;
         }
     }
 }
コード例 #2
0
        public static string Print(Settings settings)
        {
            List <SocialStatus> SocialStatuses;
            List <Policy>       Policies;
            List <Disability>   Disabilities;
            List <EyeSide>      EyeSides;

            Directory.CreateDirectory(settings.SavePath);
            Object template = Template;

            Word.Application app = new Word.Application();
            app.Visible = true;
            try
            {
                Word.Document doc = app.Documents.Add(ref template, ref missingObj, ref missingObj, ref missingObj);

                using (MedicineContext db = new MedicineContext())
                {
                    db.SocialStatuses.Load();
                    db.Policies.Load();
                    db.Disabilities.Load();
                    db.EyeSides.Load();
                    SocialStatuses = db.SocialStatuses.Local.ToList();
                    Policies       = db.Policies.Local.ToList();
                    Disabilities   = db.Disabilities.Local.ToList();
                    EyeSides       = db.EyeSides.Local.ToList();
                }

                //Общая информация о пациенте
                ReplaceText(app, "#Name", VMP.Patient.Name);
                ReplaceText(app, "#Birthday", VMP.Patient.Birthday.ToShortDateString());
                ReplaceText(app, "#Policy", Policies.FirstOrDefault(x => x.Id == VMP.Patient.PoliceId).Name);
                ReplaceText(app, "#PoliceNumber", VMP.Patient.PoliceNumber);
                ReplaceText(app, "#Address", VMP.Patient.Address);
                ReplaceText(app, "#Phone", VMP.Patient.Phone);
                ReplaceText(app, "#lgota", GetLgota(Disabilities));
                ReplaceText(app, "#SocialStatus", GetSocialStatus(SocialStatuses));

                //Основной анамнез
                ReplaceText(app, "#Complaints", VMP.GeneralHistory.Complaints);
                ReplaceText(app, "#DiseaseHistory", VMP.GeneralHistory.DiseaseHistory);
                ReplaceText(app, "#Operations ", string.IsNullOrEmpty(VMP.GeneralHistory.Operations) ? "отрицает" : VMP.GeneralHistory.Operations);
                ReplaceText(app, "#ChronicDiseases", string.IsNullOrEmpty(VMP.GeneralHistory.ChronicDiseases) ? "отрицает" : VMP.GeneralHistory.ChronicDiseases);
                ReplaceText(app, "#AllergyHistory", string.IsNullOrEmpty(VMP.GeneralHistory.AllergyHistory) ? "отрицает" : VMP.GeneralHistory.AllergyHistory);

                //Объективно
                GetObjectively(app, EyeSides);

                //Данные дополнительных исследований
                //Общий анализ крови

                if (VMP.AdditionalResearch.GeneralBloodAnalysis.IsNull())
                {
                    ClearText(doc, "GBA");
                }
                else
                {
                    ReplaceText(app, "#GeneralBloodDate", VMP.AdditionalResearch.GeneralBloodAnalysis.Date == null ? ": " : $" от {VMP.AdditionalResearch.GeneralBloodAnalysis.Date?.ToShortDateString()}: ");
                    ReplaceText(app, "#Hb", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.Hb) ? "" : $"Hb {VMP.AdditionalResearch.GeneralBloodAnalysis.Hb}; ");
                    ReplaceText(app, "#E_C", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.E_C) ? "" : $"э/ц {VMP.AdditionalResearch.GeneralBloodAnalysis.E_C}х10^12/л; ");
                    ReplaceText(app, "#CP", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.CP) ? "" : $"ЦП {VMP.AdditionalResearch.GeneralBloodAnalysis.CP}; ");
                    ReplaceText(app, "#L_C", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.L_C) ? "" : $"л/ц {VMP.AdditionalResearch.GeneralBloodAnalysis.L_C}х10^9/л; ");
                    ReplaceText(app, "#T_C", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.T_C) ? "" : $"т/ц {VMP.AdditionalResearch.GeneralBloodAnalysis.T_C}х10^9/л; ");
                    ReplaceText(app, "#P_YA", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.P_YA) ? "" : $"п/я {VMP.AdditionalResearch.GeneralBloodAnalysis.P_YA}%; ");
                    ReplaceText(app, "#C_YA", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.C_YA) ? "" : $"с/я {VMP.AdditionalResearch.GeneralBloodAnalysis.C_YA}%; ");
                    ReplaceText(app, "#E_O", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.E_O) ? "" : $"э/о {VMP.AdditionalResearch.GeneralBloodAnalysis.E_O}%; ");
                    ReplaceText(app, "#L_F", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.L_F) ? "" : $"л/ф {VMP.AdditionalResearch.GeneralBloodAnalysis.L_F}%; ");
                    ReplaceText(app, "#MO", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.MO) ? "" : $"мо {VMP.AdditionalResearch.GeneralBloodAnalysis.MO}%; ");
                    ReplaceText(app, "#COE", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralBloodAnalysis.COE) ? "" : $"СОЭ {VMP.AdditionalResearch.GeneralBloodAnalysis.COE}мм/ч; ");
                }


                //Биохимический анализ крови
                if (VMP.AdditionalResearch.ChemistryBloodAnalysis.IsNull())
                {
                    ClearText(doc, "CBA");
                }
                else
                {
                    ReplaceText(app, "#ChemistryBloodDate", VMP.AdditionalResearch.ChemistryBloodAnalysis.Date == null ? ": " : $" от {VMP.AdditionalResearch.ChemistryBloodAnalysis.Date?.ToShortDateString()}: ");
                    ReplaceText(app, "#Creatinine", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.Creatinine) ? "" : $"креатинин {VMP.AdditionalResearch.ChemistryBloodAnalysis.Creatinine} ммоль/л; ");
                    ReplaceText(app, "#ChemistryBloodUrea", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.Urea) ? "" : $"мочевина {VMP.AdditionalResearch.ChemistryBloodAnalysis.Urea} ммоль/л; ");
                    ReplaceText(app, "#CommonXC", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.CommonXC) ? "" : $"общих ХС {VMP.AdditionalResearch.ChemistryBloodAnalysis.CommonXC} ммоль/л; ");
                    ReplaceText(app, "#ChemistryBloodGlucose", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.Glucose) ? "" : $"глюкоза {VMP.AdditionalResearch.ChemistryBloodAnalysis.Glucose} ммоль/л; ");
                    ReplaceText(app, "#TotalBilirubin", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.TotalBilirubin) ? "" : $"общий билирубин {VMP.AdditionalResearch.ChemistryBloodAnalysis.TotalBilirubin} ммоль/л; ");
                    ReplaceText(app, "#TotalProtein", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.TotalProtein) ? "" : $"общий белок {VMP.AdditionalResearch.ChemistryBloodAnalysis.TotalProtein} г/л; ");
                    ReplaceText(app, "#Albumen", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.Albumen) ? "" : $"альбумин {VMP.AdditionalResearch.ChemistryBloodAnalysis.Albumen} г/л; ");
                    ReplaceText(app, "#ALT", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.ALT) ? "" : $"АЛТ {VMP.AdditionalResearch.ChemistryBloodAnalysis.ALT} Ед; ");
                    ReplaceText(app, "#ACT", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.ACT) ? "" : $"АСТ {VMP.AdditionalResearch.ChemistryBloodAnalysis.ACT} Ед; ");
                    ReplaceText(app, "#TG", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.TG) ? "" : $"ТГ {VMP.AdditionalResearch.ChemistryBloodAnalysis.TG} мкмоль/л; ");
                    ReplaceText(app, "#LPVP", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.LPVP) ? "" : $"ЛПВП {VMP.AdditionalResearch.ChemistryBloodAnalysis.LPVP} ммоль/л; ");
                    ReplaceText(app, "#LPNP", string.IsNullOrEmpty(VMP.AdditionalResearch.ChemistryBloodAnalysis.LPNP) ? "" : $"ЛПНП {VMP.AdditionalResearch.ChemistryBloodAnalysis.LPNP} ммоль/л; ");
                }

                //MP
                if (VMP.AdditionalResearch.MP.IsNull())
                {
                    ClearText(doc, "MP");
                }
                else
                {
                    ReplaceText(app, "#MPDate", VMP.AdditionalResearch.MP.Date == null ? ": " : $" от {VMP.AdditionalResearch.MP.Date?.ToShortDateString()}: ");
                    ReplaceText(app, "#MPResult", string.IsNullOrEmpty(VMP.AdditionalResearch.MP.Result) ? "" : $" {VMP.AdditionalResearch.MP.Result} результат; ");
                }

                //Общий анализ мочи
                if (VMP.AdditionalResearch.GeneralUrineAnalysis.IsNull())
                {
                    ClearText(doc, "GUA");
                }
                else
                {
                    ReplaceText(app, "#GeneralUrineDate", VMP.AdditionalResearch.GeneralUrineAnalysis.Date == null ? ": " : $" от {VMP.AdditionalResearch.GeneralUrineAnalysis.Date?.ToShortDateString()}: ");
                    ReplaceText(app, "#UrineColor", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.Color) ? "" : $"цвет {VMP.AdditionalResearch.GeneralUrineAnalysis.Color.ToLower()}, ");
                    ReplaceText(app, "#UrineDensity", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.Density) ? "" : $"плотность {VMP.AdditionalResearch.GeneralUrineAnalysis.Density.ToLower()}, ");
                    ReplaceText(app, "#UrineReaction", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.Reaction) ? "" : $"реакция {VMP.AdditionalResearch.GeneralUrineAnalysis.Reaction.ToLower()}, ");
                    ReplaceText(app, "#UrineProtein", (string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.Protein) && string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.ProteinWeight)) ? "" : $"{GetUrineProtein()}, ");
                    ReplaceText(app, "#UrineGlucose", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.Glucose) ? "" : $"глюкоза {VMP.AdditionalResearch.GeneralUrineAnalysis.Glucose.ToLower()}, ");
                    ReplaceText(app, "#Urine_L_C", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.L_C) ? "" : $"л/ц {VMP.AdditionalResearch.GeneralUrineAnalysis.L_C} в п.зр., ");
                    ReplaceText(app, "#UrineEpithelialCells", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.EpithelialCells) ? "" : $"эпителиальные клетки {VMP.AdditionalResearch.GeneralUrineAnalysis.EpithelialCells}, ");
                    ReplaceText(app, "#UrineSlime", string.IsNullOrEmpty(VMP.AdditionalResearch.GeneralUrineAnalysis.Slime) ? "" : $"слизь {VMP.AdditionalResearch.GeneralUrineAnalysis.Slime.ToLower()}");
                }

                //Кал на я/г
                if (VMP.AdditionalResearch.Feces.IsNull())
                {
                    ClearText(doc, "FA");
                }
                else
                {
                    ReplaceText(app, "#FecesDate", VMP.AdditionalResearch.Feces.Date == null ? ": " : $" от {VMP.AdditionalResearch.Feces.Date?.ToShortDateString()}: ");
                    ReplaceText(app, "#FecesResult", string.IsNullOrEmpty(VMP.AdditionalResearch.Feces.Result) ? "" : $"{VMP.AdditionalResearch.GeneralUrineAnalysis.Color}.");
                }

                //ЭКГ
                if (VMP.AdditionalResearch.ECG.IsNull())
                {
                    ClearText(doc, "ECG");
                }
                else
                {
                    ReplaceText(app, "#ECGDate", VMP.AdditionalResearch.ECG.Date == null ? ": " : $" от {VMP.AdditionalResearch.ECG.Date?.ToShortDateString()}: ");
                    ReplaceText(app, "#ECGRhythm", string.IsNullOrEmpty(VMP.AdditionalResearch.ECG.Rhythm) ? "" : $"ритм {VMP.AdditionalResearch.ECG.Rhythm.ToLower()}, ");
                    ReplaceText(app, "#ECGRate", VMP.AdditionalResearch.ECG.Rate == 0 ? "" : $"ЧСС {VMP.AdditionalResearch.ECG.Rate} уд/ мин. ");
                    ReplaceText(app, "#ECGAdditionalInfo", string.IsNullOrEmpty(VMP.AdditionalResearch.ECG.AdditionalInfo) ? "" : $"{VMP.AdditionalResearch.ECG.AdditionalInfo}");
                }


                //Дополнительные исследования
                if (VMP.AdditionalResearch.OtherResearches != null)
                {
                    ReplaceList(app, "#AdditionalResearches", VMP.AdditionalResearch.OtherResearches);
                }


                //Осмотр специалистов
                if (VMP.SpecialistInspections != null)
                {
                    ReplaceList(app, "#SpecialistInspections", VMP.SpecialistInspections);
                }

                //Диагноз
                ReplaceText(app, "#MKB", VMP.Diagnos.DiagnosisCode);
                ReplaceText(app, "#GeneralDiagnosis", GetDiagnos());
                ReplaceText(app, "#CompanionDiagnosis", VMP.Diagnos.Companion);
                ReplaceText(app, "#VMPFor", VMP.Diagnos.VMPFor);

                //Подписи
                ReplaceText(app, "#DoctorPosition", settings.DoctorPosition);
                ReplaceText(app, "#DoctorName", settings.DoctorName);
                ReplaceText(app, "#BossDoctorPosition", settings.BossDoctorPosition);
                ReplaceText(app, "#BossDoctorName", settings.BossDoctorName);

                string name = String.Format($"{VMP.Patient.Name}.docx");

                Object fileFormat = Word.WdSaveFormat.wdFormatDocumentDefault;
                Object fileName   = settings.SavePath + @"\" + name;


                doc.SaveAs(fileName, fileFormat, falseObj, missingObj, falseObj, missingObj, falseObj, falseObj, falseObj, falseObj, missingObj, missingObj, missingObj, missingObj, missingObj, missingObj);
                ((Word._Document)doc).Close(ref saveChanges);
                app.Quit();
                return("ВМП сформирован");
            }
            catch (Exception ex)
            {
                app.Quit();
                return("Ошибка формирования ВМП: " + ex.Message);
            }
        }
コード例 #3
0
        internal string Save()
        {
            try
            {
                using (MedicineContext db = new MedicineContext())
                {
                    if (this.Id == 0)
                    {
                        //Если у направления нет ID, значит оно новое - создаем новое направление
                        this.CreationDate = DateTime.Now.Date;
                        db.VMPs.Add(this);
                    }
                    else
                    {
                        //Если ID есть, загружаем информацию о направлении из базы для ее изменения
                        var vmp = db.VMPs.Include(x => x.Patient)
                                  .Include(x => x.GeneralHistory)
                                  .Include(x => x.Eyes)
                                  .Include(x => x.AdditionalResearch)
                                  .Include(x => x.SpecialistInspections)
                                  .Include(x => x.Diagnos)
                                  .FirstOrDefault(x => x.Id == this.Id);

                        if (this.Patient != null)
                        {
                            if (vmp.PatientId == null)
                            {
                                db.Patients.Add(this.Patient);
                                db.SaveChanges();
                                vmp.PatientId  = this.Patient.Id;
                                this.PatientId = this.Patient.Id;
                            }
                            else
                            {
                                var patient = db.Patients.Find(vmp.PatientId);
                                patient.Copy(this.Patient);
                            }
                        }

                        if (this.GeneralHistory != null)
                        {
                            if (vmp.GeneralHistoryId == null)
                            {
                                db.GeneralHistories.Add(this.GeneralHistory);
                                db.SaveChanges();
                                vmp.GeneralHistoryId  = this.GeneralHistory.Id;
                                this.GeneralHistoryId = this.GeneralHistory.Id;
                            }
                            else
                            {
                                var generalHistory = db.GeneralHistories.Find(vmp.GeneralHistoryId);
                                generalHistory.Copy(this.GeneralHistory);
                            }
                        }

                        if (this.Eyes != null)
                        {
                            EyeSide OD = db.EyeSides.FirstOrDefault(x => x.Side == "OD");
                            EyeSide OS = db.EyeSides.FirstOrDefault(x => x.Side == "OS");
                            if (vmp.Eyes.Count == 0)
                            {
                                foreach (var eye in this.Eyes)
                                {
                                    eye.VMPId = this.Id;
                                }
                                db.Eyes.Add(this.Eyes.FirstOrDefault(x => x.EyeSideId == OD.Id));
                                db.Eyes.Add(this.Eyes.FirstOrDefault(x => x.EyeSideId == OS.Id));
                                db.SaveChanges();
                            }
                            else
                            {
                                Eye eyeOD = db.Eyes.FirstOrDefault(x => x.VMPId == this.Id && x.EyeSideId == OD.Id);
                                Eye eyeOS = db.Eyes.FirstOrDefault(x => x.VMPId == this.Id && x.EyeSideId == OS.Id);

                                eyeOD.Copy(this.Eyes.FirstOrDefault(x => x.EyeSideId == OD.Id));
                                eyeOS.Copy(this.Eyes.FirstOrDefault(x => x.EyeSideId == OS.Id));
                            }
                        }

                        if (this.AdditionalResearch != null)
                        {
                            if (vmp.AdditionalResearchId == null)
                            {
                                db.AdditionalResearches.Add(this.AdditionalResearch);
                                db.SaveChanges();
                                vmp.AdditionalResearchId  = this.AdditionalResearch.Id;
                                this.AdditionalResearchId = this.AdditionalResearch.Id;
                            }
                            else
                            {
                                var generalBloodAnalys = db.GeneralBloodAnalyses.Find(vmp.AdditionalResearch.GeneralBloodAnalysisId);
                                generalBloodAnalys.Copy(this.AdditionalResearch.GeneralBloodAnalysis);
                                var chemistryBloodAnalys = db.ChemistryBloodAnalyses.Find(vmp.AdditionalResearch.ChemistryBloodAnalysisId);
                                chemistryBloodAnalys.Copy(this.AdditionalResearch.ChemistryBloodAnalysis);
                                var mp = db.MPs.Find(vmp.AdditionalResearch.MPId);
                                mp.Copy(this.AdditionalResearch.MP);
                                var generalUrineAnalys = db.GeneralUrineAnalyses.Find(vmp.AdditionalResearch.GeneralUrineAnalysisId);
                                generalUrineAnalys.Copy(this.AdditionalResearch.GeneralUrineAnalysis);
                                var feces = db.Feceses.Find(vmp.AdditionalResearch.FecesId);
                                feces.Copy(this.AdditionalResearch.Feces);
                                var ecg = db.ECGs.Find(vmp.AdditionalResearch.ECGId);
                                ecg.Copy(this.AdditionalResearch.ECG);

                                if (this.AdditionalResearch.OtherResearches != null)
                                {
                                    db.Database.ExecuteSqlCommand($"DELETE FROM OtherResearches WHERE AdditionalResearchId = {vmp.AdditionalResearch.Id}");

                                    foreach (var or in this.AdditionalResearch.OtherResearches)
                                    {
                                        db.Database.ExecuteSqlCommand($"INSERT INTO OtherResearches (AdditionalResearchId, Research, Date, Result) " +
                                                                      $"VALUES ({vmp.AdditionalResearch.Id}, '{or.Research}', '{or.Date?.ToString("yyyy-MM-dd 00:00:00")}', '{or.Result}')");
                                    }
                                }
                            }
                        }

                        if (this.SpecialistInspections != null)
                        {
                            db.Database.ExecuteSqlCommand($"DELETE FROM SpecialistInspections WHERE VMPId = {this.Id}");
                            foreach (var si in this.SpecialistInspections)
                            {
                                db.Database.ExecuteSqlCommand($"INSERT INTO SpecialistInspections (VMPId, Specialist, Date, Result) " +
                                                              $"VALUES ({this.Id}, '{si.Specialist}', '{si.Date.ToString("yyyy-MM-dd 00:00:00")}', '{si.Result}')");
                            }
                        }

                        if (this.Diagnos != null)
                        {
                            if (vmp.DiagnosId == null)
                            {
                                db.Diagnoses.Add(this.Diagnos);
                                db.SaveChanges();
                                vmp.DiagnosId  = this.Diagnos.Id;
                                this.DiagnosId = this.Diagnos.Id;
                            }
                            else
                            {
                                var diagnos = db.Diagnoses.Find(vmp.DiagnosId);
                                diagnos.Copy(this.Diagnos);
                            }
                        }
                    }

                    db.SaveChanges();
                }
                return("Направление успешно сохранено!");
            }
            catch (Exception ex)
            {
                return($"Ошибка сохранения: {ex.Message}");
            }
        }