Ejemplo n.º 1
0
 ///<summary>Inserts one MedLabResult into the database.  Returns the new priKey.</summary>
 public static long Insert(MedLabResult medLabResult)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         medLabResult.MedLabResultNum = DbHelper.GetNextOracleKey("medlabresult", "MedLabResultNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(medLabResult, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     medLabResult.MedLabResultNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(medLabResult, false));
     }
 }
Ejemplo n.º 2
0
        ///<summary>Updates one MedLabResult in the database.</summary>
        public static void Update(MedLabResult medLabResult)
        {
            string command = "UPDATE medlabresult SET "
                             + "MedLabNum      =  " + POut.Long(medLabResult.MedLabNum) + ", "
                             + "ObsID          = '" + POut.String(medLabResult.ObsID) + "', "
                             + "ObsText        = '" + POut.String(medLabResult.ObsText) + "', "
                             + "ObsLoinc       = '" + POut.String(medLabResult.ObsLoinc) + "', "
                             + "ObsLoincText   = '" + POut.String(medLabResult.ObsLoincText) + "', "
                             + "ObsIDSub       = '" + POut.String(medLabResult.ObsIDSub) + "', "
                             + "ObsValue       =  " + DbHelper.ParamChar + "paramObsValue, "
                             + "ObsSubType     = '" + POut.String(medLabResult.ObsSubType.ToString()) + "', "
                             + "ObsUnits       = '" + POut.String(medLabResult.ObsUnits) + "', "
                             + "ReferenceRange = '" + POut.String(medLabResult.ReferenceRange) + "', "
                             + "AbnormalFlag   = '" + POut.String(medLabResult.AbnormalFlag.ToString()) + "', "
                             + "ResultStatus   = '" + POut.String(medLabResult.ResultStatus.ToString()) + "', "
                             + "DateTimeObs    =  " + POut.DateT(medLabResult.DateTimeObs) + ", "
                             + "FacilityID     = '" + POut.String(medLabResult.FacilityID) + "', "
                             + "DocNum         =  " + POut.Long(medLabResult.DocNum) + ", "
                             + "Note           =  " + DbHelper.ParamChar + "paramNote "
                             + "WHERE MedLabResultNum = " + POut.Long(medLabResult.MedLabResultNum);

            if (medLabResult.ObsValue == null)
            {
                medLabResult.ObsValue = "";
            }
            OdSqlParameter paramObsValue = new OdSqlParameter("paramObsValue", OdDbType.Text, POut.StringParam(medLabResult.ObsValue));

            if (medLabResult.Note == null)
            {
                medLabResult.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(medLabResult.Note));

            Db.NonQ(command, paramObsValue, paramNote);
        }
Ejemplo n.º 3
0
        ///<summary>Inserts one MedLabResult into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(MedLabResult medLabResult, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO medlabresult (";

            if (!useExistingPK && isRandomKeys)
            {
                medLabResult.MedLabResultNum = ReplicationServers.GetKeyNoCache("medlabresult", "MedLabResultNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "MedLabResultNum,";
            }
            command += "MedLabNum,ObsID,ObsText,ObsLoinc,ObsLoincText,ObsIDSub,ObsValue,ObsSubType,ObsUnits,ReferenceRange,AbnormalFlag,ResultStatus,DateTimeObs,FacilityID,DocNum,Note) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(medLabResult.MedLabResultNum) + ",";
            }
            command +=
                POut.Long(medLabResult.MedLabNum) + ","
                + "'" + POut.String(medLabResult.ObsID) + "',"
                + "'" + POut.String(medLabResult.ObsText) + "',"
                + "'" + POut.String(medLabResult.ObsLoinc) + "',"
                + "'" + POut.String(medLabResult.ObsLoincText) + "',"
                + "'" + POut.String(medLabResult.ObsIDSub) + "',"
                + DbHelper.ParamChar + "paramObsValue,"
                + "'" + POut.String(medLabResult.ObsSubType.ToString()) + "',"
                + "'" + POut.String(medLabResult.ObsUnits) + "',"
                + "'" + POut.String(medLabResult.ReferenceRange) + "',"
                + "'" + POut.String(medLabResult.AbnormalFlag.ToString()) + "',"
                + "'" + POut.String(medLabResult.ResultStatus.ToString()) + "',"
                + POut.DateT(medLabResult.DateTimeObs) + ","
                + "'" + POut.String(medLabResult.FacilityID) + "',"
                + POut.Long(medLabResult.DocNum) + ","
                + DbHelper.ParamChar + "paramNote)";
            if (medLabResult.ObsValue == null)
            {
                medLabResult.ObsValue = "";
            }
            OdSqlParameter paramObsValue = new OdSqlParameter("paramObsValue", OdDbType.Text, POut.StringParam(medLabResult.ObsValue));

            if (medLabResult.Note == null)
            {
                medLabResult.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(medLabResult.Note));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramObsValue, paramNote);
            }
            else
            {
                medLabResult.MedLabResultNum = Db.NonQ(command, true, "MedLabResultNum", "medLabResult", paramObsValue, paramNote);
            }
            return(medLabResult.MedLabResultNum);
        }
Ejemplo n.º 4
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<MedLabResult> TableToList(DataTable table){
			List<MedLabResult> retVal=new List<MedLabResult>();
			MedLabResult medLabResult;
			for(int i=0;i<table.Rows.Count;i++) {
				medLabResult=new MedLabResult();
				medLabResult.MedLabResultNum= PIn.Long  (table.Rows[i]["MedLabResultNum"].ToString());
				medLabResult.MedLabNum      = PIn.Long  (table.Rows[i]["MedLabNum"].ToString());
				medLabResult.ObsID          = PIn.String(table.Rows[i]["ObsID"].ToString());
				medLabResult.ObsText        = PIn.String(table.Rows[i]["ObsText"].ToString());
				medLabResult.ObsLoinc       = PIn.String(table.Rows[i]["ObsLoinc"].ToString());
				medLabResult.ObsLoincText   = PIn.String(table.Rows[i]["ObsLoincText"].ToString());
				medLabResult.ObsIDSub       = PIn.String(table.Rows[i]["ObsIDSub"].ToString());
				medLabResult.ObsValue       = PIn.String(table.Rows[i]["ObsValue"].ToString());
				string obsSubType=table.Rows[i]["ObsSubType"].ToString();
				if(obsSubType==""){
					medLabResult.ObsSubType   =(DataSubtype)0;
				}
				else try{
					medLabResult.ObsSubType   =(DataSubtype)Enum.Parse(typeof(DataSubtype),obsSubType);
				}
				catch{
					medLabResult.ObsSubType   =(DataSubtype)0;
				}
				medLabResult.ObsUnits       = PIn.String(table.Rows[i]["ObsUnits"].ToString());
				medLabResult.ReferenceRange = PIn.String(table.Rows[i]["ReferenceRange"].ToString());
				string abnormalFlag=table.Rows[i]["AbnormalFlag"].ToString();
				if(abnormalFlag==""){
					medLabResult.AbnormalFlag =(AbnormalFlag)0;
				}
				else try{
					medLabResult.AbnormalFlag =(AbnormalFlag)Enum.Parse(typeof(AbnormalFlag),abnormalFlag);
				}
				catch{
					medLabResult.AbnormalFlag =(AbnormalFlag)0;
				}
				string resultStatus=table.Rows[i]["ResultStatus"].ToString();
				if(resultStatus==""){
					medLabResult.ResultStatus =(ResultStatus)0;
				}
				else try{
					medLabResult.ResultStatus =(ResultStatus)Enum.Parse(typeof(ResultStatus),resultStatus);
				}
				catch{
					medLabResult.ResultStatus =(ResultStatus)0;
				}
				medLabResult.DateTimeObs    = PIn.DateT (table.Rows[i]["DateTimeObs"].ToString());
				medLabResult.FacilityID     = PIn.String(table.Rows[i]["FacilityID"].ToString());
				medLabResult.DocNum         = PIn.Long  (table.Rows[i]["DocNum"].ToString());
				medLabResult.Note           = PIn.String(table.Rows[i]["Note"].ToString());
				retVal.Add(medLabResult);
			}
			return retVal;
		}
Ejemplo n.º 5
0
 ///<summary>Inserts one MedLabResult into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(MedLabResult medLabResult)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(medLabResult, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             medLabResult.MedLabResultNum = DbHelper.GetNextOracleKey("medlabresult", "MedLabResultNum");                  //Cacheless method
         }
         return(InsertNoCache(medLabResult, true));
     }
 }
Ejemplo n.º 6
0
 ///<summary>Returns true if Update(MedLabResult,MedLabResult) 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(MedLabResult medLabResult, MedLabResult oldMedLabResult)
 {
     if (medLabResult.MedLabNum != oldMedLabResult.MedLabNum)
     {
         return(true);
     }
     if (medLabResult.ObsID != oldMedLabResult.ObsID)
     {
         return(true);
     }
     if (medLabResult.ObsText != oldMedLabResult.ObsText)
     {
         return(true);
     }
     if (medLabResult.ObsLoinc != oldMedLabResult.ObsLoinc)
     {
         return(true);
     }
     if (medLabResult.ObsLoincText != oldMedLabResult.ObsLoincText)
     {
         return(true);
     }
     if (medLabResult.ObsIDSub != oldMedLabResult.ObsIDSub)
     {
         return(true);
     }
     if (medLabResult.ObsValue != oldMedLabResult.ObsValue)
     {
         return(true);
     }
     if (medLabResult.ObsSubType != oldMedLabResult.ObsSubType)
     {
         return(true);
     }
     if (medLabResult.ObsUnits != oldMedLabResult.ObsUnits)
     {
         return(true);
     }
     if (medLabResult.ReferenceRange != oldMedLabResult.ReferenceRange)
     {
         return(true);
     }
     if (medLabResult.AbnormalFlag != oldMedLabResult.AbnormalFlag)
     {
         return(true);
     }
     if (medLabResult.ResultStatus != oldMedLabResult.ResultStatus)
     {
         return(true);
     }
     if (medLabResult.DateTimeObs != oldMedLabResult.DateTimeObs)
     {
         return(true);
     }
     if (medLabResult.FacilityID != oldMedLabResult.FacilityID)
     {
         return(true);
     }
     if (medLabResult.DocNum != oldMedLabResult.DocNum)
     {
         return(true);
     }
     if (medLabResult.Note != oldMedLabResult.Note)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <MedLabResult> TableToList(DataTable table)
        {
            List <MedLabResult> retVal = new List <MedLabResult>();
            MedLabResult        medLabResult;

            foreach (DataRow row in table.Rows)
            {
                medLabResult = new MedLabResult();
                medLabResult.MedLabResultNum = PIn.Long(row["MedLabResultNum"].ToString());
                medLabResult.MedLabNum       = PIn.Long(row["MedLabNum"].ToString());
                medLabResult.ObsID           = PIn.String(row["ObsID"].ToString());
                medLabResult.ObsText         = PIn.String(row["ObsText"].ToString());
                medLabResult.ObsLoinc        = PIn.String(row["ObsLoinc"].ToString());
                medLabResult.ObsLoincText    = PIn.String(row["ObsLoincText"].ToString());
                medLabResult.ObsIDSub        = PIn.String(row["ObsIDSub"].ToString());
                medLabResult.ObsValue        = PIn.String(row["ObsValue"].ToString());
                string obsSubType = row["ObsSubType"].ToString();
                if (obsSubType == "")
                {
                    medLabResult.ObsSubType = (DataSubtype)0;
                }
                else
                {
                    try{
                        medLabResult.ObsSubType = (DataSubtype)Enum.Parse(typeof(DataSubtype), obsSubType);
                    }
                    catch {
                        medLabResult.ObsSubType = (DataSubtype)0;
                    }
                }
                medLabResult.ObsUnits       = PIn.String(row["ObsUnits"].ToString());
                medLabResult.ReferenceRange = PIn.String(row["ReferenceRange"].ToString());
                string abnormalFlag = row["AbnormalFlag"].ToString();
                if (abnormalFlag == "")
                {
                    medLabResult.AbnormalFlag = (AbnormalFlag)0;
                }
                else
                {
                    try{
                        medLabResult.AbnormalFlag = (AbnormalFlag)Enum.Parse(typeof(AbnormalFlag), abnormalFlag);
                    }
                    catch {
                        medLabResult.AbnormalFlag = (AbnormalFlag)0;
                    }
                }
                string resultStatus = row["ResultStatus"].ToString();
                if (resultStatus == "")
                {
                    medLabResult.ResultStatus = (ResultStatus)0;
                }
                else
                {
                    try{
                        medLabResult.ResultStatus = (ResultStatus)Enum.Parse(typeof(ResultStatus), resultStatus);
                    }
                    catch {
                        medLabResult.ResultStatus = (ResultStatus)0;
                    }
                }
                medLabResult.DateTimeObs = PIn.DateT(row["DateTimeObs"].ToString());
                medLabResult.FacilityID  = PIn.String(row["FacilityID"].ToString());
                medLabResult.DocNum      = PIn.Long(row["DocNum"].ToString());
                medLabResult.Note        = PIn.String(row["Note"].ToString());
                retVal.Add(medLabResult);
            }
            return(retVal);
        }
Ejemplo n.º 8
0
        ///<summary>Updates one MedLabResult 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(MedLabResult medLabResult, MedLabResult oldMedLabResult)
        {
            string command = "";

            if (medLabResult.MedLabNum != oldMedLabResult.MedLabNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MedLabNum = " + POut.Long(medLabResult.MedLabNum) + "";
            }
            if (medLabResult.ObsID != oldMedLabResult.ObsID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsID = '" + POut.String(medLabResult.ObsID) + "'";
            }
            if (medLabResult.ObsText != oldMedLabResult.ObsText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsText = '" + POut.String(medLabResult.ObsText) + "'";
            }
            if (medLabResult.ObsLoinc != oldMedLabResult.ObsLoinc)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsLoinc = '" + POut.String(medLabResult.ObsLoinc) + "'";
            }
            if (medLabResult.ObsLoincText != oldMedLabResult.ObsLoincText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsLoincText = '" + POut.String(medLabResult.ObsLoincText) + "'";
            }
            if (medLabResult.ObsIDSub != oldMedLabResult.ObsIDSub)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsIDSub = '" + POut.String(medLabResult.ObsIDSub) + "'";
            }
            if (medLabResult.ObsValue != oldMedLabResult.ObsValue)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsValue = " + DbHelper.ParamChar + "paramObsValue";
            }
            if (medLabResult.ObsSubType != oldMedLabResult.ObsSubType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsSubType = '" + POut.String(medLabResult.ObsSubType.ToString()) + "'";
            }
            if (medLabResult.ObsUnits != oldMedLabResult.ObsUnits)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsUnits = '" + POut.String(medLabResult.ObsUnits) + "'";
            }
            if (medLabResult.ReferenceRange != oldMedLabResult.ReferenceRange)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ReferenceRange = '" + POut.String(medLabResult.ReferenceRange) + "'";
            }
            if (medLabResult.AbnormalFlag != oldMedLabResult.AbnormalFlag)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AbnormalFlag = '" + POut.String(medLabResult.AbnormalFlag.ToString()) + "'";
            }
            if (medLabResult.ResultStatus != oldMedLabResult.ResultStatus)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ResultStatus = '" + POut.String(medLabResult.ResultStatus.ToString()) + "'";
            }
            if (medLabResult.DateTimeObs != oldMedLabResult.DateTimeObs)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeObs = " + POut.DateT(medLabResult.DateTimeObs) + "";
            }
            if (medLabResult.FacilityID != oldMedLabResult.FacilityID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FacilityID = '" + POut.String(medLabResult.FacilityID) + "'";
            }
            if (medLabResult.DocNum != oldMedLabResult.DocNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DocNum = " + POut.Long(medLabResult.DocNum) + "";
            }
            if (medLabResult.Note != oldMedLabResult.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = " + DbHelper.ParamChar + "paramNote";
            }
            if (command == "")
            {
                return(false);
            }
            if (medLabResult.ObsValue == null)
            {
                medLabResult.ObsValue = "";
            }
            OdSqlParameter paramObsValue = new OdSqlParameter("paramObsValue", OdDbType.Text, POut.StringParam(medLabResult.ObsValue));

            if (medLabResult.Note == null)
            {
                medLabResult.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(medLabResult.Note));

            command = "UPDATE medlabresult SET " + command
                      + " WHERE MedLabResultNum = " + POut.Long(medLabResult.MedLabResultNum);
            Db.NonQ(command, paramObsValue, paramNote);
            return(true);
        }
Ejemplo n.º 9
0
        public void MiddleTier_GetListMedLabsSpecialChars()
        {
            List <MedLab> listMLabs = WebServiceTests.GetListMedLabsSpecialChars();
            List <string> strErrors = new List <string>();

            if (listMLabs == null || listMLabs.Count < 1)
            {
                strErrors.Add("The list of MedLabs is " + listMLabs == null?"null.":"empty.");
            }
            else
            {
                MedLab mlab = listMLabs[0];
                if (mlab.MedLabNum != 1)
                {
                    strErrors.Add("The MedLabNum should be 1 but returned " + mlab.MedLabNum + ".");
                }
                if (mlab.NoteLab != WebServiceTests.DirtyString)
                {
                    strErrors.Add(string.Format(@"The MedLab.NoteLab should be {0} but returned {1}.", WebServiceTests.DirtyString, mlab.NoteLab ?? "null"));
                }
                if (mlab.NotePat != WebServiceTests.NewLineString)
                {
                    strErrors.Add(string.Format(@"The MedLab.NotePat should be {0} but returned {1}.", WebServiceTests.NewLineString, mlab.NotePat ?? "null"));
                }
                if (mlab.ResultStatus != ResultStatus.P)
                {
                    strErrors.Add("The MedLab.ResultStatus should be " + ResultStatus.P + " but returned " + mlab.ResultStatus + ".");
                }
                if (mlab.DateTimeEntered == null || mlab.DateTimeEntered.Date != WebServiceTests.DateTodayTest.Date)
                {
                    strErrors.Add(string.Format("The MedLab.DateTimeEntered should be {0} but returned {1}.", WebServiceTests.DateTodayTest.ToShortDateString(),
                                                mlab.DateTimeEntered == null?"null":mlab.DateTimeEntered.ToShortDateString()));
                }
                if (mlab.DateTimeReported != WebServiceTests.DateTEntryTest)
                {
                    strErrors.Add(string.Format("The MedLab.DateTimeReported should be {0} but returned {1}.", WebServiceTests.DateTEntryTest.ToString(),
                                                mlab.DateTimeReported == null?"null":mlab.DateTimeReported.ToString()));
                }
                if (mlab.ListMedLabResults == null || mlab.ListMedLabResults.Count < 1)
                {
                    strErrors.Add("The list of MedLabResults for the MedLab is " + mlab.ListMedLabResults == null?"null.":"empty.");
                }
                else
                {
                    MedLabResult mlr = mlab.ListMedLabResults[0];
                    if (mlr.MedLabResultNum != 2)
                    {
                        strErrors.Add("The MedLabResultNum should be 2 but returned " + mlr.MedLabResultNum + ".");
                    }
                    if (mlr.MedLabNum != 1)
                    {
                        strErrors.Add("The MedLabResult.MedLabNum should be 1 but returned " + mlr.MedLabNum + ".");
                    }
                    if (mlr.Note != WebServiceTests.DirtyString)
                    {
                        strErrors.Add(string.Format(@"The MedLabResult.Note should be {0} but returned {1}.", WebServiceTests.DirtyString, mlr.Note ?? "null"));
                    }
                    if (mlr.ObsText != WebServiceTests.NewLineString)
                    {
                        strErrors.Add(string.Format(@"The MedLabResult.ObsText should be {0} but returned {1}.", WebServiceTests.NewLineString, mlr.ObsText ?? "null"));
                    }
                    if (mlr.ObsSubType != DataSubtype.PDF)
                    {
                        strErrors.Add("The MedLabResult.ObsSubType should be " + DataSubtype.PDF + " but returned " + mlr.ObsSubType + ".");
                    }
                    if (mlr.DateTimeObs != WebServiceTests.DateTEntryTest)
                    {
                        strErrors.Add(string.Format("The MedLabResult.DateTimeObs should be {0} but returned {1}.", WebServiceTests.DateTEntryTest.ToString(),
                                                    mlr.DateTimeObs == null?"null":mlr.DateTimeObs.ToString()));
                    }
                }
            }
            Assert.IsTrue(strErrors.Count == 0);
        }
Ejemplo n.º 10
0
 ///<summary>Inserts one MedLabResult into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(MedLabResult medLabResult)
 {
     return(InsertNoCache(medLabResult, false));
 }
Ejemplo n.º 11
0
		///<summary>Inserts one MedLabResult into the database.  Returns the new priKey.</summary>
		public static long Insert(MedLabResult medLabResult){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				medLabResult.MedLabResultNum=DbHelper.GetNextOracleKey("medlabresult","MedLabResultNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(medLabResult,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							medLabResult.MedLabResultNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(medLabResult,false);
			}
		}
Ejemplo n.º 12
0
		///<summary>Updates one MedLabResult 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(MedLabResult medLabResult,MedLabResult oldMedLabResult){
			string command="";
			if(medLabResult.MedLabNum != oldMedLabResult.MedLabNum) {
				if(command!=""){ command+=",";}
				command+="MedLabNum = "+POut.Long(medLabResult.MedLabNum)+"";
			}
			if(medLabResult.ObsID != oldMedLabResult.ObsID) {
				if(command!=""){ command+=",";}
				command+="ObsID = '"+POut.String(medLabResult.ObsID)+"'";
			}
			if(medLabResult.ObsText != oldMedLabResult.ObsText) {
				if(command!=""){ command+=",";}
				command+="ObsText = '"+POut.String(medLabResult.ObsText)+"'";
			}
			if(medLabResult.ObsLoinc != oldMedLabResult.ObsLoinc) {
				if(command!=""){ command+=",";}
				command+="ObsLoinc = '"+POut.String(medLabResult.ObsLoinc)+"'";
			}
			if(medLabResult.ObsLoincText != oldMedLabResult.ObsLoincText) {
				if(command!=""){ command+=",";}
				command+="ObsLoincText = '"+POut.String(medLabResult.ObsLoincText)+"'";
			}
			if(medLabResult.ObsIDSub != oldMedLabResult.ObsIDSub) {
				if(command!=""){ command+=",";}
				command+="ObsIDSub = '"+POut.String(medLabResult.ObsIDSub)+"'";
			}
			if(medLabResult.ObsValue != oldMedLabResult.ObsValue) {
				if(command!=""){ command+=",";}
				command+="ObsValue = "+DbHelper.ParamChar+"paramObsValue";
			}
			if(medLabResult.ObsSubType != oldMedLabResult.ObsSubType) {
				if(command!=""){ command+=",";}
				command+="ObsSubType = '"+POut.String(medLabResult.ObsSubType.ToString())+"'";
			}
			if(medLabResult.ObsUnits != oldMedLabResult.ObsUnits) {
				if(command!=""){ command+=",";}
				command+="ObsUnits = '"+POut.String(medLabResult.ObsUnits)+"'";
			}
			if(medLabResult.ReferenceRange != oldMedLabResult.ReferenceRange) {
				if(command!=""){ command+=",";}
				command+="ReferenceRange = '"+POut.String(medLabResult.ReferenceRange)+"'";
			}
			if(medLabResult.AbnormalFlag != oldMedLabResult.AbnormalFlag) {
				if(command!=""){ command+=",";}
				command+="AbnormalFlag = '"+POut.String(medLabResult.AbnormalFlag.ToString())+"'";
			}
			if(medLabResult.ResultStatus != oldMedLabResult.ResultStatus) {
				if(command!=""){ command+=",";}
				command+="ResultStatus = '"+POut.String(medLabResult.ResultStatus.ToString())+"'";
			}
			if(medLabResult.DateTimeObs != oldMedLabResult.DateTimeObs) {
				if(command!=""){ command+=",";}
				command+="DateTimeObs = "+POut.DateT(medLabResult.DateTimeObs)+"";
			}
			if(medLabResult.FacilityID != oldMedLabResult.FacilityID) {
				if(command!=""){ command+=",";}
				command+="FacilityID = '"+POut.String(medLabResult.FacilityID)+"'";
			}
			if(medLabResult.DocNum != oldMedLabResult.DocNum) {
				if(command!=""){ command+=",";}
				command+="DocNum = "+POut.Long(medLabResult.DocNum)+"";
			}
			if(medLabResult.Note != oldMedLabResult.Note) {
				if(command!=""){ command+=",";}
				command+="Note = "+DbHelper.ParamChar+"paramNote";
			}
			if(command==""){
				return false;
			}
			if(medLabResult.ObsValue==null) {
				medLabResult.ObsValue="";
			}
			OdSqlParameter paramObsValue=new OdSqlParameter("paramObsValue",OdDbType.Text,medLabResult.ObsValue);
			if(medLabResult.Note==null) {
				medLabResult.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,medLabResult.Note);
			command="UPDATE medlabresult SET "+command
				+" WHERE MedLabResultNum = "+POut.Long(medLabResult.MedLabResultNum);
			Db.NonQ(command,paramObsValue,paramNote);
			return true;
		}
Ejemplo n.º 13
0
		///<summary>Updates one MedLabResult in the database.</summary>
		public static void Update(MedLabResult medLabResult){
			string command="UPDATE medlabresult SET "
				+"MedLabNum      =  "+POut.Long  (medLabResult.MedLabNum)+", "
				+"ObsID          = '"+POut.String(medLabResult.ObsID)+"', "
				+"ObsText        = '"+POut.String(medLabResult.ObsText)+"', "
				+"ObsLoinc       = '"+POut.String(medLabResult.ObsLoinc)+"', "
				+"ObsLoincText   = '"+POut.String(medLabResult.ObsLoincText)+"', "
				+"ObsIDSub       = '"+POut.String(medLabResult.ObsIDSub)+"', "
				+"ObsValue       =  "+DbHelper.ParamChar+"paramObsValue, "
				+"ObsSubType     = '"+POut.String(medLabResult.ObsSubType.ToString())+"', "
				+"ObsUnits       = '"+POut.String(medLabResult.ObsUnits)+"', "
				+"ReferenceRange = '"+POut.String(medLabResult.ReferenceRange)+"', "
				+"AbnormalFlag   = '"+POut.String(medLabResult.AbnormalFlag.ToString())+"', "
				+"ResultStatus   = '"+POut.String(medLabResult.ResultStatus.ToString())+"', "
				+"DateTimeObs    =  "+POut.DateT (medLabResult.DateTimeObs)+", "
				+"FacilityID     = '"+POut.String(medLabResult.FacilityID)+"', "
				+"DocNum         =  "+POut.Long  (medLabResult.DocNum)+", "
				+"Note           =  "+DbHelper.ParamChar+"paramNote "
				+"WHERE MedLabResultNum = "+POut.Long(medLabResult.MedLabResultNum);
			if(medLabResult.ObsValue==null) {
				medLabResult.ObsValue="";
			}
			OdSqlParameter paramObsValue=new OdSqlParameter("paramObsValue",OdDbType.Text,medLabResult.ObsValue);
			if(medLabResult.Note==null) {
				medLabResult.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,medLabResult.Note);
			Db.NonQ(command,paramObsValue,paramNote);
		}
Ejemplo n.º 14
0
		///<summary>Inserts one MedLabResult into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(MedLabResult medLabResult,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				medLabResult.MedLabResultNum=ReplicationServers.GetKey("medlabresult","MedLabResultNum");
			}
			string command="INSERT INTO medlabresult (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="MedLabResultNum,";
			}
			command+="MedLabNum,ObsID,ObsText,ObsLoinc,ObsLoincText,ObsIDSub,ObsValue,ObsSubType,ObsUnits,ReferenceRange,AbnormalFlag,ResultStatus,DateTimeObs,FacilityID,DocNum,Note) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(medLabResult.MedLabResultNum)+",";
			}
			command+=
				     POut.Long  (medLabResult.MedLabNum)+","
				+"'"+POut.String(medLabResult.ObsID)+"',"
				+"'"+POut.String(medLabResult.ObsText)+"',"
				+"'"+POut.String(medLabResult.ObsLoinc)+"',"
				+"'"+POut.String(medLabResult.ObsLoincText)+"',"
				+"'"+POut.String(medLabResult.ObsIDSub)+"',"
				+    DbHelper.ParamChar+"paramObsValue,"
				+"'"+POut.String(medLabResult.ObsSubType.ToString())+"',"
				+"'"+POut.String(medLabResult.ObsUnits)+"',"
				+"'"+POut.String(medLabResult.ReferenceRange)+"',"
				+"'"+POut.String(medLabResult.AbnormalFlag.ToString())+"',"
				+"'"+POut.String(medLabResult.ResultStatus.ToString())+"',"
				+    POut.DateT (medLabResult.DateTimeObs)+","
				+"'"+POut.String(medLabResult.FacilityID)+"',"
				+    POut.Long  (medLabResult.DocNum)+","
				+    DbHelper.ParamChar+"paramNote)";
			if(medLabResult.ObsValue==null) {
				medLabResult.ObsValue="";
			}
			OdSqlParameter paramObsValue=new OdSqlParameter("paramObsValue",OdDbType.Text,medLabResult.ObsValue);
			if(medLabResult.Note==null) {
				medLabResult.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,medLabResult.Note);
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command,paramObsValue,paramNote);
			}
			else {
				medLabResult.MedLabResultNum=Db.NonQ(command,true,paramObsValue,paramNote);
			}
			return medLabResult.MedLabResultNum;
		}
Ejemplo n.º 15
0
		///<summary>This will insert a new MedLabResult object and set _medLabResultCur.</summary>
		public static void ProcessOBX(HL7DefSegment segDef,SegmentHL7 obxSeg) {
			if(_medLabResultCur!=null) {
				//if _medLabResultCur already exists and we're about to start another OBX, save the changes to _medLabResultCur before instantiating a new one
				MedLabResults.Update(_medLabResultCur);
			}
			_medLabResultCur=new MedLabResult();
			_medLabResultCur.MedLabNum=_medLabCur.MedLabNum;
			_isObsValueNte=false;
			for(int i=0;i<segDef.hl7DefFields.Count;i++) {
				HL7DefField fieldDefCur=segDef.hl7DefFields[i];
				switch(fieldDefCur.FieldName) {
					case "obsID":
						_medLabResultCur.ObsID=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						_medLabResultCur.ObsText=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos,1);
						_medLabResultCur.ObsLoinc=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos,3);
						_medLabResultCur.ObsLoincText=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos,4);
						continue;
					case "obsIDSub":
						_medLabResultCur.ObsIDSub=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						continue;
					case "obsValue":
						_medLabResultCur.ObsValue=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						if(_medLabResultCur.ObsValue.ToLower()=="tnp") {
							_medLabResultCur.ObsValue="Test Not Performed";
						}
						DataSubtype dataSubType;
						try {
							dataSubType=(DataSubtype)Enum.Parse(typeof(DataSubtype),obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos,2),true);
						}
						catch(Exception ex){
							dataSubType=DataSubtype.Unknown;
						}
						_medLabResultCur.ObsSubType=dataSubType;
						continue;
					case "obsValueType":
						if(obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos).ToLower()=="tx") {//if value type is text (TX) the value will be in attached NTEs
							_isObsValueNte=true;
						}
						continue;
					case "obsUnits":
						if(_medLabResultCur.ObsValue.ToLower()=="test not performed") {//if TNP then we won't bother saving the units
							continue;
						}
						_medLabResultCur.ObsUnits=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						if(obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos,1).Length>0) {
							if(_medLabResultCur.Note!=null && _medLabResultCur.Note.Length>0) {
								_medLabResultCur.Note+="\r\n";
							}
							_medLabResultCur.Note+="Units full text: "+obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos,1);
						}
						continue;
					case "obsRefRange":
						_medLabResultCur.ReferenceRange=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						continue;
					case "obsAbnormalFlag":
						_medLabResultCur.AbnormalFlag=FieldParserMedLab.AbnormalFlagParse(obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos));
						continue;
					case "resultStatus":
						_medLabResultCur.ResultStatus=FieldParserMedLab.ResultStatusParse(obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos));
						continue;
					case "dateTimeObs":
						_medLabResultCur.DateTimeObs=FieldParserMedLab.DateTimeParse(obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos));
						continue;
					case "facilityID":
						_medLabResultCur.FacilityID=obxSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						continue;
					default:
						continue;
				}
			}
			_medLabResultCur.MedLabResultNum=MedLabResults.Insert(_medLabResultCur);
			if(_medLabResultCur.FacilityID=="") {//no facility ID in the OBX segment, can't link to facilities in the ZPS segments
				return;
			}
			if(!_dictFacilityCodeNum.ContainsKey(_medLabResultCur.FacilityID)) {//no facility in the ZPS segments with this facility ID
				return;
			}
			List<long> facNumList=_dictFacilityCodeNum[_medLabResultCur.FacilityID];//should only be one facility in the ZPS segments with this ID
			for(int i=0;i<facNumList.Count;i++) {
				MedLabFacAttach medLabAttachCur=new MedLabFacAttach();
				medLabAttachCur.MedLabFacilityNum=facNumList[i];
				medLabAttachCur.MedLabResultNum=_medLabResultCur.MedLabResultNum;
				MedLabFacAttaches.Insert(medLabAttachCur);
			}
		}
Ejemplo n.º 16
0
		///<summary>Processes the msg and creates the MedLab, MedLabResult, MedLabSpecimen, MedLabFacility, and MedLabAttach objects.
		///Stores the msgArchiveFileName for each MedLab object created from the inbound message.
		///Each message will result in one MedLab object for each repitition of the ORC/OBR observation group in the message.
		///Each of the MedLab objects created will be linked to the msgArchiveFileName supplied.
		///Each repetition of the OBX result group will result in a MedLabResult object.
		///This returns a list of the MedLab.MedLabNums for all MedLab objects created from this message.
		///Use selectedPat to manually specify the patient to attach the objects and embedded files to.  Used when a patient could not be located using
		///the original message PID segment info and the user has now manually selected a patient.  The ZEF segments would not have been processed if a
		///patient could not be located and once the user selects the patient we will need to re-process the message to create the embedded PDFs.</summary>
		public static List<long> Process(MessageHL7 msg,string msgArchiveFileName,bool isVerboseLogging,Patient selectedPat=null) {
			_isVerboseLogging=isVerboseLogging;
			_msgArchiveFileName=msgArchiveFileName;
			_medLabNumList=new List<long>();
			_medLabCur=null;//make sure the last medlab object is cleared out
			_medLabResultCur=null;
			_patCur=null;
			HL7Def def=HL7Defs.GetOneDeepEnabled(true);
			if(def==null) {
				throw new Exception("Could not process the MedLab HL7 message.  No MedLab HL7 definition is enabled.");
			}
			_defCur=def;
			HL7DefMessage hl7defmsg=null;
			for(int i=0;i<def.hl7DefMessages.Count;i++) {
				//for now there are only incoming ORU messages supported, so there should only be one defined message type and it should be inbound
				if(def.hl7DefMessages[i].MessageType==msg.MsgType && def.hl7DefMessages[i].InOrOut==InOutHL7.Incoming) {
					hl7defmsg=def.hl7DefMessages[i];
					break;
				}
			}
			if(hl7defmsg==null) {//No message definition matches this message's MessageType and is Incoming
				throw new Exception("Could not process the MedLab HL7 message.  There is no definition for this type of message in the enabled MedLab HL7Def.");
			}
			#region Locate Patient
			//for MedLab interfaces, we limit the ability to rearrange the message structure, so the PID segment is always in position 1
			if(hl7defmsg.hl7DefSegments.Count<2 || msg.Segments.Count<2) {
				throw new Exception("Could not process the MedLab HL7 message.  "
					+"The message or message definition for this type of message does not contain the correct number of segments.");
			}
			HL7DefSegment pidSegDef=hl7defmsg.hl7DefSegments[1];
			SegmentHL7 pidSegCur=msg.Segments[1];
			if(pidSegDef.SegmentName!=SegmentNameHL7.PID || pidSegCur.Name!=SegmentNameHL7.PID) {
				throw new Exception("Could not process the MedLab HL7 message.  "
					+"The second segment in the message or message definition is not the PID segment.");
			}
			if(selectedPat==null) {
				//get the patient from the PID segment
				_patCur=GetPatFromPID(pidSegDef,pidSegCur);
			}
			if(_patCur==null) {//if no patient is located using PID segment or if selectedPat is not null, use selectedPat
				_patCur=selectedPat;//selectedPat could be null as well, but null _patCur is handled
			}
			#endregion Locate Patient
			#region Validate Message Structure
			if(hl7defmsg.hl7DefSegments.Count<1 || msg.Segments.Count<1) {
				throw new Exception("Could not process the MedLab HL7 message.  "
					+"The message or message definition for this type of message does not contain the correct number of segments.");
			}
			SegmentHL7 mshSegCur=msg.Segments[0];
			if(hl7defmsg.hl7DefSegments[0].SegmentName!=SegmentNameHL7.MSH || mshSegCur.Name!=SegmentNameHL7.MSH) {
				throw new Exception("Could not process the MedLab HL7 message.  "
					+"The first segment in the message or the message definition is not the MSH segment.");
			}
			SegmentHL7 nk1SegCur=null;
			List<SegmentHL7> listNteSegs=new List<SegmentHL7>();
			List<SegmentHL7> listZpsSegs=new List<SegmentHL7>();
			int indexFirstOrc=0;
			int indexFirstZps=0;
			//the third item could be the optional NK1 segment, followed by an optional and repeatable NTE segment, so the first ORC segment
			//could be anywhere after the PID segment in position 2.  This will tell us where the first ORC (order) repeatable group begins.
			for(int i=2;i<msg.Segments.Count;i++) {
				if(indexFirstZps>0 && msg.Segments[i].Name!=SegmentNameHL7.ZPS) {
					throw new Exception("Could not process the MedLab HL7 message.  There is a "+msg.Segments[i].Name.ToString()
						+" segment after a ZPS segment.  Incorrect message structure.");
				}
				if(msg.Segments[i].Name==SegmentNameHL7.NK1) {
					//the NK1 segment must come after the PID segment
					if(msg.Segments[i-1].Name!=SegmentNameHL7.PID) {
						throw new Exception("Could not process the MedLab HL7 message.  The NK1 segment was in the wrong position.  Incorrect message structure.");
					}
					nk1SegCur=msg.Segments[i];
					continue;
				}
				if(indexFirstOrc==0 && msg.Segments[i].Name==SegmentNameHL7.NTE) {//if we find an ORC segment, the NTEs that follow won't be at the PID level
					//the PID level NTE segments can follow after the PID segment, the optional NK1 segment, or other repetitions of the NTE segment
					if(msg.Segments[i-1].Name!=SegmentNameHL7.PID
						&& msg.Segments[i-1].Name!=SegmentNameHL7.NK1
						&& msg.Segments[i-1].Name!=SegmentNameHL7.NTE) 
					{
						throw new Exception("Could not process the MedLab HL7 message.  Found a NTE segment before an ORC segment but after a "
							+msg.Segments[i-1].Name.ToString()+" segment.  Incorrect message structure.");
					}
					listNteSegs.Add(msg.Segments[i]);
					continue;
				}
				if(msg.Segments[i].Name==SegmentNameHL7.ZPS) {
					if(indexFirstZps==0) {//this is the first ZPS segment we've encountered, set the index
						indexFirstZps=i;
					}
					listZpsSegs.Add(msg.Segments[i]);
					continue;
				}
				if(indexFirstOrc==0 && msg.Segments[i].Name==SegmentNameHL7.ORC) {//this is the first ORC segment we've encountered, set the index
					indexFirstOrc=i;
				}
			}
			#endregion Validate Message Structure
			#region Process Order Observations
			//We can process the ZPS segments before any of the other segments and then link each of the
			//MedLab objects created to each of the MedLabFacilities referenced by the ZPSs
			ProcessSeg(hl7defmsg,listZpsSegs,msg);
			List<SegmentHL7> listRepeatSegs=new List<SegmentHL7>();
			_isFirstObr=true;
			for(int i=indexFirstOrc;i<indexFirstZps;i++) {
				//for every repetition of the order observation, process the MSH, PID, NK1 and PID level NTE segments for a new MedLab object
				if(msg.Segments[i].Name==SegmentNameHL7.ORC) {
					ProcessSeg(hl7defmsg,new List<SegmentHL7> { mshSegCur },msg);//instatiates a new MedLab object _medLabCur and inserts to get PK
					ProcessSeg(hl7defmsg,new List<SegmentHL7> { pidSegCur },msg);
					//ProcessSeg(hl7defmsg,new List<SegmentHL7> { nk1SegCur },msg);
					if(listNteSegs.Count>0) {
						ProcessSeg(hl7defmsg,listNteSegs,msg,SegmentNameHL7.PID);
					}
					listRepeatSegs=new List<SegmentHL7>();
				}
				if(msg.Segments[i].Name==SegmentNameHL7.NTE
					|| msg.Segments[i].Name==SegmentNameHL7.ZEF
					|| msg.Segments[i].Name==SegmentNameHL7.SPM) {
					SegmentNameHL7 prevSegName=msg.Segments[i-1].Name;
					listRepeatSegs.Add(msg.Segments[i]);
					for(int j=i+1;j<indexFirstZps;j++) {
						if(msg.Segments[j].Name!=msg.Segments[i].Name) {
							i=j-1;
							break;
						}
						listRepeatSegs.Add(msg.Segments[j]);
					}
					ProcessSeg(hl7defmsg,listRepeatSegs,msg,prevSegName);
					listRepeatSegs=new List<SegmentHL7>();//clear out list for next repeatable segment
					continue;
				}
				//if the segment is an OBX, ProcessOBX will instantiate a new MedLabResult object, one for each repetition of the OBX, ZEF, NTE group
				ProcessSeg(hl7defmsg,new List<SegmentHL7> { msg.Segments[i] },msg);
			}
			MedLabs.Update(_medLabCur);
			MedLabResults.Update(_medLabResultCur);
			#endregion Process Order Observations
			return _medLabNumList;
		}