Example #1
0
        ///<summary>Inserts one EhrAptObs into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(EhrAptObs ehrAptObs, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO ehraptobs (";

            if (!useExistingPK && isRandomKeys)
            {
                ehrAptObs.EhrAptObsNum = ReplicationServers.GetKeyNoCache("ehraptobs", "EhrAptObsNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "EhrAptObsNum,";
            }
            command += "AptNum,IdentifyingCode,ValType,ValReported,UcumCode,ValCodeSystem) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(ehrAptObs.EhrAptObsNum) + ",";
            }
            command +=
                POut.Long(ehrAptObs.AptNum) + ","
                + POut.Int((int)ehrAptObs.IdentifyingCode) + ","
                + POut.Int((int)ehrAptObs.ValType) + ","
                + "'" + POut.String(ehrAptObs.ValReported) + "',"
                + "'" + POut.String(ehrAptObs.UcumCode) + "',"
                + "'" + POut.String(ehrAptObs.ValCodeSystem) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                ehrAptObs.EhrAptObsNum = Db.NonQ(command, true, "EhrAptObsNum", "ehrAptObs");
            }
            return(ehrAptObs.EhrAptObsNum);
        }
Example #2
0
 ///<summary>Returns true if Update(EhrAptObs,EhrAptObs) 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(EhrAptObs ehrAptObs, EhrAptObs oldEhrAptObs)
 {
     if (ehrAptObs.AptNum != oldEhrAptObs.AptNum)
     {
         return(true);
     }
     if (ehrAptObs.IdentifyingCode != oldEhrAptObs.IdentifyingCode)
     {
         return(true);
     }
     if (ehrAptObs.ValType != oldEhrAptObs.ValType)
     {
         return(true);
     }
     if (ehrAptObs.ValReported != oldEhrAptObs.ValReported)
     {
         return(true);
     }
     if (ehrAptObs.UcumCode != oldEhrAptObs.UcumCode)
     {
         return(true);
     }
     if (ehrAptObs.ValCodeSystem != oldEhrAptObs.ValCodeSystem)
     {
         return(true);
     }
     return(false);
 }
Example #3
0
        ///<summary>Inserts one EhrAptObs into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(EhrAptObs ehrAptObs, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                ehrAptObs.EhrAptObsNum = ReplicationServers.GetKey("ehraptobs", "EhrAptObsNum");
            }
            string command = "INSERT INTO ehraptobs (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "EhrAptObsNum,";
            }
            command += "AptNum,IdentifyingCode,ValType,ValReported,UcumCode,ValCodeSystem) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(ehrAptObs.EhrAptObsNum) + ",";
            }
            command +=
                POut.Long(ehrAptObs.AptNum) + ","
                + POut.Int((int)ehrAptObs.IdentifyingCode) + ","
                + POut.Int((int)ehrAptObs.ValType) + ","
                + "'" + POut.String(ehrAptObs.ValReported) + "',"
                + "'" + POut.String(ehrAptObs.UcumCode) + "',"
                + "'" + POut.String(ehrAptObs.ValCodeSystem) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                ehrAptObs.EhrAptObsNum = Db.NonQ(command, true);
            }
            return(ehrAptObs.EhrAptObsNum);
        }
Example #4
0
 ///<summary>Inserts one EhrAptObs into the database.  Returns the new priKey.</summary>
 public static long Insert(EhrAptObs ehrAptObs)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         ehrAptObs.EhrAptObsNum = DbHelper.GetNextOracleKey("ehraptobs", "EhrAptObsNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(ehrAptObs, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     ehrAptObs.EhrAptObsNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(ehrAptObs, false));
     }
 }
Example #5
0
        ///<summary>Updates one EhrAptObs 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.</summary>
        public static void Update(EhrAptObs ehrAptObs, EhrAptObs oldEhrAptObs)
        {
            string command = "";

            if (ehrAptObs.AptNum != oldEhrAptObs.AptNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AptNum = " + POut.Long(ehrAptObs.AptNum) + "";
            }
            if (ehrAptObs.IdentifyingCode != oldEhrAptObs.IdentifyingCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IdentifyingCode = " + POut.Int((int)ehrAptObs.IdentifyingCode) + "";
            }
            if (ehrAptObs.ValType != oldEhrAptObs.ValType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ValType = " + POut.Int((int)ehrAptObs.ValType) + "";
            }
            if (ehrAptObs.ValReported != oldEhrAptObs.ValReported)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ValReported = '" + POut.String(ehrAptObs.ValReported) + "'";
            }
            if (ehrAptObs.UcumCode != oldEhrAptObs.UcumCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UcumCode = '" + POut.String(ehrAptObs.UcumCode) + "'";
            }
            if (ehrAptObs.ValCodeSystem != oldEhrAptObs.ValCodeSystem)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ValCodeSystem = '" + POut.String(ehrAptObs.ValCodeSystem) + "'";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE ehraptobs SET " + command
                      + " WHERE EhrAptObsNum = " + POut.Long(ehrAptObs.EhrAptObsNum);
            Db.NonQ(command);
        }
Example #6
0
        ///<summary>Updates one EhrAptObs in the database.</summary>
        public static void Update(EhrAptObs ehrAptObs)
        {
            string command = "UPDATE ehraptobs SET "
                             + "AptNum         =  " + POut.Long(ehrAptObs.AptNum) + ", "
                             + "IdentifyingCode=  " + POut.Int((int)ehrAptObs.IdentifyingCode) + ", "
                             + "ValType        =  " + POut.Int((int)ehrAptObs.ValType) + ", "
                             + "ValReported    = '" + POut.String(ehrAptObs.ValReported) + "', "
                             + "UcumCode       = '" + POut.String(ehrAptObs.UcumCode) + "', "
                             + "ValCodeSystem  = '" + POut.String(ehrAptObs.ValCodeSystem) + "' "
                             + "WHERE EhrAptObsNum = " + POut.Long(ehrAptObs.EhrAptObsNum);

            Db.NonQ(command);
        }
Example #7
0
        private void gridObservations_CellDoubleClick(object sender, UI.ODGridClickEventArgs e)
        {
            EhrAptObs         obs   = (EhrAptObs)gridObservations.ListGridRows[e.Row].Tag;
            FormEhrAptObsEdit formE = new FormEhrAptObsEdit(obs);

            if (formE.ShowDialog() == DialogResult.OK)
            {
                if (obs.EhrAptObsNum != 0)               //Was not deleted.
                {
                    EhrAptObses.Update(obs);
                }
                FillGridObservations();
            }
        }
Example #8
0
        private void butAdd_Click(object sender, EventArgs e)
        {
            EhrAptObs obs = new EhrAptObs();

            obs.IsNew  = true;
            obs.AptNum = _appt.AptNum;
            FormEhrAptObsEdit formE = new FormEhrAptObsEdit(obs);

            if (formE.ShowDialog() == DialogResult.OK)
            {
                EhrAptObses.Insert(obs);
                FillGridObservations();
            }
        }
Example #9
0
 ///<summary>Inserts one EhrAptObs into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(EhrAptObs ehrAptObs)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(ehrAptObs, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             ehrAptObs.EhrAptObsNum = DbHelper.GetNextOracleKey("ehraptobs", "EhrAptObsNum");                  //Cacheless method
         }
         return(InsertNoCache(ehrAptObs, true));
     }
 }
Example #10
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<EhrAptObs> TableToList(DataTable table){
			List<EhrAptObs> retVal=new List<EhrAptObs>();
			EhrAptObs ehrAptObs;
			for(int i=0;i<table.Rows.Count;i++) {
				ehrAptObs=new EhrAptObs();
				ehrAptObs.EhrAptObsNum   = PIn.Long  (table.Rows[i]["EhrAptObsNum"].ToString());
				ehrAptObs.AptNum         = PIn.Long  (table.Rows[i]["AptNum"].ToString());
				ehrAptObs.IdentifyingCode= (OpenDentBusiness.EhrAptObsIdentifier)PIn.Int(table.Rows[i]["IdentifyingCode"].ToString());
				ehrAptObs.ValType        = (OpenDentBusiness.EhrAptObsType)PIn.Int(table.Rows[i]["ValType"].ToString());
				ehrAptObs.ValReported    = PIn.String(table.Rows[i]["ValReported"].ToString());
				ehrAptObs.UcumCode       = PIn.String(table.Rows[i]["UcumCode"].ToString());
				ehrAptObs.ValCodeSystem  = PIn.String(table.Rows[i]["ValCodeSystem"].ToString());
				retVal.Add(ehrAptObs);
			}
			return retVal;
		}
Example #11
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <EhrAptObs> TableToList(DataTable table)
        {
            List <EhrAptObs> retVal = new List <EhrAptObs>();
            EhrAptObs        ehrAptObs;

            foreach (DataRow row in table.Rows)
            {
                ehrAptObs = new EhrAptObs();
                ehrAptObs.EhrAptObsNum    = PIn.Long(row["EhrAptObsNum"].ToString());
                ehrAptObs.AptNum          = PIn.Long(row["AptNum"].ToString());
                ehrAptObs.IdentifyingCode = (OpenDentBusiness.EhrAptObsIdentifier)PIn.Int(row["IdentifyingCode"].ToString());
                ehrAptObs.ValType         = (OpenDentBusiness.EhrAptObsType)PIn.Int(row["ValType"].ToString());
                ehrAptObs.ValReported     = PIn.String(row["ValReported"].ToString());
                ehrAptObs.UcumCode        = PIn.String(row["UcumCode"].ToString());
                ehrAptObs.ValCodeSystem   = PIn.String(row["ValCodeSystem"].ToString());
                retVal.Add(ehrAptObs);
            }
            return(retVal);
        }
Example #12
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <EhrAptObs> TableToList(DataTable table)
        {
            List <EhrAptObs> retVal = new List <EhrAptObs>();
            EhrAptObs        ehrAptObs;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                ehrAptObs = new EhrAptObs();
                ehrAptObs.EhrAptObsNum    = PIn.Long(table.Rows[i]["EhrAptObsNum"].ToString());
                ehrAptObs.AptNum          = PIn.Long(table.Rows[i]["AptNum"].ToString());
                ehrAptObs.IdentifyingCode = (EhrAptObsIdentifier)PIn.Int(table.Rows[i]["IdentifyingCode"].ToString());
                ehrAptObs.ValType         = (EhrAptObsType)PIn.Int(table.Rows[i]["ValType"].ToString());
                ehrAptObs.ValReported     = PIn.String(table.Rows[i]["ValReported"].ToString());
                ehrAptObs.UcumCode        = PIn.String(table.Rows[i]["UcumCode"].ToString());
                ehrAptObs.ValCodeSystem   = PIn.String(table.Rows[i]["ValCodeSystem"].ToString());
                retVal.Add(ehrAptObs);
            }
            return(retVal);
        }
Example #13
0
		///<summary>Inserts one EhrAptObs into the database.  Returns the new priKey.</summary>
		public static long Insert(EhrAptObs ehrAptObs){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				ehrAptObs.EhrAptObsNum=DbHelper.GetNextOracleKey("ehraptobs","EhrAptObsNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(ehrAptObs,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							ehrAptObs.EhrAptObsNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(ehrAptObs,false);
			}
		}
Example #14
0
        private void FillGridObservations()
        {
            gridObservations.BeginUpdate();
            gridObservations.ListGridColumns.Clear();
            gridObservations.ListGridColumns.Add(new UI.GridColumn("Observation", 200));   //0
            gridObservations.ListGridColumns.Add(new UI.GridColumn("Value Type", 200));    //1
            gridObservations.ListGridColumns.Add(new UI.GridColumn("Value", 0));           //2
            gridObservations.ListGridRows.Clear();
            List <EhrAptObs> listEhrAptObses = EhrAptObses.Refresh(_appt.AptNum);

            for (int i = 0; i < listEhrAptObses.Count; i++)
            {
                EhrAptObs  obs = listEhrAptObses[i];
                UI.GridRow row = new UI.GridRow();
                row.Tag = obs;
                row.Cells.Add(obs.IdentifyingCode.ToString());                //0 Observation
                if (obs.ValType == EhrAptObsType.Coded)
                {
                    row.Cells.Add(obs.ValType.ToString() + " - " + obs.ValCodeSystem);                //1 Value Type
                    if (obs.ValCodeSystem == "LOINC")
                    {
                        Loinc loincValue = Loincs.GetByCode(obs.ValReported);
                        row.Cells.Add(loincValue.NameShort);                        //2 Value
                    }
                    else if (obs.ValCodeSystem == "SNOMEDCT")
                    {
                        Snomed snomedValue = Snomeds.GetByCode(obs.ValReported);
                        row.Cells.Add(snomedValue.Description);                        //2 Value
                    }
                    else if (obs.ValCodeSystem == "ICD9")
                    {
                        ICD9 icd9Value = ICD9s.GetByCode(obs.ValReported);
                        row.Cells.Add(icd9Value.Description);                        //2 Value
                    }
                    else if (obs.ValCodeSystem == "ICD10")
                    {
                        Icd10 icd10Value = Icd10s.GetByCode(obs.ValReported);
                        row.Cells.Add(icd10Value.Description);                        //2 Value
                    }
                }
                else if (obs.ValType == EhrAptObsType.Address)
                {
                    string sendingFacilityAddress1 = PrefC.GetString(PrefName.PracticeAddress);
                    string sendingFacilityAddress2 = PrefC.GetString(PrefName.PracticeAddress2);
                    string sendingFacilityCity     = PrefC.GetString(PrefName.PracticeCity);
                    string sendingFacilityState    = PrefC.GetString(PrefName.PracticeST);
                    string sendingFacilityZip      = PrefC.GetString(PrefName.PracticeZip);
                    if (PrefC.HasClinicsEnabled && _appt.ClinicNum != 0)                   //Using clinics and a clinic is assigned.
                    {
                        Clinic clinic = Clinics.GetClinic(_appt.ClinicNum);
                        sendingFacilityAddress1 = clinic.Address;
                        sendingFacilityAddress2 = clinic.Address2;
                        sendingFacilityCity     = clinic.City;
                        sendingFacilityState    = clinic.State;
                        sendingFacilityZip      = clinic.Zip;
                    }
                    row.Cells.Add(obs.ValType.ToString());                                                                                                                      //1 Value Type
                    row.Cells.Add(sendingFacilityAddress1 + " " + sendingFacilityAddress2 + " " + sendingFacilityCity + " " + sendingFacilityState + " " + sendingFacilityZip); //2 Value
                }
                else
                {
                    row.Cells.Add(obs.ValType.ToString());             //1 Value Type
                    row.Cells.Add(obs.ValReported);                    //2 Value
                }
                gridObservations.ListGridRows.Add(row);
            }
            gridObservations.EndUpdate();
        }
Example #15
0
		///<summary>Updates one EhrAptObs 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(EhrAptObs ehrAptObs,EhrAptObs oldEhrAptObs){
			string command="";
			if(ehrAptObs.AptNum != oldEhrAptObs.AptNum) {
				if(command!=""){ command+=",";}
				command+="AptNum = "+POut.Long(ehrAptObs.AptNum)+"";
			}
			if(ehrAptObs.IdentifyingCode != oldEhrAptObs.IdentifyingCode) {
				if(command!=""){ command+=",";}
				command+="IdentifyingCode = "+POut.Int   ((int)ehrAptObs.IdentifyingCode)+"";
			}
			if(ehrAptObs.ValType != oldEhrAptObs.ValType) {
				if(command!=""){ command+=",";}
				command+="ValType = "+POut.Int   ((int)ehrAptObs.ValType)+"";
			}
			if(ehrAptObs.ValReported != oldEhrAptObs.ValReported) {
				if(command!=""){ command+=",";}
				command+="ValReported = '"+POut.String(ehrAptObs.ValReported)+"'";
			}
			if(ehrAptObs.UcumCode != oldEhrAptObs.UcumCode) {
				if(command!=""){ command+=",";}
				command+="UcumCode = '"+POut.String(ehrAptObs.UcumCode)+"'";
			}
			if(ehrAptObs.ValCodeSystem != oldEhrAptObs.ValCodeSystem) {
				if(command!=""){ command+=",";}
				command+="ValCodeSystem = '"+POut.String(ehrAptObs.ValCodeSystem)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE ehraptobs SET "+command
				+" WHERE EhrAptObsNum = "+POut.Long(ehrAptObs.EhrAptObsNum);
			Db.NonQ(command);
			return true;
		}
Example #16
0
		///<summary>Updates one EhrAptObs in the database.</summary>
		public static void Update(EhrAptObs ehrAptObs){
			string command="UPDATE ehraptobs SET "
				+"AptNum         =  "+POut.Long  (ehrAptObs.AptNum)+", "
				+"IdentifyingCode=  "+POut.Int   ((int)ehrAptObs.IdentifyingCode)+", "
				+"ValType        =  "+POut.Int   ((int)ehrAptObs.ValType)+", "
				+"ValReported    = '"+POut.String(ehrAptObs.ValReported)+"', "
				+"UcumCode       = '"+POut.String(ehrAptObs.UcumCode)+"', "
				+"ValCodeSystem  = '"+POut.String(ehrAptObs.ValCodeSystem)+"' "
				+"WHERE EhrAptObsNum = "+POut.Long(ehrAptObs.EhrAptObsNum);
			Db.NonQ(command);
		}
Example #17
0
        public static string Validate(Appointment appt)
        {
            StringBuilder sb           = new StringBuilder();
            Provider      provFacility = Providers.GetProv(PrefC.GetInt(PrefName.PracticeDefaultProv));

            if (!Regex.IsMatch(provFacility.NationalProvID, "^(80840)?[0-9]{10}$"))
            {
                WriteError(sb, "Invalid NPI for provider '" + provFacility.Abbr + "'");
            }
            if (PrefC.HasClinicsEnabled && appt.ClinicNum != 0)           //Using clinics and a clinic is assigned.
            {
                Clinic clinic = Clinics.GetClinic(appt.ClinicNum);
                if (clinic.Description == "")
                {
                    WriteError(sb, "Missing clinic description for clinic attached to appointment.");
                }
            }
            else              //Not using clinics for this patient
            {
                if (PrefC.GetString(PrefName.PracticeTitle) == "")
                {
                    WriteError(sb, "Missing practice title.");
                }
            }
            Patient pat = Patients.GetPat(appt.PatNum);

            if (pat.PatStatus == PatientStatus.Deceased && pat.DateTimeDeceased.Year < 1880)
            {
                WriteError(sb, "Missing date time deceased.");
            }
            List <EhrAptObs> listObservations = EhrAptObses.Refresh(appt.AptNum);

            if (listObservations.Count == 0)
            {
                WriteError(sb, "Missing observation.");
            }
            for (int i = 0; i < listObservations.Count; i++)
            {
                EhrAptObs obs = listObservations[i];
                if (obs.ValType == EhrAptObsType.Coded)
                {
                    if (obs.ValCodeSystem.Trim().ToUpper() == "LOINC")
                    {
                        Loinc loincVal = Loincs.GetByCode(obs.ValReported);
                        if (loincVal == null)
                        {
                            WriteError(sb, "Loinc code not found '" + loincVal.LoincCode + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "SNOMEDCT")
                    {
                        Snomed snomedVal = Snomeds.GetByCode(obs.ValReported);
                        if (snomedVal == null)
                        {
                            WriteError(sb, "Snomed code not found '" + snomedVal.SnomedCode + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "ICD9")
                    {
                        ICD9 icd9Val = ICD9s.GetByCode(obs.ValReported);
                        if (icd9Val == null)
                        {
                            WriteError(sb, "ICD9 code not found '" + icd9Val.ICD9Code + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "ICD10")
                    {
                        Icd10 icd10Val = Icd10s.GetByCode(obs.ValReported);
                        if (icd10Val == null)
                        {
                            WriteError(sb, "ICD10 code not found '" + icd10Val.Icd10Code + "'.  Please add by going to Setup | Chart | EHR.");
                        }
                    }
                }
                else if (obs.ValType == EhrAptObsType.Numeric && obs.UcumCode != "")             //We only validate the ucum code if it will be sent out.  Blank units allowed.
                {
                    Ucum ucum = Ucums.GetByCode(obs.UcumCode);
                    if (ucum == null)
                    {
                        WriteError(sb, "Invalid unit code '" + obs.UcumCode + "' for observation (must be UCUM code).");
                    }
                }
            }
            return(sb.ToString());
        }
Example #18
0
        ///<summary>Observation/result segment.  Used to transmit observations related to the patient and visit.  Guide page 64.</summary>
        private void OBX()
        {
            List <EhrAptObs> listObservations = EhrAptObses.Refresh(_appt.AptNum);

            for (int i = 0; i < listObservations.Count; i++)
            {
                EhrAptObs obs = listObservations[i];
                _seg = new SegmentHL7(SegmentNameHL7.OBX);
                _seg.SetField(0, "OBX");
                _seg.SetField(1, (i + 1).ToString());             //OBX-1 Set ID - OBX.  Required (length 1..4).  Must start at 1 and increment.
                //OBX-2 Value Type.  Required (length 1..3).  Cardinality [1..1].  Identifies the structure of data in observation value OBX-5.  Values allowed: TS=Time Stamp (Date and/or Time),TX=Text,NM=Numeric,CWE=Coded with exceptions,XAD=Address.
                if (obs.ValType == EhrAptObsType.Coded)
                {
                    _seg.SetField(2, "CWE");
                }
                else if (obs.ValType == EhrAptObsType.DateAndTime)
                {
                    _seg.SetField(2, "TS");
                }
                else if (obs.ValType == EhrAptObsType.Numeric)
                {
                    _seg.SetField(2, "NM");
                }
                else                  //obs.ValType==EhrAptObsType.Text
                {
                    _seg.SetField(2, "TX");
                }
                //OBX-3 Observation Identifier.  Required (length up to 478).  Cardinality [1..1].  Value set is HL7 table named "Observation Identifier".  Type CE.  We use LOINC codes because the testing tool used LOINC codes and so do vaccines.
                string obsIdCode         = "";
                string obsIdCodeDescript = "";
                string obsIdCodeSystem   = "LN";
                if (obs.IdentifyingCode == EhrAptObsIdentifier.BodyTemp)
                {
                    obsIdCode         = "11289-6";
                    obsIdCodeDescript = "Body temperature:Temp:Enctrfrst:Patient:Qn:";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.CheifComplaint)
                {
                    obsIdCode         = "8661-1";
                    obsIdCodeDescript = "Chief complaint:Find:Pt:Patient:Nom:Reported";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.DateIllnessOrInjury)
                {
                    obsIdCode         = "11368-8";
                    obsIdCodeDescript = "Illness or injury onset date and time:TmStp:Pt:Patient:Qn:";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.OxygenSaturation)
                {
                    obsIdCode         = "59408-5";
                    obsIdCodeDescript = "Oxygen saturation:MFr:Pt:BldA:Qn:Pulse oximetry";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.PatientAge)
                {
                    obsIdCode         = "21612-7";
                    obsIdCodeDescript = "Age Time Patient Reported";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.PrelimDiag)
                {
                    obsIdCode         = "44833-2";
                    obsIdCodeDescript = "Diagnosis.preliminary:Imp:Pt:Patient:Nom:";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.TreatFacilityID)
                {
                    obsIdCode         = "SS001";
                    obsIdCodeDescript = "Treating Facility Identifier";
                    obsIdCodeSystem   = "PHINQUESTION";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.TreatFacilityLocation)
                {
                    obsIdCode         = "SS002";
                    obsIdCodeDescript = "Treating Facility Location";
                    obsIdCodeSystem   = "PHINQUESTION";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.TriageNote)
                {
                    obsIdCode         = "54094-8";
                    obsIdCodeDescript = "Triage note:Find:Pt:Emergency department:Doc:";
                }
                else if (obs.IdentifyingCode == EhrAptObsIdentifier.VisitType)
                {
                    obsIdCode         = "SS003";
                    obsIdCodeDescript = "Facility / Visit Type";
                    obsIdCodeSystem   = "PHINQUESTION";
                }
                WriteCE(3, obsIdCode, obsIdCodeDescript, obsIdCodeSystem);
                //OBX-4 Observation Sub-ID.  No longer used.
                //OBX-5 Observation Value.  Required if known (length 1..99999).  Value must match type in OBX-2.
                if (obs.ValType == EhrAptObsType.Address)
                {
                    WriteXAD(5, _sendingFacilityAddress1, _sendingFacilityAddress2, _sendingFacilityCity, _sendingFacilityState, _sendingFacilityZip);
                }
                else if (obs.ValType == EhrAptObsType.Coded)
                {
                    string codeDescript     = "";
                    string codeSystemAbbrev = "";
                    if (obs.ValCodeSystem.Trim().ToUpper() == "LOINC")
                    {
                        Loinc loincVal = Loincs.GetByCode(obs.ValReported);
                        codeDescript     = loincVal.NameShort;
                        codeSystemAbbrev = "LN";
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "SNOMEDCT")
                    {
                        Snomed snomedVal = Snomeds.GetByCode(obs.ValReported);
                        codeDescript     = snomedVal.Description;
                        codeSystemAbbrev = "SCT";
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "ICD9")
                    {
                        ICD9 icd9Val = ICD9s.GetByCode(obs.ValReported);
                        codeDescript     = icd9Val.Description;
                        codeSystemAbbrev = "I9";
                    }
                    else if (obs.ValCodeSystem.Trim().ToUpper() == "ICD10")
                    {
                        Icd10 icd10Val = Icd10s.GetByCode(obs.ValReported);
                        codeDescript     = icd10Val.Description;
                        codeSystemAbbrev = "I10";
                    }
                    WriteCE(5, obs.ValReported.Trim(), codeDescript, codeSystemAbbrev);
                }
                else if (obs.ValType == EhrAptObsType.DateAndTime)
                {
                    DateTime dateVal    = DateTime.Parse(obs.ValReported.Trim());
                    string   strDateOut = dateVal.ToString("yyyyMMdd");
                    //The testing tool threw errors when there were trailing zeros, even though technically valid.
                    if (dateVal.Second > 0)
                    {
                        strDateOut += dateVal.ToString("HHmmss");
                    }
                    else if (dateVal.Minute > 0)
                    {
                        strDateOut += dateVal.ToString("HHmm");
                    }
                    else if (dateVal.Hour > 0)
                    {
                        strDateOut += dateVal.ToString("HH");
                    }
                    _seg.SetField(5, strDateOut);
                }
                else if (obs.ValType == EhrAptObsType.Numeric)
                {
                    _seg.SetField(5, obs.ValReported.Trim());
                }
                else                   //obs.ValType==EhrAptObsType.Text
                {
                    _seg.SetField(5, obs.ValReported);
                }
                //OBX-6 Units.  Required if OBX-2 is NM=Numeric.  Cardinality [0..1].  Type CE.  The guide suggests value sets: Pulse Oximetry Unit, Temperature Unit, or Age Unit.  However, the testing tool used UCUM, so we will use UCUM.
                if (obs.ValType == EhrAptObsType.Numeric)
                {
                    if (String.IsNullOrEmpty(obs.UcumCode))                      //If units are required but known, we must send a null flavor.
                    {
                        WriteCE(6, "UNK", "", "NULLFL");
                    }
                    else
                    {
                        Ucum ucum = Ucums.GetByCode(obs.UcumCode);
                        WriteCE(6, ucum.UcumCode, ucum.Description, "UCUM");
                    }
                }
                //OBX-7 References Range.  No longer used.
                //OBX-8 Abnormal Flags.  No longer used.
                //OBX-9 Probability.  No longer used.
                //OBX-10 Nature of Abnormal Test.  No longer used.
                _seg.SetField(11, "F");               //OBX-11 Observation Result Status.  Required (length 1..1).  Expected value is "F".
                //OBX-12 Effective Date of Reference Range.  No longer used.
                //OBX-13 User Defined Access Checks.  No longer used.
                //OBX-14 Date/Time of the Observation.  Optional.
                //OBX-15 Producer's ID.  No longer used.
                //OBX-16 Responsible Observer.  No longer used.
                //OBX-17 Observation Method.  No longer used.
                //OBX-18 Equipment Instance Identifier.  No longer used.
                //OBX-19 Date/Time of the Analysis.  No longer used.
                _msg.Segments.Add(_seg);
            }
        }
Example #19
0
		///<summary>Inserts one EhrAptObs into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(EhrAptObs ehrAptObs,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				ehrAptObs.EhrAptObsNum=ReplicationServers.GetKey("ehraptobs","EhrAptObsNum");
			}
			string command="INSERT INTO ehraptobs (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="EhrAptObsNum,";
			}
			command+="AptNum,IdentifyingCode,ValType,ValReported,UcumCode,ValCodeSystem) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(ehrAptObs.EhrAptObsNum)+",";
			}
			command+=
				     POut.Long  (ehrAptObs.AptNum)+","
				+    POut.Int   ((int)ehrAptObs.IdentifyingCode)+","
				+    POut.Int   ((int)ehrAptObs.ValType)+","
				+"'"+POut.String(ehrAptObs.ValReported)+"',"
				+"'"+POut.String(ehrAptObs.UcumCode)+"',"
				+"'"+POut.String(ehrAptObs.ValCodeSystem)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				ehrAptObs.EhrAptObsNum=Db.NonQ(command,true);
			}
			return ehrAptObs.EhrAptObsNum;
		}
Example #20
0
 public FormEhrAptObsEdit(EhrAptObs ehrAptObs)
 {
     InitializeComponent();
     Lan.F(this);
     _ehrAptObsCur = ehrAptObs;
 }
Example #21
0
 ///<summary>Inserts one EhrAptObs into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(EhrAptObs ehrAptObs)
 {
     return(InsertNoCache(ehrAptObs, false));
 }