private static void ReadCpFiles(IMappable mapper, DbContextOptionsBuilder <MedicContext> builder, string directoryPath) { string invalidCpFileMessage = "Invalid CP file."; string[] files = Directory.GetFiles(directoryPath, "*.xml"); IMedicXmlParser medicXmlParser = new DefaultMedicXmlParser(new GetXmlParameters()); int counter = 1; foreach (string file in files) { using FileStream sr = new FileStream(file, FileMode.Open, FileAccess.Read); CP.CPFile cpFile = medicXmlParser.ParseXML <CP.CPFile>(sr); if (cpFile != default) { CPFile cpFileEntity = mapper.Map <CPFile, CP.CPFile>(cpFile); if (cpFileEntity != default) { using MedicContext medicContext = new MedicContext(builder.Options); using IImportMedicFile importMedicFile = new ImportMedicFile(medicContext); importMedicFile.ImportCPFile(cpFileEntity); consoleWriter.Notify($"{file} - imported, ({counter++}/{files.Length})."); } else { consoleWriter.Notify(invalidCpFileMessage); } } else { consoleWriter.Notify(invalidCpFileMessage); } } }
public async Task <IActionResult> CPFile(IFormFile CpFileFormFile) { try { string error = default; if (CpFileFormFile != default) { CP.CPFile cpFileModel = MedicXmlParser .ParseXML <CP.CPFile>(CpFileFormFile.OpenReadStream()); if (cpFileModel != default) { CPFile cpFileEntity = Mapper.Map <CPFile, CP.CPFile>(cpFileModel); await Task.Run(() => ImportMedicFile.ImportCPFile(cpFileEntity)); ClearCache(); } else { error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile); } } else { error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile); } return(View(new FileUploadPageCPFile() { Title = MedicDataLocalization.Get(MedicDataLocalization.CPFile), Description = MedicDataLocalization.Get(MedicDataLocalization.CPFile), Keywords = MedicDataLocalization.Get(MedicDataLocalization.CPFileSummary), Error = error })); } catch (XmlException xmlEx) { Task <int> _ = MedicLoggerService.SaveAsync(new Log() { Message = xmlEx.Message, InnerExceptionMessage = xmlEx?.InnerException?.Message ?? null, Source = xmlEx.Source, StackTrace = xmlEx.StackTrace, Date = DateTime.Now }); return(View(new FileUploadPageCPFile() { Title = MedicDataLocalization.Get(MedicDataLocalization.CPFile), Description = MedicDataLocalization.Get(MedicDataLocalization.CPFile), Keywords = MedicDataLocalization.Get(MedicDataLocalization.CPFileSummary), Error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile) })); } catch (InvalidOperationException invalOpEx) { Task <int> _ = MedicLoggerService.SaveAsync(new Log() { Message = invalOpEx.Message, InnerExceptionMessage = invalOpEx?.InnerException?.Message ?? null, Source = invalOpEx.Source, StackTrace = invalOpEx.StackTrace, Date = DateTime.Now }); return(View(new FileUploadPageCPFile() { Title = MedicDataLocalization.Get(MedicDataLocalization.CPFile), Description = MedicDataLocalization.Get(MedicDataLocalization.CPFile), Keywords = MedicDataLocalization.Get(MedicDataLocalization.CPFileSummary), Error = MedicDataLocalization.Get(MedicDataLocalization.InvalidFile) })); } 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; } }
public CPFile ImportCPFile(CPFile cpFile) { if (cpFile == default) { throw new ArgumentNullException(nameof(cpFile)); } if (!_areHelpLibrariesLoaded) { LoadHelpData(); _areHelpLibrariesLoaded = !_areHelpLibrariesLoaded; } cpFile.FileType = AddFileType(cpFile.FileType); cpFile.Practice = AddPractice(cpFile.Practice); foreach (Planned planned in cpFile.Plannings) { planned.Patient = AddPatient(planned.Patient); planned.PatientBranch = AddPatientBarch(planned.PatientBranch); planned.Sender = AddHealthcarePractitioner(planned.Sender); planned.PatientHRegion = AddHealthRegion(planned.PatientHRegion); foreach (Diagnose diagnose in planned.Diagnoses) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } foreach (Diagnose diagnose in planned.SendDiagnoses) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } } foreach (In currentIn in cpFile.Ins) { currentIn.Patient = AddPatient(currentIn.Patient); currentIn.PatientBranch = AddPatientBarch(currentIn.PatientBranch); currentIn.Sender = AddHealthcarePractitioner(currentIn.Sender); currentIn.PatientHRegion = AddHealthRegion(currentIn.PatientHRegion); foreach (Diagnose diagnose in currentIn.SendDiagnoses) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } foreach (Diagnose diagnose in currentIn.Diagnoses) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } } foreach (Out currentOut in cpFile.Outs) { currentOut.Patient = AddPatient(currentOut.Patient); currentOut.PatientBranch = AddPatientBarch(currentOut.PatientBranch); currentOut.Sender = AddHealthcarePractitioner(currentOut.Sender); currentOut.PatientHRegion = AddHealthRegion(currentOut.PatientHRegion); foreach (Procedure procedure in currentOut.Procedures) { if (procedure.Implant != default) { procedure.Implant.Provider = AddProvider(procedure.Implant.Provider); } } if (currentOut.OutMainDiagnose != default) { currentOut.OutMainDiagnose.Primary = AddMKB(currentOut.OutMainDiagnose.Primary); currentOut.OutMainDiagnose.Secondary = AddMKB(currentOut.OutMainDiagnose.Secondary); } foreach (Diagnose diagnose in currentOut.SendDiagnoses) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } if (currentOut.Dead != default) { currentOut.Dead.Primary = AddMKB(currentOut.Dead.Primary); currentOut.Dead.Secondary = AddMKB(currentOut.Dead.Secondary); } foreach (Diagnose diagnose in currentOut.Diagnoses) { if (diagnose != default) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } } foreach (Diagnose diagnose in currentOut.OutDiagnoses) { if (diagnose != default) { diagnose.Primary = AddMKB(diagnose.Primary); diagnose.Secondary = AddMKB(diagnose.Secondary); } } } foreach (ProtocolDrugTherapy protocolDrugTherapy in cpFile.ProtocolDrugTherapies) { protocolDrugTherapy.Patient = AddPatient(protocolDrugTherapy.Patient); protocolDrugTherapy.PatientHRegion = AddHealthRegion(protocolDrugTherapy.PatientHRegion); protocolDrugTherapy.PatientBranch = AddPatientBarch(protocolDrugTherapy.PatientBranch); protocolDrugTherapy.Chairman = AddHealthcarePractitioner(protocolDrugTherapy.Chairman); protocolDrugTherapy.Practice = AddPractice(protocolDrugTherapy.Practice); foreach (AccompanyingDrug accompanyingDrug in protocolDrugTherapy.AccompanyingDrugs) { accompanyingDrug.TherapyType = AddTherapyType(accompanyingDrug.TherapyType); } foreach (DrugProtocol drugProtocol in protocolDrugTherapy.DrugProtocols) { drugProtocol.TherapyType = AddTherapyType(drugProtocol.TherapyType); } if (protocolDrugTherapy.Members != default) { foreach (ProtocolDrugTherapyHealthPractitioner member in protocolDrugTherapy.Members) { member.HealthcarePractitioner = AddHealthcarePractitioner(member.HealthcarePractitioner); } } if (protocolDrugTherapy.Diag != default) { protocolDrugTherapy.Diag.MKB = AddMKB(protocolDrugTherapy.Diag.MKB); protocolDrugTherapy.Diag.LinkDMKB = AddMKB(protocolDrugTherapy.Diag.LinkDMKB); } if (protocolDrugTherapy.ChemotherapyPart != default) { foreach (Diag diag in protocolDrugTherapy.ChemotherapyPart.AddDiags) { diag.MKB = AddMKB(diag.MKB); diag.LinkDMKB = AddMKB(diag.LinkDMKB); } } } if (cpFile.Transfers != default) { foreach (Transfer transfer in cpFile.Transfers) { if (transfer.FirstMainDiag != default) { transfer.FirstMainDiag.MKB = AddMKB(transfer.FirstMainDiag.MKB); transfer.FirstMainDiag.LinkDMKB = AddMKB(transfer.FirstMainDiag.LinkDMKB); } if (transfer.SecondMainDiag != default) { transfer.SecondMainDiag.MKB = AddMKB(transfer.SecondMainDiag.MKB); transfer.SecondMainDiag.LinkDMKB = AddMKB(transfer.SecondMainDiag.LinkDMKB); } } } MedicContext.CPFiles.Add(cpFile); MedicContext.SaveChanges(); return(cpFile); }