Пример #1
0
        //____ _ _  _ ___  ___  _   _ _ ___
        //|___ | |\ | |  \ |__]  \_/  | |  \ 
        //|    | | \| |__/ |__]   |   | |__/
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static PatientLookupResult FindByID(String ID_toQuery)
        {
            Patient patient;

            using (var db = new ADT_ModelContainer1())
            {
                if (ID_toQuery == "")
                {
                    return(new PatientLookupResult(PatientLookupStatus.Blank, null));
                }
                else
                {
                    try
                    {
                        // Check database for patient
                        patient = db.Patients.First(pat => pat.PatientID == ID_toQuery);

                        // Patient was found
                        return(new PatientLookupResult(PatientLookupStatus.Found, patient));
                    }
                    // TargetInvocationException
                    catch (Exception)
                    {
                        patient = new Patient(ID_toQuery);
                        return(new PatientLookupResult(PatientLookupStatus.CreatedNew, patient));
                    }
                }
            }
        }
Пример #2
0
        private static void initDatabase()
        {
            using (var db = new ADT_ModelContainer1())
            {
                var objCtx = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db).ObjectContext;
                try
                {
                    MLog.Info("Caching database...");

                    objCtx.ExecuteStoreCommand("SELECT TOP 1000 [MessageID] from [ADT].[dbo].[ADTMessages]");
                    objCtx.ExecuteStoreCommand("SELECT TOP 1000 [LocationID] from [ADT].[dbo].[Locations]");
                    objCtx.ExecuteStoreCommand("SELECT TOP 1000 [PatientID] from [ADT].[dbo].[Patients]");

                    if (Global.clearAllTables)
                    {
                        MLog.Info("    Clearing Tables...");

                        objCtx.ExecuteStoreCommand("TRUNCATE TABLE [ADT].[dbo].[ADTMessages]");
                        objCtx.ExecuteStoreCommand("TRUNCATE TABLE [ADT].[dbo].[Locations]");
                        objCtx.ExecuteStoreCommand("TRUNCATE TABLE [ADT].[dbo].[Patients]");
                    }
                }

                catch (Exception)
                {
                    MLog.Info("    Creating Tables...");
                    SqlFile_Execute("ADT_Model.edmx.sql", objCtx);
                }
            }
        }
Пример #3
0
 public void RemoveFromDatabase()
 {
     using (var db = new ADT_ModelContainer1())
     {
         db.Patients.Attach(this);
         db.Patients.Remove(this);
         db.SaveChanges();
     }
 }
Пример #4
0
 public void UpdateInDatabase()
 {
     using (var db = new ADT_ModelContainer1())
     {
         db.Patients.Attach(this);
         db.Entry(this).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #5
0
 public void CreateInDatabase()
 {
     using (var db = new ADT_ModelContainer1())
     {
         db.Patients.Attach(this);
         db.Patients.Add(this);
         db.SaveChanges();
     }
 }
Пример #6
0
        //____ _ _  _ ___  ___  _   _ _ ___
        //|___ | |\ | |  \ |__]  \_/  | |  \ 
        //|    | | \| |__/ |__]   |   | |__/
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static LocationLookupResult FindByID(String ID_toQuery)
        {
            Location location;
            Patient  existingPatient;

            using (var db = new ADT_ModelContainer1())
            {
                if (ID_toQuery == null || ID_toQuery == "")
                {
                    return(new LocationLookupResult(LocationLookupStatus.Blank, null));
                }
                else
                {
                    try
                    {
                        // Try to find the location
                        location = db.Locations.First(loc => loc.LocationID == ID_toQuery);

                        // Location Found!

                        // Check for existing patient
                        try
                        {
                            // Try to find an existing patient
                            existingPatient = db.Patients.First(pat => pat.LocationID == ID_toQuery);

                            // There was a patient there...  this should almost NEVER happen... Time to kick them out.
                            return(new LocationLookupResult(LocationLookupStatus.Found_PatientPresent, location, existingPatient));
                        }
                        catch (Exception)
                        {
                            // No patient was in that room
                            return(new LocationLookupResult(LocationLookupStatus.Found_NoPatient, location));
                        }
                    }
                    // TargetInvocationException
                    catch (Exception)
                    {
                        if (Global.CreateLocations)
                        {
                            location = new Location(ID_toQuery);
                            location.CreateInDatabase();
                            return(new LocationLookupResult(LocationLookupStatus.CreatedNew, location));
                        }
                        else
                        {
                            return(new LocationLookupResult(LocationLookupStatus.NotFound_NotCreated, null));
                        }
                    }
                }
            }
        }
Пример #7
0
        //____ _ _  _ ___  ___  _   _ _ ___
        //|___ | |\ | |  \ |__]  \_/  | |  \ 
        //|    | | \| |__/ |__]   |   | |__/
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static ADTLookupResult FindByID(String ID_toQuery)
        {
            ADTMessage adt_message;

            using (var db = new ADT_ModelContainer1())
            {
                if (ID_toQuery == "")
                {
                    return(new ADTLookupResult(ADTLookupStatus.Blank, null));
                }
                else
                {
                    try
                    {
                        // Check database for ADTMessage
                        adt_message = db.ADTMessages.First(adt => adt.MessageID == ID_toQuery);

                        // ADTMessage was found...

                        // If AllowDuplicateMessageIDs is set, recursively find the next available MessageID
                        if (Global.AllowDuplicateMessageIDs)
                        {
                            string[] full_id_split = ID_toQuery.Split(new string[] { "--" }, StringSplitOptions.None);
                            if (full_id_split.Length == 1)
                            {
                                return(FindByID(ID_toQuery + "--1"));
                            }
                            else
                            {
                                return(FindByID(full_id_split[0] + "--" + (Int32.Parse(full_id_split[1]) + 1)));
                            }
                        }
                        // Otherwise, return that it was found
                        else
                        {
                            return(new ADTLookupResult(ADTLookupStatus.Found, adt_message));
                        }
                    }
                    // TargetInvocationException
                    catch (Exception)
                    {
                        adt_message = new ADTMessage(ID_toQuery);
                        return(new ADTLookupResult(ADTLookupStatus.CreatedNew, adt_message));
                    }
                }
            }
        }