Beispiel #1
0
        protected override void ProcessSheet(ISheet currentSheet)
        {
            Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) =>
            {
                List <PatientMRCScore> mrcs = _context.PatientMRCScores.Where(d => d.PatientId.Equals(patient.ID)).ToList();
                var newMRC = new PatientMRCScore()
                {
                    PatientId = patient.ID
                };
                patient = ReadRowCellsIntoPatientObject(patient, row, cellCount, newMRC);
                var  existingDates    = mrcs.Select(pi => pi.DateTaken.Date).ToList();
                bool dateDoesNotExist = existingDates.FindAll(d => d.Date == newMRC.DateTaken.Date).ToList().Count == 0;
                if (newMRC.DateTaken.Year > 1 && dateDoesNotExist)
                {
                    if (patient.PatientMRCScores == null)
                    {
                        patient.PatientMRCScores = new List <PatientMRCScore>();
                    }
                    patient.PatientMRCScores.Add(newMRC);
                }
                Imported.Add(patient);
            };

            InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction);
        }
        private PatientMRCScore BuildMRCScore(Patient patient, IDictionary record)
        {
            var score = new PatientMRCScore();

            score.PatientId = patient.ID;
            var stringScore = (string)record[SCORE];

            if (stringScore == "NULL" || string.IsNullOrEmpty(stringScore))
            {
                return(null);
            }
            score.Score = stringScore;
            string stringDateTaken = (string)record[DATE_TAKEN];
            var    dateTaken       = ParseDate(stringDateTaken);

            if (dateTaken == null)
            {
                return(null);
            }
            score.DateTaken = dateTaken.Value;
            _context.Entry(patient).Collection(p => p.PatientMRCScores).Load();
            var dates           = patient.PatientMRCScores.Select(s => s.DateTaken.Date).ToList();
            var existingDbDates = dates.FindAll(d => d.Date == score.DateTaken.Date);

            if (existingDbDates.Count > 0)
            {
                return(null);
            }
            Imported.Add(score);
            return(score);
        }
Beispiel #3
0
        private void ReadCell(Patient patient, IRow row, int cellIndex, PatientMRCScore newMRC)
        {
            string header        = _headers.ElementAt(cellIndex);
            string propertyValue = row.GetCell(cellIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();


            string newObjectFields = (string)_dictonary[header];

            if (newObjectFields != null)
            {
                string[] fields = newObjectFields.Split("|");
                foreach (string field in fields)
                {
                    var klassAndField = field.Split(".");
                    var propertyName  = klassAndField[1];
                    switch (klassAndField[0])
                    {
                    case "PatientMRCScore":
                        try
                        {
                            Type         type         = newMRC.GetType();
                            PropertyInfo propertyInfo = type.GetProperty(propertyName);
                            if (propertyName == "DateTaken")
                            {
                                DateTime qDate = DateTime.ParseExact(propertyValue, "dd-MMM-yyyy", CultureInfo.InvariantCulture);
                                propertyInfo.SetValue(newMRC, qDate);
                            }
                            else if (propertyName == "Score")
                            {
                                newMRC.Score = propertyValue;
                            }
                        } catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(propertyValue);
                            Console.WriteLine(klassAndField[1]);
                        }

                        break;
                    }
                }
            }
        }
Beispiel #4
0
        private Patient ReadRowCellsIntoPatientObject(Patient patient, IRow row, int cellCount, PatientMRCScore newMRC)
        {
            for (int cellCursor = row.FirstCellNum; cellCursor < cellCount; cellCursor++)
            {
                if (row.GetCell(cellCursor) != null)
                {
                    ReadCell(patient, row, cellCursor, newMRC);
                }
            }

            return(patient);
        }