Ejemplo n.º 1
0
 public ActionResult NewCase(FormCollection collection)
 {
     try
     {
         if (HasIncorrectCharacter(collection["Name"]) || HasIncorrectCharacter(collection["LastName"]) || HasIncorrectCharacter(collection["Municipality"]) || HasIncorrectCharacter(collection["Symptoms"]) || HasIncorrectCharacter(collection["InfectionDescription"]))
         {
             ModelState.AddModelError("Name", "Por favor ingrese datos no numéricos en los campos pertinentes.");
             return(View("NewCase"));
         }
         if (int.Parse(collection["Age"]) < 0 || int.Parse(collection["Age"]) > 122)
         {
             ModelState.AddModelError("Age", "Por favor ingrese una edad válida");
             return(View("NewCase"));
         }
         else if (collection["Department"] == "Seleccionar Departamento")
         {
             ModelState.AddModelError("Department", "Por favor seleccione un departamento");
             return(View("NewCase"));
         }
         foreach (var patient in Storage.Instance.PatientsHash.GetAsNodes())
         {
             if (patient.Value.CUI == collection["CUI"])
             {
                 ModelState.AddModelError("CUI", "Un paciente con el mismo dpi ya ha sido ingresado en el sistema. Ingrese otro paciente.");
                 return(View("NewCase"));
             }
         }
         var newPatient = new PatientModel()
         {
             Name                 = collection["Name"],
             LastName             = collection["LastName"],
             Department           = collection["Department"],
             Hospital             = GetHospital(collection["Department"]),
             Municipality         = collection["Municipality"],
             Symptoms             = collection["Symptoms"],
             CUI                  = collection["CUI"],
             Age                  = int.Parse(collection["Age"]),
             InfectionDescription = collection["InfectionDescription"],
             IsInfected           = false,
             ArrivalDate          = DateTime.Parse(collection["ArrivalDate"]),
             Status               = "Sospechoso"
         };
         newPatient.SetInfectionChance(GetBool(collection["Europe"]), GetBool(collection["InfectedSibling"]), GetBool(collection["Socialmeeting"]), GetBool(collection["InfectedFriend"]));
         newPatient.PriorityAssignment();
         var structurePatient = new PatientStructure()
         {
             Name        = newPatient.Name,
             LastName    = newPatient.LastName,
             Hospital    = newPatient.Hospital,
             CUI         = newPatient.CUI,
             Age         = newPatient.Age,
             IsInfected  = newPatient.IsInfected,
             ArrivalDate = newPatient.ArrivalDate,
             Priority    = newPatient.Priority,
             Status      = newPatient.Status
         };
         foreach (var patient in Storage.Instance.PatientsHash.GetAsNodes())
         {
             if (patient.Value.Name == collection["Name"])
             {
                 Storage.Instance.RepeatedNames.Add(patient.Value.Name);
             }
             if (patient.Value.LastName == collection["LastName"])
             {
                 Storage.Instance.RepeatedLastNames.Add(patient.Value.LastName);
             }
         }
         Storage.Instance.PatientsHash.Insert(newPatient, newPatient.CUI);
         Storage.Instance.PatientsByName.AddPatient(structurePatient, PatientStructure.CompareByName);
         Storage.Instance.PatientsByLastName.AddPatient(structurePatient, PatientStructure.CompareByLastName);
         Storage.Instance.PatientsByCUI.AddPatient(structurePatient, PatientStructure.CompareByCUI);
         Storage.Instance.CountryStatistics.Suspicious++;
         SendToHospital(structurePatient);
         return(RedirectToAction("Index"));
     }
     catch
     {
         ModelState.AddModelError("InfectionDescription", "Por favor asegúrese de haber llenado todos los campos correctamente.");
         return(View("NewCase"));
     }
 }