private void ReadCell(Patient patient, IRow row, PatientNACDates nacDates, int cellIndex) { string header = _headers.ElementAt(cellIndex); string newObjectFields = (string)_dictonary[header]; string propertyValue = row.GetCell(cellIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(); if (!string.IsNullOrEmpty(propertyValue) && newObjectFields != null && FirstTwoCellsNotEmpty(row)) { var klassAndField = newObjectFields.Split("."); string propertyName = klassAndField[1]; if (klassAndField[0] == "PatientNACDates") { if (propertyName.Contains("CPA")) { var cpaBand = Int32.Parse(propertyValue); nacDates.CPABand = cpaBand; } else { Type type = nacDates.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) { propertyInfo. SetValue(nacDates, Convert.ChangeType(propertyValue, typeof(DateTime)), null); } } } } }
private Patient ReadCellsForPatient(Patient patient, IRow row, int cellCount) { var allDates = _context.PatientNACDates .Where(p => p.PatientId == patient.ID) .FirstOrDefault(); var dates = patient.PatientNACDates.FirstOrDefault(); if (dates == null) { dates = new PatientNACDates(); } dates.PatientId = patient.ID; for (int cellCursor = 0; cellCursor < cellCount; cellCursor++) { if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null) { ReadCell(patient, row, dates, cellCursor); } } patient.PatientNACDates.Add(dates); if (dates.PatientId != 0 && dates.PatientId > 0) { Imported.Add(dates); } return(patient); }
private void ReadCell(Patient patient, IRow row, int cellIndex, List <PatientNACDates> dates) { string header = _headers.ElementAt(cellIndex); string propertyValue = row.GetCell(cellIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(); if (dates.Count == 0) { var nacDate = new PatientNACDates() { Patient = patient }; patient.PatientNACDates.Add(nacDate); dates = patient.PatientNACDates.ToList(); } string newObjectFields = (string)_dictonary[header]; if (newObjectFields != null) { string[] fields = newObjectFields.Split("|"); foreach (string field in fields) { var klassAndField = field.Split("."); switch (klassAndField[0]) { case "Patient": break; case "PatientNACDates": try { var date = dates.FirstOrDefault(); string propertyName = klassAndField[1]; Type type = date.GetType(); PropertyInfo propertyInfo = type.GetProperty(propertyName); if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?) && !string.IsNullOrEmpty(propertyValue)) { propertyInfo. SetValue(date, Convert.ChangeType(propertyValue, typeof(DateTime)), null); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(propertyValue); Console.WriteLine(klassAndField[1]); } break; } } } }
private void InitializeNACDatesNavigationProperty(Patient patient) { var nacInfo = _context.PatientNACDates.FirstOrDefault(); if (nacInfo == null) { nacInfo = new PatientNACDates(); nacInfo.PatientId = patient.ID; _context.PatientNACDates.Add(nacInfo); } _context.Update(nacInfo); }
internal void AddPatientNACDates(Patient patient, PatientNACDates patientNACDates) { if (patientNACDates == null) { return; } patient.PatientPulmonaryFunctionTests = new List <PatientPulmonaryFunctionTest>(); patientNACDates.PatientId = patient.ID; _context.PatientNACDates.Add(patientNACDates); patient.PatientNACDates.Add(patientNACDates); }
public void Run() { foreach (string fileToImportPath in FilesToImport()) { var ms = new MemoryStream(File.ReadAllBytes(fileToImportPath)); Action <FileStream, string> readAndSaveFileAction = (stream, fullPath) => { _importer = new ClinicLetterPdfFileImporter(stream, fullPath, _context); string fileContent = _importer.ReadFile(); var dateExtractor = new ClnicLettersDateExtractor(fileContent); var rm2Number = dateExtractor.ForRM2Number(); var datesList = dateExtractor.Dates(); var patient = _context.Patients .Include(p => p.PatientNACDates) .Where(p => p.RM2Number == rm2Number) .FirstOrDefault(); if (patient == null) { return; } if (patient.PatientNACDates.Count == 0) { var nacdate = new PatientNACDates() { PatientId = patient.ID }; patient.PatientNACDates = new List <PatientNACDates>() { nacdate }; } if (patient.PatientNACDates.FirstOrDefault().FirstSeenAtNAC.Year == 1) { patient.PatientNACDates.FirstOrDefault().FirstSeenAtNAC = dateExtractor.EarliestDate(); } patient.PatientNACDates.FirstOrDefault().LastObservationPoint = dateExtractor.LatestDate(); _context.Update(patient); _context.PatientNACDates.UpdateRange(patient.PatientNACDates); _context.SaveChanges(); Imported++; }; FileImporter.Import(fileToImportPath, readAndSaveFileAction); if (_deleteImported) { File.Delete(fileToImportPath); } } }
private Patient ReadCellsForPatient(Patient patient, IRow row, int cellCount) { var nacDates = new PatientNACDates(); nacDates.PatientId = patient.ID; for (int cellCursor = 0; cellCursor < cellCount; cellCursor++) { if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null) { ReadCell(patient, row, nacDates, cellCursor); } } patient.PatientNACDates.Add(nacDates); return(patient); }
private void ReadCell(Patient patient, IRow row, PatientNACDates dates, int cellIndex) { string header = _headers.ElementAt(cellIndex); string newObjectFields = (string)_dictonary[header]; string propertyValue = row.GetCell(cellIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK) .ToString().Replace(" ", String.Empty); if (!string.IsNullOrEmpty(propertyValue) && newObjectFields != null) { var klassAndField = newObjectFields.Split("."); string propertyName = klassAndField[1]; if (klassAndField[0] == "PatientNACDates") { if (propertyName == "DateOfDiagnosis") { try { var dateOfDiagnosis = DateTime.ParseExact(propertyValue, "dd/MM/yyyy", CultureInfo.InstalledUICulture); dates.DateOfDiagnosis = dateOfDiagnosis; } catch (Exception ex) { try { var yearDate = DateTime.ParseExact(propertyValue, "yyyy", CultureInfo.InstalledUICulture); dates.DateOfDiagnosis = yearDate; } catch (Exception ex2) { var yearDate = DateTime.ParseExact(propertyValue, "dd-MMM-yyyy", CultureInfo.InstalledUICulture); dates.DateOfDiagnosis = yearDate; } } } } } }
internal void UpdateNacDates(PatientNACDates patientNACDates, Patient patientToUpdate) { if (patientNACDates.FirstSeenAtNAC.Year == 1) { patientNACDates.ID = 0; patientToUpdate.PatientNACDates = null; return; } else { var dbPatientNACDates = _context.PatientNACDates.SingleOrDefault(s => s.PatientId == patientToUpdate.ID); if (dbPatientNACDates == null) { return; } dbPatientNACDates.CPABand = patientNACDates.CPABand; dbPatientNACDates.FirstSeenAtNAC = patientNACDates.FirstSeenAtNAC; dbPatientNACDates.FollowUp3MonthsDrug = patientNACDates.FollowUp3MonthsDrug; dbPatientNACDates.LastObservationPoint = patientNACDates.LastObservationPoint; dbPatientNACDates.InitialDrug = patientNACDates.InitialDrug; dbPatientNACDates.ReferralDate = patientNACDates.ReferralDate; _context.Update(dbPatientNACDates); } }
public IActionResult Create([Bind("LastName,FirstName,DOB,Gender, RM2Number, PatientStatusId, DateOfDeath, PostCode, GenericNote")] Patient patient, PatientDiagnosis[] diagnoses, PatientDrug[] drugs, PatientSTGQuestionnaire[] sTGQuestionnaires, PatientImmunoglobulin[] patientImmunoglobulin, PatientRadiologyFinding[] patientRadiologyFinding, PatientMedicalTrial[] patientMedicalTrial, PatientDrugLevel[] drugLevels, PatientSurgery[] surgeries, PatientAllergicIntoleranceItem[] allergies, PatientPulmonaryFunctionTest[] patientPulmonaryFunctionTest, PatientNACDates patientNACDates, PatientMeasurement[] patientMeasurement, PatientMRCScore[] patientMRCScore, CaseReportFormResult[] caseReportFormResult, PatientSmokingDrinkingStatus patientSmokingDrinkingStatus) { var existingPatient = _context.Patients.FirstOrDefault(x => x.RM2Number == patient.RM2Number); patient.CaseReportFormResults = new List <CaseReportFormResult>(); _patientManager.Request = Request; CheckIsUnique(existingPatient); if (caseReportFormResult != null && caseReportFormResult.Length > 0 && caseReportFormResult[0].Results != null) { var results = caseReportFormResult[0].Results.ToArray(); _caseReportFormManager.CreateCaseReportFormForResults(patient, results); patient.CaseReportFormResults.Add(caseReportFormResult[0]); _caseReportFormManager.LockForm(caseReportFormResult[0].CaseReportFormId); } _patientManager.AddCollectionsFromFormToPatients(patient, ref diagnoses, ref drugs, ref sTGQuestionnaires, patientImmunoglobulin, ref patientRadiologyFinding); _patientManager.AddMedicalTrials(patient, patientMedicalTrial); _patientManager.AddDrugLevels(patient, drugLevels); _patientManager.AddPatientSurgeries(patient, surgeries); _patientManager.AddPatientAllergiesIntolerances(patient, allergies); _patientManager.AddPatientPFTs(patient, patientPulmonaryFunctionTest); _patientManager.AddPatientMeasurements(patient, patientMeasurement); _patientManager.AddMRCScores(patient, patientMRCScore); _patientManager.AddPatientNACDates(patient, patientNACDates); AddOrSkipSmokingStatus(patient, patientSmokingDrinkingStatus); try { if (ModelState.IsValid) { _context.Add(patient); _context.SaveChanges(); _externalImport.Add(ExternalPatient.BuildFromPatient(patient)); var externalPatient = new ExternalPatient(); _externalImport.SaveChanges(); return(Json(new { result = "ok" })); } else { Hashtable errors = ModelStateHelper.Errors(ModelState); return(Json(new { success = false, errors })); } } catch (DbUpdateException ex) { return(null); } }
public async Task <IActionResult> EditPatient(int?id, [Bind("ID,DiagnosisCategoryId,DiagnosisTypeId,Description")] PatientDiagnosis[] diagnoses, [Bind("ID,DrugId,StartDate,EndDate")] PatientDrug[] drugs, [Bind("ID, ActivityScore, SymptomScore, ImpactScore, TotalScore")] PatientSTGQuestionnaire[] sTGQuestionnaires, [Bind("ID, DateTaken, Value, ImmunoglobulinTypeId")] PatientImmunoglobulin[] patientImmunoglobulines, [Bind("ID, DateTaken, FindingId, RadiologyTypeId, ChestLocationId, ChestDistributionId, GradeId, TreatmentResponseId, Note")] PatientRadiologyFinding[] radiololgyFindings, [Bind("ID, PatientId, MedicalTrialId, PatientMedicalTrialStatusId, IdentifiedDate, ConsentedDate, RecruitedDate, Consented")] PatientMedicalTrial[] patientMedicalTrial, [Bind("ID, PatientId, DrugId, UnitOfMeasurementId, DateTaken, DateReceived, ResultValue, ComparisionCharacter")] PatientDrugLevel[] drugLevels, [Bind("ID, SurgeryId, PatientId, SurgeryDate, Note")] PatientSurgery[] surgeries, [Bind("ID, AllergyIntoleranceItemType, AllergyIntoleranceItemId, IntoleranceType, Severity, Note")] PatientAllergicIntoleranceItem[] allergies, [Bind("ID, PulmonaryFunctionTestId, Value, ResultValue, PatientId")] PatientPulmonaryFunctionTest[] pulmonaryFunctionTest, [Bind("ID, FirstSeenAtNAC, CPABand, ReferralDate, LastObservationPoint, InitialDrug, FollowUp3MonthsDrug, PatientId")] PatientNACDates patientNACDates, [Bind("ID, DateTaken, Weight, Height")] PatientMeasurement[] patientMeasurements, [Bind("ID, DateTaken, Score")] PatientMRCScore[] patientMRCScores, [Bind("ID, SmokingStatusId, PatientId, StartAge, StopAge, CigarettesPerDay, PacksPerYear, AlcolholUnits")] PatientSmokingDrinkingStatus patientSmokingDrinkingStatus, CaseReportFormResult[] caseReportFormResult) { if (id == null) { return(NotFound()); } Patient patientToUpdate = await _patientManager .FindPatientWithFirstLevelRelationsByIdAsync(id); _patientManager.UpdateDiagnoses(diagnoses, patientToUpdate); _patientManager.UpdateDrugs(drugs, patientToUpdate, Request); _patientManager.UpdateSGRQ(sTGQuestionnaires, patientToUpdate); _patientManager.UpdateImmunoglobines(patientImmunoglobulines, patientToUpdate); _patientManager.UpdatePatientRadiology(radiololgyFindings, patientToUpdate); _patientManager.UpdatePatientMedicalTrials(patientMedicalTrial, patientToUpdate); _patientManager.UpdatePatientDrugLevels(drugLevels, patientToUpdate); _patientManager.UpdatePatientSurgeries(surgeries, patientToUpdate); _patientManager.UpdatePatientAllergiesIntolerances(allergies, patientToUpdate, Request); _patientManager.UpdatePatientsPFTs(pulmonaryFunctionTest, patientToUpdate); _patientManager.UpdateNacDates(patientNACDates, patientToUpdate); _patientManager.UpdateWeightHeight(patientMeasurements, patientToUpdate); _patientManager.UpdateMRCScore(patientMRCScores, patientToUpdate); AddOrSkipSmokingStatus(patientToUpdate, patientSmokingDrinkingStatus); _caseReportFormManager.UpdateCaseReportFormsForPatient(caseReportFormResult, patientToUpdate); _context.Entry(patientToUpdate).State = EntityState.Modified; ModelState.Remove("FirstSeenAtNAC"); //TODO - FIX THIS HACK.. if (await TryUpdateModelAsync <Patient>(patientToUpdate, "", p => p.FirstName, p => p.LastName, p => p.DOB, p => p.RM2Number, p => p.PostCode, p => p.Gender, p => p.PatientStatusId, p => p.DateOfDeath, p => p.GenericNote)) { try { _context.SaveChanges(); } catch (DbUpdateException ex) { var message = ex.Message; ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } } else { Hashtable errors = ModelStateHelper.Errors(ModelState); return(Json(new { success = false, errors })); } return(Json(new { result = "ok" })); }