Esempio n. 1
0
        public EhrExtract Convert(OutViewModel model, string name, string systemId)
        {
            if (model == default)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (_outToEHRConverter == default)
            {
                _locker.EnterWriteLock();

                if (_outToEHRConverter == default)
                {
                    _outToEHRConverter = new OutToEHRConverter(EhrManager);
                }

                _locker.ExitWriteLock();
            }

            return(_outToEHRConverter.Convert(model, name, systemId));
        }
Esempio n. 2
0
        public async Task <IActionResult> Json(int id)
        {
            try
            {
                if (id < 1)
                {
                    return(RedirectToAction(nameof(HomeController.Index), this.GetControllerName(nameof(HomeController))));
                }
                else
                {
                    OutViewModel model = await GetModelById(id);

                    if (model == default)
                    {
                        return(BadRequest());
                    }

                    EhrExtract ehrExtractModel = ToEHRConverter.Convert(model, nameof(OutViewModel), MedicConstants.ItupMedic);

                    return(await base.FormatModel(ehrExtractModel, FormattableFactory.CreateFormatter(FormatterEnum.Json)));
                }
            }
            catch (Exception ex)
            {
                Task <int> _ = MedicLoggerService.SaveAsync(new Log()
                {
                    Message = ex.Message,
                    InnerExceptionMessage = ex?.InnerException?.Message ?? null,
                    Source     = ex.Source,
                    StackTrace = ex.StackTrace,
                    Date       = DateTime.Now
                });

                throw;
            }
        }
Esempio n. 3
0
        internal EhrExtract Convert(OutViewModel model, string name, string systemId)
        {
            if (model == default)
            {
                throw new ArgumentNullException(nameof(model));
            }

            IEntryBuilder entryOutBuilder = EhrManager.EntryBuilder;

            entryOutBuilder.AddItems(
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.PatientBranch)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.PatientBranch).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.PatientHRegion)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.PatientHRegion).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.InType)).Build())
                .AddValue(EhrManager.INTBuilder.Clear().AddValue(model.InType).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.SendDate)).Build())
                .AddValue(EhrManager.DATEBuilder.Clear().AddDate(model.SendDate).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.SendUrgency)).Build())
                .AddValue(EhrManager.INTBuilder.Clear().AddValue(model.SendUrgency).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.UniqueIdentifier)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.UniqueIdentifier).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.ExaminationDate)).Build())
                .AddValue(EhrManager.DATEBuilder.Clear().AddDate(model.ExaminationDate).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Urgency)).Build())
                .AddValue(EhrManager.INTBuilder.Clear().AddValue(model.Urgency).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.NZOKPay)).Build())
                .AddValue(EhrManager.INTBuilder.Clear().AddValue(model.NZOKPay).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.InMedicalWard)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.InMedicalWard).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.EntryDate)).Build())
                .AddValue(EhrManager.DATEBuilder.Clear().AddDate(model.EntryDate).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Payer)).Build())
                .AddValue(EhrManager.INTBuilder.Clear().AddValue(model.Payer).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutMedicalWard)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.OutMedicalWard).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutUniqueIdentifier)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.OutUniqueIdentifier).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutDate)).Build())
                .AddValue(EhrManager.DATEBuilder.Clear().AddDate(model.OutDate).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutType)).Build())
                .AddValue(EhrManager.INTBuilder.Clear().AddValue(model.OutType).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.BirthPractice)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.BirthPractice).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutClinicalPath)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.OutClinicalPath).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutAPr)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.OutAPr).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.HLNumber)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.HLNumber).Build()).Build(),
                EhrManager.ElementBuilder.Clear()
                .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.CPFile)).Build())
                .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.CPFile).Build()).Build()
                );

            if (model.PlannedNumber != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.PlannedNumber)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.PlannedNumber).Build())
                    .Build());
            }

            if (model.SendClinicalPath != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.SendClinicalPath)).Build())
                    .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.SendClinicalPath).Build())
                    .Build());
            }

            if (model.ClinicalPath != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.ClinicalPath)).Build())
                    .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.ClinicalPath).Build())
                    .Build());
            }

            if (model.SendAPr != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.SendAPr)).Build())
                    .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.SendAPr).Build())
                    .Build());
            }

            if (model.InAPr != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.InAPr)).Build())
                    .AddValue(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(model.InAPr).Build())
                    .Build());
            }

            if (model.Severity != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Severity)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.Severity).Build()).Build());
            }

            if (model.Delay != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Delay)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.Delay).Build())
                    .Build());
            }

            if (model.AgeInDays != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.AgeInDays)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.AgeInDays).Build())
                    .Build());
            }

            if (model.WeightInGrams != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.WeightInGrams)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.WeightInGrams).Build())
                    .Build());
            }

            if (model.BirthWeight != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.BirthWeight)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.BirthWeight).Build())
                    .Build());
            }

            if (model.MotherIZYear != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.MotherIZYear)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.MotherIZYear).Build())
                    .Build());
            }

            if (model.MotherIZNo != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.MotherIZNo)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.MotherIZNo).Build())
                    .Build());
            }

            if (model.IZYear != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.IZYear)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.IZYear).Build())
                    .Build());
            }

            if (model.IZNo != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.IZNo)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.IZNo).Build())
                    .Build());
            }

            if (model.BirthNumber != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.BirthNumber)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.BirthNumber).Build())
                    .Build());
            }

            if (model.BirthGestWeek != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.BirthGestWeek)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.BirthGestWeek).Build())
                    .Build());
            }

            if (model.BedDays != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.BedDays)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.BedDays).Build())
                    .Build());
            }

            if (model.HLDateFrom != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.HLDateFrom)).Build())
                    .AddValue(EhrManager.DATEBuilder.Clear().AddDate((DateTime)model.HLDateFrom).Build())
                    .Build());
            }

            if (model.HLTotalDays != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.HLTotalDays)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.HLTotalDays).Build())
                    .Build());
            }

            if (model.StateAtDischarge != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.StateAtDischarge)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.StateAtDischarge).Build())
                    .Build());
            }

            if (model.Laparoscopic != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Laparoscopic)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.Laparoscopic).Build())
                    .Build());
            }

            if (model.EndCourse != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.EndCourse)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.EndCourse).Build())
                    .Build());
            }

            if (model.PackageType != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.PackageType)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.PackageType).Build())
                    .Build());
            }

            if (model.SendPackageType != default)
            {
                entryOutBuilder.AddItems(
                    EhrManager.ElementBuilder
                    .Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.SendPackageType)).Build())
                    .AddValue(EhrManager.INTBuilder.Clear().AddValue((int)model.SendPackageType).Build())
                    .Build());
            }

            Content outContent = entryOutBuilder.Build();

            ICompositionBuilder compositionBuilder = EhrManager.CompositionBuilder
                                                     .Clear()
                                                     .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(name).Build());

            if (model.Patient != default)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Patient)).Build())
                    .AddMembers(base.CreatePatientEntry(model.Patient))
                    .Build());
            }

            if (model.Sender != default)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Sender)).Build())
                    .AddMembers(base.CreatePractitionerEntry(model.Sender))
                    .Build());
            }

            if (model.SendDiagnoses != default && model.SendDiagnoses.Count > 0)
            {
                compositionBuilder.AddContent(EhrManager.SectionBuilder.Clear()
                                              .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.SendDiagnoses)).Build())
                                              .AddMembers(model.SendDiagnoses.Where(sd => sd != default).Select(sd => base.CreateDiagnoseEntry(sd)).ToArray())
                                              .Build());
            }

            if (model.Diagnoses != default && model.Diagnoses.Count > 0)
            {
                compositionBuilder.AddContent(EhrManager.SectionBuilder.Clear()
                                              .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Diagnoses)).Build())
                                              .AddMembers(model.Diagnoses.Where(d => d != default).Select(d => base.CreateDiagnoseEntry(d)).ToArray())
                                              .Build());
            }

            if (model.Dead != default)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Dead)).Build())
                    .AddMembers(base.CreateDiagnoseEntry(model.Dead))
                    .Build());
            }

            if (model.OutMainDiagnose != default)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutMainDiagnose)).Build())
                    .AddMembers(base.CreateDiagnoseEntry(model.OutMainDiagnose))
                    .Build());
            }

            if (model.OutDiagnoses != default && model.OutDiagnoses.Count > 0)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.OutDiagnoses)).Build())
                    .AddMembers(model.OutDiagnoses.Where(d => d != default).Select(d => base.CreateDiagnoseEntry(d)).ToArray())
                    .Build());
            }

            if (model.HistologicalResult != default)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.HistologicalResult)).Build())
                    .AddMembers(CreateHistologicalResultEntry(model.HistologicalResult))
                    .Build());
            }

            if (model.Epicrisis != default)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.Epicrisis)).Build())
                    .AddMembers(CreateEpicrisisEntry(model.Epicrisis))
                    .Build());
            }

            if (model.UsedDrugs != default && model.UsedDrugs.Count > 0)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.HistologicalResult)).Build())
                    .AddMembers(model.UsedDrugs.Where(ud => ud != default).Select(ud => CreateUsedDrugEntry(ud)).ToArray())
                    .Build());
            }

            if (model.Procedures != default && model.Procedures.Count > 0)
            {
                compositionBuilder.AddContent(
                    EhrManager.SectionBuilder.Clear()
                    .AddName(EhrManager.SimpleTextBuilder.Clear().AddOriginalText(nameof(model.HistologicalResult)).Build())
                    .AddMembers(model.Procedures.Where(p => p != default).Select(p => CreateProcedureEntry(p)).ToArray())
                    .Build());
            }

            compositionBuilder.AddContent(EhrManager.SectionBuilder.Clear().AddMembers(outContent).Build());

            EhrExtract ehrExtractModel = EhrManager
                                         .EhrExtractModelBuilder
                                         .AddEhrSystem(EhrManager.IIBuilder.Clear().AddRoot(EhrManager.OIDBuilder.Build(systemId)).Build())
                                         .AddSubjectOfCare(EhrManager.IIBuilder.Clear().AddRoot(EhrManager.OIDBuilder.Build(model.Patient.IdentityNumber)).Build())
                                         .AddTimeCreated(EhrManager.TSBuilder.Clear().AddTime(DateTime.Now).Build())
                                         .AddComposition(compositionBuilder.Build())
                                         .Build();

            return(ehrExtractModel);
        }