Exemplo n.º 1
0
 ///<summary>Inserts one MedLabFacility into the database.  Returns the new priKey.</summary>
 public static long Insert(MedLabFacility medLabFacility)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         medLabFacility.MedLabFacilityNum = DbHelper.GetNextOracleKey("medlabfacility", "MedLabFacilityNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(medLabFacility, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     medLabFacility.MedLabFacilityNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(medLabFacility, false));
     }
 }
Exemplo n.º 2
0
        private void FillGridFacilities()
        {
            gridFacilities.BeginUpdate();
            gridFacilities.Columns.Clear();
            ODGridColumn col;

            col = new ODGridColumn("ID", 40);         //Facility ID from the MedLabResult
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("Name", 200);
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("Address", 165);
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("City", 90);
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("State", 35);
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("Zip", 70);
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("Phone", 130);
            gridFacilities.Columns.Add(col);
            col = new ODGridColumn("Director", 200);         //FName LName, Title
            gridFacilities.Columns.Add(col);
            gridFacilities.Rows.Clear();
            ODGridRow row;

            for (int i = 0; i < _listFacilities.Count; i++)
            {
                MedLabFacility facilityCur = _listFacilities[i];
                row = new ODGridRow();
                row.Cells.Add((i + 1).ToString().PadLeft(2, '0'));             //Actually more of a local renumbering of labs referenced by each Lab Result Row.
                row.Cells.Add(facilityCur.FacilityName);
                row.Cells.Add(facilityCur.Address);
                row.Cells.Add(facilityCur.City);
                row.Cells.Add(facilityCur.State);
                row.Cells.Add(facilityCur.Zip);
                row.Cells.Add(facilityCur.Phone);
                string directorName = facilityCur.DirectorFName;
                if (facilityCur.DirectorFName != "" && facilityCur.DirectorLName != "")
                {
                    directorName += " ";
                }
                directorName += facilityCur.DirectorLName;
                if (directorName != "" && facilityCur.DirectorTitle != "")
                {
                    directorName += ", " + facilityCur.DirectorTitle;
                }
                row.Cells.Add(directorName);                //could be blank
                gridFacilities.Rows.Add(row);
            }
            gridFacilities.EndUpdate();
        }
Exemplo n.º 3
0
 ///<summary>Inserts one MedLabFacility into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(MedLabFacility medLabFacility)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(medLabFacility, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             medLabFacility.MedLabFacilityNum = DbHelper.GetNextOracleKey("medlabfacility", "MedLabFacilityNum");                  //Cacheless method
         }
         return(InsertNoCache(medLabFacility, true));
     }
 }
Exemplo n.º 4
0
        ///<summary>Updates one MedLabFacility in the database.</summary>
        public static void Update(MedLabFacility medLabFacility)
        {
            string command = "UPDATE medlabfacility SET "
                             + "FacilityName     = '" + POut.String(medLabFacility.FacilityName) + "', "
                             + "Address          = '" + POut.String(medLabFacility.Address) + "', "
                             + "City             = '" + POut.String(medLabFacility.City) + "', "
                             + "State            = '" + POut.String(medLabFacility.State) + "', "
                             + "Zip              = '" + POut.String(medLabFacility.Zip) + "', "
                             + "Phone            = '" + POut.String(medLabFacility.Phone) + "', "
                             + "DirectorTitle    = '" + POut.String(medLabFacility.DirectorTitle) + "', "
                             + "DirectorLName    = '" + POut.String(medLabFacility.DirectorLName) + "', "
                             + "DirectorFName    = '" + POut.String(medLabFacility.DirectorFName) + "' "
                             + "WHERE MedLabFacilityNum = " + POut.Long(medLabFacility.MedLabFacilityNum);

            Db.NonQ(command);
        }
Exemplo n.º 5
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<MedLabFacility> TableToList(DataTable table){
			List<MedLabFacility> retVal=new List<MedLabFacility>();
			MedLabFacility medLabFacility;
			for(int i=0;i<table.Rows.Count;i++) {
				medLabFacility=new MedLabFacility();
				medLabFacility.MedLabFacilityNum= PIn.Long  (table.Rows[i]["MedLabFacilityNum"].ToString());
				medLabFacility.FacilityName     = PIn.String(table.Rows[i]["FacilityName"].ToString());
				medLabFacility.Address          = PIn.String(table.Rows[i]["Address"].ToString());
				medLabFacility.City             = PIn.String(table.Rows[i]["City"].ToString());
				medLabFacility.State            = PIn.String(table.Rows[i]["State"].ToString());
				medLabFacility.Zip              = PIn.String(table.Rows[i]["Zip"].ToString());
				medLabFacility.Phone            = PIn.String(table.Rows[i]["Phone"].ToString());
				medLabFacility.DirectorTitle    = PIn.String(table.Rows[i]["DirectorTitle"].ToString());
				medLabFacility.DirectorLName    = PIn.String(table.Rows[i]["DirectorLName"].ToString());
				medLabFacility.DirectorFName    = PIn.String(table.Rows[i]["DirectorFName"].ToString());
				retVal.Add(medLabFacility);
			}
			return retVal;
		}
Exemplo n.º 6
0
 ///<summary>Returns true if Update(MedLabFacility,MedLabFacility) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(MedLabFacility medLabFacility, MedLabFacility oldMedLabFacility)
 {
     if (medLabFacility.FacilityName != oldMedLabFacility.FacilityName)
     {
         return(true);
     }
     if (medLabFacility.Address != oldMedLabFacility.Address)
     {
         return(true);
     }
     if (medLabFacility.City != oldMedLabFacility.City)
     {
         return(true);
     }
     if (medLabFacility.State != oldMedLabFacility.State)
     {
         return(true);
     }
     if (medLabFacility.Zip != oldMedLabFacility.Zip)
     {
         return(true);
     }
     if (medLabFacility.Phone != oldMedLabFacility.Phone)
     {
         return(true);
     }
     if (medLabFacility.DirectorTitle != oldMedLabFacility.DirectorTitle)
     {
         return(true);
     }
     if (medLabFacility.DirectorLName != oldMedLabFacility.DirectorLName)
     {
         return(true);
     }
     if (medLabFacility.DirectorFName != oldMedLabFacility.DirectorFName)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <MedLabFacility> TableToList(DataTable table)
        {
            List <MedLabFacility> retVal = new List <MedLabFacility>();
            MedLabFacility        medLabFacility;

            foreach (DataRow row in table.Rows)
            {
                medLabFacility = new MedLabFacility();
                medLabFacility.MedLabFacilityNum = PIn.Long(row["MedLabFacilityNum"].ToString());
                medLabFacility.FacilityName      = PIn.String(row["FacilityName"].ToString());
                medLabFacility.Address           = PIn.String(row["Address"].ToString());
                medLabFacility.City          = PIn.String(row["City"].ToString());
                medLabFacility.State         = PIn.String(row["State"].ToString());
                medLabFacility.Zip           = PIn.String(row["Zip"].ToString());
                medLabFacility.Phone         = PIn.String(row["Phone"].ToString());
                medLabFacility.DirectorTitle = PIn.String(row["DirectorTitle"].ToString());
                medLabFacility.DirectorLName = PIn.String(row["DirectorLName"].ToString());
                medLabFacility.DirectorFName = PIn.String(row["DirectorFName"].ToString());
                retVal.Add(medLabFacility);
            }
            return(retVal);
        }
Exemplo n.º 8
0
        ///<summary>Inserts one MedLabFacility into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(MedLabFacility medLabFacility, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO medlabfacility (";

            if (!useExistingPK && isRandomKeys)
            {
                medLabFacility.MedLabFacilityNum = ReplicationServers.GetKeyNoCache("medlabfacility", "MedLabFacilityNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "MedLabFacilityNum,";
            }
            command += "FacilityName,Address,City,State,Zip,Phone,DirectorTitle,DirectorLName,DirectorFName) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(medLabFacility.MedLabFacilityNum) + ",";
            }
            command +=
                "'" + POut.String(medLabFacility.FacilityName) + "',"
                + "'" + POut.String(medLabFacility.Address) + "',"
                + "'" + POut.String(medLabFacility.City) + "',"
                + "'" + POut.String(medLabFacility.State) + "',"
                + "'" + POut.String(medLabFacility.Zip) + "',"
                + "'" + POut.String(medLabFacility.Phone) + "',"
                + "'" + POut.String(medLabFacility.DirectorTitle) + "',"
                + "'" + POut.String(medLabFacility.DirectorLName) + "',"
                + "'" + POut.String(medLabFacility.DirectorFName) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                medLabFacility.MedLabFacilityNum = Db.NonQ(command, true, "MedLabFacilityNum", "medLabFacility");
            }
            return(medLabFacility.MedLabFacilityNum);
        }
Exemplo n.º 9
0
		///<summary>Inserts one MedLabFacility into the database.  Returns the new priKey.</summary>
		public static long Insert(MedLabFacility medLabFacility){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				medLabFacility.MedLabFacilityNum=DbHelper.GetNextOracleKey("medlabfacility","MedLabFacilityNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(medLabFacility,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							medLabFacility.MedLabFacilityNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(medLabFacility,false);
			}
		}
Exemplo n.º 10
0
        ///<summary>Updates one MedLabFacility in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(MedLabFacility medLabFacility, MedLabFacility oldMedLabFacility)
        {
            string command = "";

            if (medLabFacility.FacilityName != oldMedLabFacility.FacilityName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FacilityName = '" + POut.String(medLabFacility.FacilityName) + "'";
            }
            if (medLabFacility.Address != oldMedLabFacility.Address)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Address = '" + POut.String(medLabFacility.Address) + "'";
            }
            if (medLabFacility.City != oldMedLabFacility.City)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "City = '" + POut.String(medLabFacility.City) + "'";
            }
            if (medLabFacility.State != oldMedLabFacility.State)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "State = '" + POut.String(medLabFacility.State) + "'";
            }
            if (medLabFacility.Zip != oldMedLabFacility.Zip)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Zip = '" + POut.String(medLabFacility.Zip) + "'";
            }
            if (medLabFacility.Phone != oldMedLabFacility.Phone)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Phone = '" + POut.String(medLabFacility.Phone) + "'";
            }
            if (medLabFacility.DirectorTitle != oldMedLabFacility.DirectorTitle)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DirectorTitle = '" + POut.String(medLabFacility.DirectorTitle) + "'";
            }
            if (medLabFacility.DirectorLName != oldMedLabFacility.DirectorLName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DirectorLName = '" + POut.String(medLabFacility.DirectorLName) + "'";
            }
            if (medLabFacility.DirectorFName != oldMedLabFacility.DirectorFName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DirectorFName = '" + POut.String(medLabFacility.DirectorFName) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE medlabfacility SET " + command
                      + " WHERE MedLabFacilityNum = " + POut.Long(medLabFacility.MedLabFacilityNum);
            Db.NonQ(command);
            return(true);
        }
Exemplo n.º 11
0
 ///<summary>Inserts one MedLabFacility into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(MedLabFacility medLabFacility)
 {
     return(InsertNoCache(medLabFacility, false));
 }
Exemplo n.º 12
0
		///<summary>Inserts any MedLabFacility objects not in the database.  Creates a dictionary linking the facilityIDs to a list of MedLabFacilityNums.
		///For each MedLab and MedLabResult in the message, OBR.24 and OBX.15, respectively, will contain the facilityID for the facility where the lab
		///was performed.  Using the facilityID, the orders and results will be attached to facilities via entries in the MedLabAttach table.</summary>
		public static void ProcessZPS(HL7DefSegment segDef,List<SegmentHL7> listSegs,MessageHL7 msg) {
			_dictFacilityCodeNum=new Dictionary<string,List<long>>();
			int facIdIndex=-1;
			int facNameIndex=-1;
			int facAddrIndex=-1;
			int facPhIndex=-1;
			int facDirIndex=-1;
			for(int i=0;i<segDef.hl7DefFields.Count;i++) {//get indexes for fields from the segment def
				HL7DefField fieldDefCur=segDef.hl7DefFields[i];
				switch(fieldDefCur.FieldName) {
					case "facilityID":
						facIdIndex=fieldDefCur.OrdinalPos;
						continue;
					case "facilityName":
						facNameIndex=fieldDefCur.OrdinalPos;
						continue;
					case "facilityAddress":
						facAddrIndex=fieldDefCur.OrdinalPos;
						continue;
					case "facilityPhone":
						facPhIndex=fieldDefCur.OrdinalPos;
						continue;
					case "facilityDirector":
						facDirIndex=fieldDefCur.OrdinalPos;
						continue;
					default:
						continue;
				}
			}
			if(facIdIndex<0 || facNameIndex<0 || facAddrIndex<0) {
				EventLog.WriteEntry("MessageParserMedLab","The MedLab HL7 definition does not contain a field definition for facilityID, facilityName, or "
					+"facilityAddress with a valid item order.  There will not be any MedLabFacility objects created and linked to the MedLabResult objects.",
					EventLogEntryType.Warning);
				return;
			}
			for(int i=0;i<listSegs.Count;i++) {
				MedLabFacility facilityCur=new MedLabFacility();
				facilityCur.FacilityName=listSegs[i].GetFieldComponent(facNameIndex);
				if(facAddrIndex>=0) {
					facilityCur.Address=listSegs[i].GetFieldComponent(facAddrIndex,0);
					facilityCur.City=listSegs[i].GetFieldComponent(facAddrIndex,2);
					facilityCur.State=listSegs[i].GetFieldComponent(facAddrIndex,3);
					facilityCur.Zip=listSegs[i].GetFieldComponent(facAddrIndex,4);
				}
				if(facPhIndex>=0) {
					facilityCur.Phone=listSegs[i].GetFieldComponent(facPhIndex);
				}
				if(facDirIndex>=0) {
					facilityCur.DirectorTitle=listSegs[i].GetFieldComponent(facDirIndex,0);
					facilityCur.DirectorLName=listSegs[i].GetFieldComponent(facDirIndex,1);
					facilityCur.DirectorFName=listSegs[i].GetFieldComponent(facDirIndex,2);
				}
				facilityCur.MedLabFacilityNum=MedLabFacilities.InsertIfNotInDb(facilityCur);
				string segFacId=listSegs[i].GetFieldComponent(facIdIndex);
				if(!_dictFacilityCodeNum.ContainsKey(segFacId)) {//if the footnote id doesn't exist in the dictionary, add it and the MedLabFacilityNum value
					_dictFacilityCodeNum.Add(segFacId,new List<long>() { facilityCur.MedLabFacilityNum });
					continue;
				}
				if(!_dictFacilityCodeNum[segFacId].Contains(facilityCur.MedLabFacilityNum)) {//if the id is not linked to this facilitynum, add it to the list
					_dictFacilityCodeNum[segFacId].Add(facilityCur.MedLabFacilityNum);
				}
				//dictionary contains the footnote id key and the list value for that key contains this MedLabFacilityNum
			}
			return;
		}
Exemplo n.º 13
0
		///<summary>Inserts one MedLabFacility into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(MedLabFacility medLabFacility,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				medLabFacility.MedLabFacilityNum=ReplicationServers.GetKey("medlabfacility","MedLabFacilityNum");
			}
			string command="INSERT INTO medlabfacility (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="MedLabFacilityNum,";
			}
			command+="FacilityName,Address,City,State,Zip,Phone,DirectorTitle,DirectorLName,DirectorFName) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(medLabFacility.MedLabFacilityNum)+",";
			}
			command+=
				 "'"+POut.String(medLabFacility.FacilityName)+"',"
				+"'"+POut.String(medLabFacility.Address)+"',"
				+"'"+POut.String(medLabFacility.City)+"',"
				+"'"+POut.String(medLabFacility.State)+"',"
				+"'"+POut.String(medLabFacility.Zip)+"',"
				+"'"+POut.String(medLabFacility.Phone)+"',"
				+"'"+POut.String(medLabFacility.DirectorTitle)+"',"
				+"'"+POut.String(medLabFacility.DirectorLName)+"',"
				+"'"+POut.String(medLabFacility.DirectorFName)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				medLabFacility.MedLabFacilityNum=Db.NonQ(command,true);
			}
			return medLabFacility.MedLabFacilityNum;
		}
Exemplo n.º 14
0
		///<summary>Updates one MedLabFacility in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
		public static bool Update(MedLabFacility medLabFacility,MedLabFacility oldMedLabFacility){
			string command="";
			if(medLabFacility.FacilityName != oldMedLabFacility.FacilityName) {
				if(command!=""){ command+=",";}
				command+="FacilityName = '"+POut.String(medLabFacility.FacilityName)+"'";
			}
			if(medLabFacility.Address != oldMedLabFacility.Address) {
				if(command!=""){ command+=",";}
				command+="Address = '"+POut.String(medLabFacility.Address)+"'";
			}
			if(medLabFacility.City != oldMedLabFacility.City) {
				if(command!=""){ command+=",";}
				command+="City = '"+POut.String(medLabFacility.City)+"'";
			}
			if(medLabFacility.State != oldMedLabFacility.State) {
				if(command!=""){ command+=",";}
				command+="State = '"+POut.String(medLabFacility.State)+"'";
			}
			if(medLabFacility.Zip != oldMedLabFacility.Zip) {
				if(command!=""){ command+=",";}
				command+="Zip = '"+POut.String(medLabFacility.Zip)+"'";
			}
			if(medLabFacility.Phone != oldMedLabFacility.Phone) {
				if(command!=""){ command+=",";}
				command+="Phone = '"+POut.String(medLabFacility.Phone)+"'";
			}
			if(medLabFacility.DirectorTitle != oldMedLabFacility.DirectorTitle) {
				if(command!=""){ command+=",";}
				command+="DirectorTitle = '"+POut.String(medLabFacility.DirectorTitle)+"'";
			}
			if(medLabFacility.DirectorLName != oldMedLabFacility.DirectorLName) {
				if(command!=""){ command+=",";}
				command+="DirectorLName = '"+POut.String(medLabFacility.DirectorLName)+"'";
			}
			if(medLabFacility.DirectorFName != oldMedLabFacility.DirectorFName) {
				if(command!=""){ command+=",";}
				command+="DirectorFName = '"+POut.String(medLabFacility.DirectorFName)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE medlabfacility SET "+command
				+" WHERE MedLabFacilityNum = "+POut.Long(medLabFacility.MedLabFacilityNum);
			Db.NonQ(command);
			return true;
		}
Exemplo n.º 15
0
		///<summary>Updates one MedLabFacility in the database.</summary>
		public static void Update(MedLabFacility medLabFacility){
			string command="UPDATE medlabfacility SET "
				+"FacilityName     = '"+POut.String(medLabFacility.FacilityName)+"', "
				+"Address          = '"+POut.String(medLabFacility.Address)+"', "
				+"City             = '"+POut.String(medLabFacility.City)+"', "
				+"State            = '"+POut.String(medLabFacility.State)+"', "
				+"Zip              = '"+POut.String(medLabFacility.Zip)+"', "
				+"Phone            = '"+POut.String(medLabFacility.Phone)+"', "
				+"DirectorTitle    = '"+POut.String(medLabFacility.DirectorTitle)+"', "
				+"DirectorLName    = '"+POut.String(medLabFacility.DirectorLName)+"', "
				+"DirectorFName    = '"+POut.String(medLabFacility.DirectorFName)+"' "
				+"WHERE MedLabFacilityNum = "+POut.Long(medLabFacility.MedLabFacilityNum);
			Db.NonQ(command);
		}