Example #1
0
        private int ProcessCases(string tableName, List <EddieCase> caseData, int startIndex, int endIndex)
        {
            foreach (EddieCase c in caseData)
            {
                int animalID  = -1;
                int patientID = -1;
                int ownerID   = -1;
                try
                {
                    string logFileStartLine = "Adding Case From " + tableName + " ID: " + c.CaseId;
                    Console.WriteLine(logFileStartLine);

                    if (CheckIfCaseWasAlreadyInserted(c.CaseId, tableName)) // skip if this case was already inserted
                    {
                        continue;
                    }
                    // logFileWriter.WriteLine(logFileStartLine);

                    #region GENERAL CASE INFORMATION
                    Cases newCase = new Cases();
                    newCase.ApplicationVersion = appVersion;
                    newCase.DateOfCaseLogged   = currentDate;

                    DateTime caseDate;
                    DateTime.TryParse(c.Date, out caseDate);

                    newCase.DateOfCaseObserved = caseDate;

                    newCase.OriginDbname    = "Eddie";
                    newCase.OriginTableName = tableName;
                    newCase.OriginId        = c.CaseId;

                    newCase.Location = c.Location + "," + c.Region;
                    newCase.Comments = c.Comment;
                    #endregion

                    #region ANIMAL/OWNER INFO
                    animalID = GetAnimalIDBasedOnCaseInfo(c.Species, c.Sex, c.Age);

                    ownerID = IdentifyOrCreateOwnerOfCase(c.Owner, c.Region, c.Location);

                    newCase.PatientId = IdentifyOrCreateNewPatient(animalID, ownerID);

                    #endregion

                    #region INFO ON DISEASE CHOSEN BY USER
                    string[] diseaseInfo = GetInfoOnDiseaseChosenByUser(c.UserChdisease);
                    newCase.DiseaseChosenByUserId = GetDiseaseID(diseaseInfo[0]);
                    float likelihoodOfDiseaseChosenByUser; float.TryParse(diseaseInfo[1].Trim(), out likelihoodOfDiseaseChosenByUser);
                    newCase.LikelihoodOfDiseaseChosenByUser = likelihoodOfDiseaseChosenByUser;
                    newCase.RankOfDiseaseChosenByUser       = GetRankOfDiseaseChosenByUser(c.CaseId, tableName);
                    #endregion

                    ReturnValue DiseasePredictedByApp = GetInfoOnDiseasePredictedByAppRankedFirst(c.CaseId, tableName);
                    if (DiseasePredictedByApp.ThereWasAnError)
                    {
                        CleanUpNewPatientAndNewOwnerAsAResultOfAnError(patientID, ownerID);
                        continue;
                    }

                    newCase.DiseasePredictedByAppId = DiseasePredictedByApp.ID;



                    #region INFO ON TREATMENT CHOSEN BY USER
                    //!!!TO DO CHANGE THIS WHEN TREATMENT DESIGH IS COMPLETE!!!!!
                    newCase.TreatmentChosenByUserId = ADDB.Treatments.Last().Id;
                    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//////////////////
                    #endregion


                    ADDB.Add(newCase);
                    ADDB.SaveChanges();
                }
                catch (Exception e)
                {
                    logFileWriter.WriteLine("Problem With Case " + c.CaseId + "from " + tableName);
                    logFileWriter.WriteLine("Excpetion details: {0} {1}", e.Message, e.StackTrace);

                    if (ADDB.Patients.Count() > 0)
                    {
                        patientID = ADDB.Patients.Last().Id;
                        patientID = ADDB.Owners.Last().Id;
                        CleanUpNewPatientAndNewOwnerAsAResultOfAnError(patientID, ownerID);
                    }
                    continue;
                }

                //WARNING THE SYMPTOMS AND RESULTS TABLE FUNCTION NEED THE NEW CASE ID (SO WE MUST UPDATE THE CASE TABLE FIRST AND THEN CALL THE FUNCTIONS


                #region POPULATE THE SIGNS FOR CASE TABLE
                int currentCaseID = ADDB.Cases.Last().Id; // get the id of the latest case
                GetSymptomsForCaseAndPopulateTable(c.CaseId, currentCaseID, tableName);
                #endregion

                #region INFO ON RESULTS OF THE CASE
                ReturnValue ResultsOfTheCaseInsertionOutcome = GetResultsForCaseAndPopulateTable(c.CaseId, currentCaseID, tableName);
                if (ResultsOfTheCaseInsertionOutcome.ThereWasAnError)
                {
                    continue;
                }
                #endregion

                Console.WriteLine("Added Case Succesfully");
                // logFileWriter.WriteLine("Added Case {0} from {1} Successfully", c.CaseId, tableName);
            }
            return(1);
        }