Esempio n. 1
0
        ///<summary>Inserts or Deletes neccesary PatientRace entries for the specified patient given the list of PatRaces provided.</summary>
        public static void Reconcile(long patNum, List <PatRace> listPatRaces)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), patNum, listPatRaces);
                return;
            }
            string command;

            if (listPatRaces.Count == 0)                                                 //DELETE all for the patient if listPatRaces is empty.
            {
                command = "DELETE FROM patientrace WHERE PatNum = " + POut.Long(patNum); //Can't use CRUD layer here because there might be multiple races for one patient.
                Db.NonQ(command);
                return;
            }
            List <PatientRace> listPatientRaces;           //Rename this variable and the listPatRaces variable so it is easier to indicate which is the "selected" list and which is the db list.

            command          = "SELECT * FROM patientrace WHERE PatNum = " + POut.Long(patNum);
            listPatientRaces = Crud.PatientRaceCrud.SelectMany(command);
            //delete excess rows
            for (int i = 0; i < listPatientRaces.Count; i++)
            {
                if (!listPatRaces.Contains((PatRace)listPatientRaces[i].Race))                 //if there is a PatientRace row that does not match the new list of PatRaces, delete it
                {
                    Crud.PatientRaceCrud.Delete(listPatientRaces[i].PatientRaceNum);
                }
            }
            //insert new rows
            for (int i = 0; i < listPatRaces.Count; i++)
            {
                bool insertNeeded = true;
                for (int j = 0; j < listPatientRaces.Count; j++)
                {
                    if (listPatRaces[i] == listPatientRaces[j].Race)
                    {
                        insertNeeded = false;
                    }
                }
                if (insertNeeded)
                {
                    PatientRace pr = new PatientRace();
                    pr.PatNum     = patNum;
                    pr.Race       = listPatRaces[i];
                    pr.CdcrecCode = Cdcrecs.GetByPatRace(listPatRaces[i]);
                    Crud.PatientRaceCrud.Insert(pr);
                }
                //next PatRace
            }
            //return;
        }