Exemple #1
0
 ///<summary>Inserts one MedLab into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(MedLab medLab)
 {
     return(InsertNoCache(medLab, false));
 }
Exemple #2
0
        ///<summary>Inserts one MedLab into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(MedLab medLab, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO medlab (";

            if (!useExistingPK && isRandomKeys)
            {
                medLab.MedLabNum = ReplicationServers.GetKeyNoCache("medlab", "MedLabNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "MedLabNum,";
            }
            command += "ProvNum,SendingApp,SendingFacility,PatNum,PatIDLab,PatIDAlt,PatAge,PatAccountNum,PatFasting,SpecimenID,SpecimenIDFiller,ObsTestID,ObsTestDescript,ObsTestLoinc,ObsTestLoincText,DateTimeCollected,TotalVolume,ActionCode,ClinicalInfo,DateTimeEntered,OrderingProvNPI,OrderingProvLocalID,OrderingProvLName,OrderingProvFName,SpecimenIDAlt,DateTimeReported,ResultStatus,ParentObsID,ParentObsTestID,NotePat,NoteLab,FileName,OriginalPIDSegment) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(medLab.MedLabNum) + ",";
            }
            command +=
                POut.Long(medLab.ProvNum) + ","
                + "'" + POut.String(medLab.SendingApp) + "',"
                + "'" + POut.String(medLab.SendingFacility) + "',"
                + POut.Long(medLab.PatNum) + ","
                + "'" + POut.String(medLab.PatIDLab) + "',"
                + "'" + POut.String(medLab.PatIDAlt) + "',"
                + "'" + POut.String(medLab.PatAge) + "',"
                + "'" + POut.String(medLab.PatAccountNum) + "',"
                + POut.Int((int)medLab.PatFasting) + ","
                + "'" + POut.String(medLab.SpecimenID) + "',"
                + "'" + POut.String(medLab.SpecimenIDFiller) + "',"
                + "'" + POut.String(medLab.ObsTestID) + "',"
                + "'" + POut.String(medLab.ObsTestDescript) + "',"
                + "'" + POut.String(medLab.ObsTestLoinc) + "',"
                + "'" + POut.String(medLab.ObsTestLoincText) + "',"
                + POut.DateT(medLab.DateTimeCollected) + ","
                + "'" + POut.String(medLab.TotalVolume) + "',"
                + "'" + POut.String(medLab.ActionCode.ToString()) + "',"
                + "'" + POut.String(medLab.ClinicalInfo) + "',"
                + POut.DateT(medLab.DateTimeEntered) + ","
                + "'" + POut.String(medLab.OrderingProvNPI) + "',"
                + "'" + POut.String(medLab.OrderingProvLocalID) + "',"
                + "'" + POut.String(medLab.OrderingProvLName) + "',"
                + "'" + POut.String(medLab.OrderingProvFName) + "',"
                + "'" + POut.String(medLab.SpecimenIDAlt) + "',"
                + POut.DateT(medLab.DateTimeReported) + ","
                + "'" + POut.String(medLab.ResultStatus.ToString()) + "',"
                + "'" + POut.String(medLab.ParentObsID) + "',"
                + "'" + POut.String(medLab.ParentObsTestID) + "',"
                + DbHelper.ParamChar + "paramNotePat,"
                + DbHelper.ParamChar + "paramNoteLab,"
                + "'" + POut.String(medLab.FileName) + "',"
                + DbHelper.ParamChar + "paramOriginalPIDSegment)";
            if (medLab.NotePat == null)
            {
                medLab.NotePat = "";
            }
            OdSqlParameter paramNotePat = new OdSqlParameter("paramNotePat", OdDbType.Text, POut.StringParam(medLab.NotePat));

            if (medLab.NoteLab == null)
            {
                medLab.NoteLab = "";
            }
            OdSqlParameter paramNoteLab = new OdSqlParameter("paramNoteLab", OdDbType.Text, POut.StringParam(medLab.NoteLab));

            if (medLab.OriginalPIDSegment == null)
            {
                medLab.OriginalPIDSegment = "";
            }
            OdSqlParameter paramOriginalPIDSegment = new OdSqlParameter("paramOriginalPIDSegment", OdDbType.Text, POut.StringParam(medLab.OriginalPIDSegment));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramNotePat, paramNoteLab, paramOriginalPIDSegment);
            }
            else
            {
                medLab.MedLabNum = Db.NonQ(command, true, "MedLabNum", "medLab", paramNotePat, paramNoteLab, paramOriginalPIDSegment);
            }
            return(medLab.MedLabNum);
        }
        private void FillGridResultHist()
        {
            MedLab medLabCur = MedLabs.GetOne(ResultCur.MedLabNum);

            if (medLabCur == null)           //should never happen, but we must have a MedLab object to fill the grid
            {
                return;
            }
            gridResultHist.BeginUpdate();
            gridResultHist.Columns.Clear();
            ODGridColumn col;

            col = new ODGridColumn("Result Description / Value", 425);
            gridResultHist.Columns.Add(col);
            col = new ODGridColumn("Flag", 110);
            gridResultHist.Columns.Add(col);
            col = new ODGridColumn("Units", 65);
            gridResultHist.Columns.Add(col);
            col = new ODGridColumn("Date/Time Reported", 130);         //OBR-22, Date/Time Observations Reported
            col.SortingStrategy = GridSortingStrategy.DateParse;
            gridResultHist.Columns.Add(col);
            col = new ODGridColumn("Date/Time Observed", 130);         //OBX-11, Date/Time of Observation
            col.SortingStrategy = GridSortingStrategy.DateParse;
            gridResultHist.Columns.Add(col);
            col = new ODGridColumn("Status", 70);
            gridResultHist.Columns.Add(col);
            gridResultHist.Rows.Clear();
            ODGridRow row;
            long      patNum = 0;

            if (PatCur != null)
            {
                patNum = PatCur.PatNum;
            }
            List <MedLabResult> listResults = MedLabResults.GetResultHist(ResultCur, patNum, medLabCur.SpecimenID, medLabCur.SpecimenIDFiller);

            for (int i = 0; i < listResults.Count; i++)
            {
                row = new ODGridRow();
                string obsVal = listResults[i].ObsText;
                if (listResults[i].ObsValue != "Test Not Performed")
                {
                    obsVal += "\r\n    " + listResults[i].ObsValue.Replace("\r\n", "\r\n    ");
                }
                if (listResults[i].Note != "")
                {
                    obsVal += "\r\n    " + listResults[i].Note.Replace("\r\n", "\r\n    ");
                }
                row.Cells.Add(obsVal);
                row.Cells.Add(MedLabResults.GetAbnormalFlagDescript(listResults[i].AbnormalFlag));
                row.Cells.Add(listResults[i].ObsUnits);
                medLabCur = MedLabs.GetOne(listResults[i].MedLabNum);
                string dateReported = "";
                if (medLabCur != null)
                {
                    dateReported = medLabCur.DateTimeReported.ToString("MM/dd/yyyy hh:mm tt");                  //DT format matches LabCorp examples (US only company)
                }
                row.Cells.Add(dateReported);
                row.Cells.Add(listResults[i].DateTimeObs.ToString("MM/dd/yyyy hh:mm tt"));                //DT format matches LabCorp examples (US only company)
                row.Cells.Add(MedLabs.GetStatusDescript(listResults[i].ResultStatus));
                gridResultHist.Rows.Add(row);
            }
            gridResultHist.EndUpdate();
        }
Exemple #4
0
 ///<summary>Inserts one MedLab into the database.  Returns the new priKey.</summary>
 public static long Insert(MedLab medLab)
 {
     return(Insert(medLab, false));
 }
Exemple #5
0
        ///<summary>Formatting for fields in this grid designed to emulate as accurately as possible the sample provided by LabCorp.</summary>
        private void FillGridResults()
        {
            gridResults.BeginUpdate();
            gridResults.Columns.Clear();
            ODGridColumn col;

            col = new ODGridColumn("Test / Result", 500);
            gridResults.Columns.Add(col);
            col = new ODGridColumn("Flag", 115);
            gridResults.Columns.Add(col);
            col = new ODGridColumn("Units", 110);
            gridResults.Columns.Add(col);
            col = new ODGridColumn("Reference Interval", 145);
            gridResults.Columns.Add(col);
            col = new ODGridColumn("Lab", 60);
            gridResults.Columns.Add(col);
            gridResults.Rows.Clear();
            ODGridRow row;
            string    obsDescriptPrev = "";

            for (int i = 0; i < _listResults.Count; i++)
            {
                //LabCorp requested that these non-performance results not be displayed on the report
                if ((_listResults[i].ResultStatus == ResultStatus.F || _listResults[i].ResultStatus == ResultStatus.X) &&
                    _listResults[i].ObsValue == "" &&
                    _listResults[i].Note == "")
                {
                    continue;
                }
                string obsDescript = "";
                MedLab medLabCur   = MedLabs.GetOne(_listResults[i].MedLabNum);
                //Only dipslay full medLabCur.ObsTestDescript if different than previous Descript.
                if (i == 0 || _listResults[i].MedLabNum != _listResults[i - 1].MedLabNum)
                {
                    if (medLabCur.ActionCode != ResultAction.G)
                    {
                        if (obsDescriptPrev == medLabCur.ObsTestDescript)
                        {
                            obsDescript = ".";
                        }
                        else
                        {
                            obsDescript     = medLabCur.ObsTestDescript;
                            obsDescriptPrev = obsDescript;
                        }
                    }
                }
                //Set tabs using spaces and spaces2, can be changed further down in the code
                string spaces  = "    ";
                string spaces2 = "        ";
                string obsVal  = "";
                int    padR    = 78;
                string newLine = "";
                if (obsDescript != "")
                {
                    if (obsDescript == _listResults[i].ObsText)
                    {
                        spaces  = "";
                        spaces2 = "    ";
                        padR    = 80;
                    }
                    else
                    {
                        obsVal  += obsDescript + "\r\n";
                        newLine += "\r\n";
                    }
                }
                if (_listResults[i].ObsValue == "Test Not Performed")
                {
                    obsVal += spaces + _listResults[i].ObsText;
                }
                else if (_listResults[i].ObsText == "." ||
                         _listResults[i].ObsValue.Contains(":") ||
                         _listResults[i].ObsValue.Length > 20 ||
                         medLabCur.ActionCode == ResultAction.G)
                {
                    obsVal  += spaces + _listResults[i].ObsText + "\r\n" + spaces2 + _listResults[i].ObsValue.Replace("\r\n", "\r\n" + spaces2);
                    newLine += "\r\n";
                }
                else
                {
                    obsVal += spaces + _listResults[i].ObsText.PadRight(padR, ' ') + _listResults[i].ObsValue;
                }
                if (_listResults[i].Note != "")
                {
                    obsVal += "\r\n" + spaces2 + _listResults[i].Note.Replace("\r\n", "\r\n" + spaces2);
                }
                row = new ODGridRow();
                row.Cells.Add(obsVal);
                row.Cells.Add(newLine + MedLabResults.GetAbnormalFlagDescript(_listResults[i].AbnormalFlag));
                row.Cells.Add(newLine + _listResults[i].ObsUnits);
                row.Cells.Add(newLine + _listResults[i].ReferenceRange);
                row.Cells.Add(newLine + _listResults[i].FacilityID);
                row.Tag = _listResults[i];
                gridResults.Rows.Add(row);
            }
            gridResults.EndUpdate();
        }
Exemple #6
0
        ///<summary>Moves all MedLab objects and any embedded PDFs tied to the MedLabResults to the PatCur.
        ///If the MedLab objects were not originally attached to a patient, any embedded PDFs will be in the image folder in a directory called
        ///"MedLabEmbeddedFiles" and will be moved to PatCur's image folder.
        ///If PatCur is null or the MedLabs are already attached to PatCur, does nothing.</summary>
        private void MoveLabsAndImagesHelper()
        {
            //if they have selected the same patient, nothing to do
            if (PatCur == null || PatCur.PatNum == _medLabCur.PatNum)
            {
                return;
            }
            //if the MedLab object(s) were attached to a patient and they are being moved to another patient, move the associated documents
            Patient patOld = Patients.GetPat(_medLabCur.PatNum);

            MedLabs.UpdateAllPatNums(ListMedLabs.Select(x => x.MedLabNum).ToList(), PatCur.PatNum);
            string atozFrom = "";
            string atozTo   = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                string atozPath = ImageStore.GetPreferredAtoZpath();
                //if patOld is null, the file was placed into the image folder in a directory named MedLabEmbeddedFiles, not a patient's image folder
                if (patOld == null)
                {
                    atozFrom = ODFileUtils.CombinePaths(atozPath, "MedLabEmbeddedFiles");
                }
                else
                {
                    atozFrom = ImageStore.GetPatientFolder(patOld, atozPath);
                }
                atozTo = ImageStore.GetPatientFolder(PatCur, atozPath);
            }
            else if (CloudStorage.IsCloudStorage)
            {
                atozFrom = ODFileUtils.CombinePaths(ImageStore.GetPreferredAtoZpath(), "MedLabEmbeddedFiles", '/');
                atozTo   = ImageStore.GetPatientFolder(PatCur, "");
            }
            //get list of all DocNums of files referenced by MedLabResults which were embedded in the MedLab HL7 message as base64 text
            //in order to move the file (if not storing images in db) and assign (or reassign) the FileName
            List <long> listDocNums = ListMedLabs
                                      .SelectMany(x => x.ListMedLabResults
                                                  .Select(y => y.DocNum)
                                                  .Where(y => y > 0))
                                      .Distinct().ToList();
            List <Document> listDocs         = Documents.GetByNums(listDocNums);
            int             fileMoveFailures = 0;

            for (int i = 0; i < listDocs.Count; i++)
            {
                Document doc          = listDocs[i];
                string   destFileName = Documents.GetUniqueFileNameForPatient(PatCur, doc.DocNum, Path.GetExtension(doc.FileName));
                if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
                {
                    string fromFilePath = ODFileUtils.CombinePaths(atozFrom, doc.FileName);
                    if (!File.Exists(fromFilePath))
                    {
                        //the DocNum in the MedLabResults table is pointing to a file that either doesn't exist or is not accessible, can't move/copy it
                        fileMoveFailures++;
                        continue;
                    }
                    string destFilePath = ODFileUtils.CombinePaths(atozTo, destFileName);
                    if (File.Exists(destFilePath))                     //should never happen, since we already got a unique file name, but just in case
                    //The file being copied has the same name as a file that exists in the destination folder, use a unique file name and update document table
                    {
                        destFileName = patOld.PatNum.ToString() + "_" + doc.FileName;                  //try to prepend patient's PatNum to the original file name
                        destFilePath = ODFileUtils.CombinePaths(atozTo, destFileName);
                        while (File.Exists(destFilePath))
                        {
                            //if still not unique, try appending date/time to seconds precision until the file name is unique
                            destFileName = patOld.PatNum.ToString() + "_" + Path.GetFileNameWithoutExtension(doc.FileName)
                                           + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(doc.FileName);
                            destFilePath = ODFileUtils.CombinePaths(atozTo, destFileName);
                        }
                    }
                    try {
                        File.Copy(fromFilePath, destFilePath);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        fileMoveFailures++;
                        continue;
                    }
                    //try to delete the original file
                    try {
                        File.Delete(fromFilePath);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        //If we cannot delete the file, could be a permission issue or someone has the file open currently
                        //Just skip deleting the file, which means there could be an image in the old pat's folder that may need to be deleted manually
                        fileMoveFailures++;
                    }
                }
                else if (CloudStorage.IsCloudStorage)
                {
                    //move files around in the cloud
                    FormProgress FormP = new FormProgress(false);
                    FormP.DisplayText          = "Uploading...";
                    FormP.NumberFormat         = "F";
                    FormP.NumberMultiplication = 1;
                    FormP.MaxVal = 100;                  //Doesn't matter what this value is as long as it is greater than 0
                    FormP.TickMS = 1000;
                    OpenDentalCloud.Core.TaskStateMove state = CloudStorage.MoveAsync(atozFrom
                                                                                      , atozTo
                                                                                      , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                    FormP.ShowDialog();                    //Don't allow users to cancel from here due to the limitations of the current feature for figuring out which files were moved successfully.
                }
                //if we get here the file was copied successfully or not storing images in the database, so update the document row
                //Safe to update the document FileName and PatNum to PatCur and new file name
                doc.PatNum   = PatCur.PatNum;
                doc.FileName = destFileName;
                Documents.Update(doc);
            }
            ListMedLabs.ForEach(x => x.PatNum = PatCur.PatNum); //update local list, done after moving files
            _medLabCur = ListMedLabs[0];
            if (fileMoveFailures > 0)                           //will never be > 0 if storing images in the db
            {
                MessageBox.Show(Lan.g(this, "Some files attached to the MedLab objects could not be moved.") + "\r\n"
                                + Lan.g(this, "This could be due to a missing file, a file being open, or a permission issue on the file which is preventing the move.") + "\r\n"
                                + Lan.g(this, "The file(s) will have to be moved manually from the Image module.") + "\r\n"
                                + Lan.g(this, "Number of files not moved") + ": " + fileMoveFailures.ToString());
            }
        }
Exemple #7
0
 ///<summary>Returns true if Update(MedLab,MedLab) 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(MedLab medLab, MedLab oldMedLab)
 {
     if (medLab.ProvNum != oldMedLab.ProvNum)
     {
         return(true);
     }
     if (medLab.SendingApp != oldMedLab.SendingApp)
     {
         return(true);
     }
     if (medLab.SendingFacility != oldMedLab.SendingFacility)
     {
         return(true);
     }
     if (medLab.PatNum != oldMedLab.PatNum)
     {
         return(true);
     }
     if (medLab.PatIDLab != oldMedLab.PatIDLab)
     {
         return(true);
     }
     if (medLab.PatIDAlt != oldMedLab.PatIDAlt)
     {
         return(true);
     }
     if (medLab.PatAge != oldMedLab.PatAge)
     {
         return(true);
     }
     if (medLab.PatAccountNum != oldMedLab.PatAccountNum)
     {
         return(true);
     }
     if (medLab.PatFasting != oldMedLab.PatFasting)
     {
         return(true);
     }
     if (medLab.SpecimenID != oldMedLab.SpecimenID)
     {
         return(true);
     }
     if (medLab.SpecimenIDFiller != oldMedLab.SpecimenIDFiller)
     {
         return(true);
     }
     if (medLab.ObsTestID != oldMedLab.ObsTestID)
     {
         return(true);
     }
     if (medLab.ObsTestDescript != oldMedLab.ObsTestDescript)
     {
         return(true);
     }
     if (medLab.ObsTestLoinc != oldMedLab.ObsTestLoinc)
     {
         return(true);
     }
     if (medLab.ObsTestLoincText != oldMedLab.ObsTestLoincText)
     {
         return(true);
     }
     if (medLab.DateTimeCollected != oldMedLab.DateTimeCollected)
     {
         return(true);
     }
     if (medLab.TotalVolume != oldMedLab.TotalVolume)
     {
         return(true);
     }
     if (medLab.ActionCode != oldMedLab.ActionCode)
     {
         return(true);
     }
     if (medLab.ClinicalInfo != oldMedLab.ClinicalInfo)
     {
         return(true);
     }
     if (medLab.DateTimeEntered != oldMedLab.DateTimeEntered)
     {
         return(true);
     }
     if (medLab.OrderingProvNPI != oldMedLab.OrderingProvNPI)
     {
         return(true);
     }
     if (medLab.OrderingProvLocalID != oldMedLab.OrderingProvLocalID)
     {
         return(true);
     }
     if (medLab.OrderingProvLName != oldMedLab.OrderingProvLName)
     {
         return(true);
     }
     if (medLab.OrderingProvFName != oldMedLab.OrderingProvFName)
     {
         return(true);
     }
     if (medLab.SpecimenIDAlt != oldMedLab.SpecimenIDAlt)
     {
         return(true);
     }
     if (medLab.DateTimeReported != oldMedLab.DateTimeReported)
     {
         return(true);
     }
     if (medLab.ResultStatus != oldMedLab.ResultStatus)
     {
         return(true);
     }
     if (medLab.ParentObsID != oldMedLab.ParentObsID)
     {
         return(true);
     }
     if (medLab.ParentObsTestID != oldMedLab.ParentObsTestID)
     {
         return(true);
     }
     if (medLab.NotePat != oldMedLab.NotePat)
     {
         return(true);
     }
     if (medLab.NoteLab != oldMedLab.NoteLab)
     {
         return(true);
     }
     if (medLab.FileName != oldMedLab.FileName)
     {
         return(true);
     }
     if (medLab.OriginalPIDSegment != oldMedLab.OriginalPIDSegment)
     {
         return(true);
     }
     return(false);
 }
Exemple #8
0
		///<summary>This will insert a new MedLab object and set _medLabCur.</summary>
		public static void ProcessMSH(HL7DefSegment segDef,SegmentHL7 mshSeg,MessageHL7 msg) {
			string firstObrClinicalInfo="";
			if(_medLabCur!=null) {
				//if _medLabCur already exists and we are about to start another ORC/OBR group, save the changes to _medLabCur before instantiating a new one
				MedLabs.Update(_medLabCur);
				firstObrClinicalInfo=_medLabCur.ClinicalInfo;//this is populated with processing the OBR segment of the first OBR in the message
			}
			_medLabCur=new MedLab();
			_medLabCur.FileName=_msgArchiveFileName;
			_medLabCur.ClinicalInfo=firstObrClinicalInfo;//the clinical information from the first OBR, will be on each report generated by this message
			for(int i=0;i<segDef.hl7DefFields.Count;i++) {
				HL7DefField fieldDefCur=segDef.hl7DefFields[i];
				switch(fieldDefCur.FieldName) {
					case "messageControlId":
						msg.ControlId=mshSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						continue;
					case "sendingApp":
						_medLabCur.SendingApp=mshSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						continue;
					case "sendingFacility":
						_medLabCur.SendingFacility=mshSeg.GetFieldComponent(fieldDefCur.OrdinalPos);
						continue;
					default:
						continue;
				}
			}
			_medLabCur.MedLabNum=MedLabs.Insert(_medLabCur);
			_medLabNumList.Add(_medLabCur.MedLabNum);
		}
Exemple #9
0
		///<summary>Updates one MedLab 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(MedLab medLab,MedLab oldMedLab){
			string command="";
			if(medLab.ProvNum != oldMedLab.ProvNum) {
				if(command!=""){ command+=",";}
				command+="ProvNum = "+POut.Long(medLab.ProvNum)+"";
			}
			if(medLab.SendingApp != oldMedLab.SendingApp) {
				if(command!=""){ command+=",";}
				command+="SendingApp = '"+POut.String(medLab.SendingApp)+"'";
			}
			if(medLab.SendingFacility != oldMedLab.SendingFacility) {
				if(command!=""){ command+=",";}
				command+="SendingFacility = '"+POut.String(medLab.SendingFacility)+"'";
			}
			if(medLab.PatNum != oldMedLab.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(medLab.PatNum)+"";
			}
			if(medLab.PatIDLab != oldMedLab.PatIDLab) {
				if(command!=""){ command+=",";}
				command+="PatIDLab = '"+POut.String(medLab.PatIDLab)+"'";
			}
			if(medLab.PatIDAlt != oldMedLab.PatIDAlt) {
				if(command!=""){ command+=",";}
				command+="PatIDAlt = '"+POut.String(medLab.PatIDAlt)+"'";
			}
			if(medLab.PatAge != oldMedLab.PatAge) {
				if(command!=""){ command+=",";}
				command+="PatAge = '"+POut.String(medLab.PatAge)+"'";
			}
			if(medLab.PatAccountNum != oldMedLab.PatAccountNum) {
				if(command!=""){ command+=",";}
				command+="PatAccountNum = '"+POut.String(medLab.PatAccountNum)+"'";
			}
			if(medLab.PatFasting != oldMedLab.PatFasting) {
				if(command!=""){ command+=",";}
				command+="PatFasting = "+POut.Int   ((int)medLab.PatFasting)+"";
			}
			if(medLab.SpecimenID != oldMedLab.SpecimenID) {
				if(command!=""){ command+=",";}
				command+="SpecimenID = '"+POut.String(medLab.SpecimenID)+"'";
			}
			if(medLab.SpecimenIDFiller != oldMedLab.SpecimenIDFiller) {
				if(command!=""){ command+=",";}
				command+="SpecimenIDFiller = '"+POut.String(medLab.SpecimenIDFiller)+"'";
			}
			if(medLab.ObsTestID != oldMedLab.ObsTestID) {
				if(command!=""){ command+=",";}
				command+="ObsTestID = '"+POut.String(medLab.ObsTestID)+"'";
			}
			if(medLab.ObsTestDescript != oldMedLab.ObsTestDescript) {
				if(command!=""){ command+=",";}
				command+="ObsTestDescript = '"+POut.String(medLab.ObsTestDescript)+"'";
			}
			if(medLab.ObsTestLoinc != oldMedLab.ObsTestLoinc) {
				if(command!=""){ command+=",";}
				command+="ObsTestLoinc = '"+POut.String(medLab.ObsTestLoinc)+"'";
			}
			if(medLab.ObsTestLoincText != oldMedLab.ObsTestLoincText) {
				if(command!=""){ command+=",";}
				command+="ObsTestLoincText = '"+POut.String(medLab.ObsTestLoincText)+"'";
			}
			if(medLab.DateTimeCollected != oldMedLab.DateTimeCollected) {
				if(command!=""){ command+=",";}
				command+="DateTimeCollected = "+POut.DateT(medLab.DateTimeCollected)+"";
			}
			if(medLab.TotalVolume != oldMedLab.TotalVolume) {
				if(command!=""){ command+=",";}
				command+="TotalVolume = '"+POut.String(medLab.TotalVolume)+"'";
			}
			if(medLab.ActionCode != oldMedLab.ActionCode) {
				if(command!=""){ command+=",";}
				command+="ActionCode = '"+POut.String(medLab.ActionCode.ToString())+"'";
			}
			if(medLab.ClinicalInfo != oldMedLab.ClinicalInfo) {
				if(command!=""){ command+=",";}
				command+="ClinicalInfo = '"+POut.String(medLab.ClinicalInfo)+"'";
			}
			if(medLab.DateTimeEntered != oldMedLab.DateTimeEntered) {
				if(command!=""){ command+=",";}
				command+="DateTimeEntered = "+POut.DateT(medLab.DateTimeEntered)+"";
			}
			if(medLab.OrderingProvNPI != oldMedLab.OrderingProvNPI) {
				if(command!=""){ command+=",";}
				command+="OrderingProvNPI = '"+POut.String(medLab.OrderingProvNPI)+"'";
			}
			if(medLab.OrderingProvLocalID != oldMedLab.OrderingProvLocalID) {
				if(command!=""){ command+=",";}
				command+="OrderingProvLocalID = '"+POut.String(medLab.OrderingProvLocalID)+"'";
			}
			if(medLab.OrderingProvLName != oldMedLab.OrderingProvLName) {
				if(command!=""){ command+=",";}
				command+="OrderingProvLName = '"+POut.String(medLab.OrderingProvLName)+"'";
			}
			if(medLab.OrderingProvFName != oldMedLab.OrderingProvFName) {
				if(command!=""){ command+=",";}
				command+="OrderingProvFName = '"+POut.String(medLab.OrderingProvFName)+"'";
			}
			if(medLab.SpecimenIDAlt != oldMedLab.SpecimenIDAlt) {
				if(command!=""){ command+=",";}
				command+="SpecimenIDAlt = '"+POut.String(medLab.SpecimenIDAlt)+"'";
			}
			if(medLab.DateTimeReported != oldMedLab.DateTimeReported) {
				if(command!=""){ command+=",";}
				command+="DateTimeReported = "+POut.DateT(medLab.DateTimeReported)+"";
			}
			if(medLab.ResultStatus != oldMedLab.ResultStatus) {
				if(command!=""){ command+=",";}
				command+="ResultStatus = '"+POut.String(medLab.ResultStatus.ToString())+"'";
			}
			if(medLab.ParentObsID != oldMedLab.ParentObsID) {
				if(command!=""){ command+=",";}
				command+="ParentObsID = '"+POut.String(medLab.ParentObsID)+"'";
			}
			if(medLab.ParentObsTestID != oldMedLab.ParentObsTestID) {
				if(command!=""){ command+=",";}
				command+="ParentObsTestID = '"+POut.String(medLab.ParentObsTestID)+"'";
			}
			if(medLab.NotePat != oldMedLab.NotePat) {
				if(command!=""){ command+=",";}
				command+="NotePat = "+DbHelper.ParamChar+"paramNotePat";
			}
			if(medLab.NoteLab != oldMedLab.NoteLab) {
				if(command!=""){ command+=",";}
				command+="NoteLab = "+DbHelper.ParamChar+"paramNoteLab";
			}
			if(medLab.FileName != oldMedLab.FileName) {
				if(command!=""){ command+=",";}
				command+="FileName = '"+POut.String(medLab.FileName)+"'";
			}
			if(medLab.OriginalPIDSegment != oldMedLab.OriginalPIDSegment) {
				if(command!=""){ command+=",";}
				command+="OriginalPIDSegment = '"+POut.String(medLab.OriginalPIDSegment)+"'";
			}
			if(command==""){
				return false;
			}
			if(medLab.NotePat==null) {
				medLab.NotePat="";
			}
			OdSqlParameter paramNotePat=new OdSqlParameter("paramNotePat",OdDbType.Text,medLab.NotePat);
			if(medLab.NoteLab==null) {
				medLab.NoteLab="";
			}
			OdSqlParameter paramNoteLab=new OdSqlParameter("paramNoteLab",OdDbType.Text,medLab.NoteLab);
			command="UPDATE medlab SET "+command
				+" WHERE MedLabNum = "+POut.Long(medLab.MedLabNum);
			Db.NonQ(command,paramNotePat,paramNoteLab);
			return true;
		}
Exemple #10
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<MedLab> TableToList(DataTable table){
			List<MedLab> retVal=new List<MedLab>();
			MedLab medLab;
			for(int i=0;i<table.Rows.Count;i++) {
				medLab=new MedLab();
				medLab.MedLabNum          = PIn.Long  (table.Rows[i]["MedLabNum"].ToString());
				medLab.ProvNum            = PIn.Long  (table.Rows[i]["ProvNum"].ToString());
				medLab.SendingApp         = PIn.String(table.Rows[i]["SendingApp"].ToString());
				medLab.SendingFacility    = PIn.String(table.Rows[i]["SendingFacility"].ToString());
				medLab.PatNum             = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				medLab.PatIDLab           = PIn.String(table.Rows[i]["PatIDLab"].ToString());
				medLab.PatIDAlt           = PIn.String(table.Rows[i]["PatIDAlt"].ToString());
				medLab.PatAge             = PIn.String(table.Rows[i]["PatAge"].ToString());
				medLab.PatAccountNum      = PIn.String(table.Rows[i]["PatAccountNum"].ToString());
				medLab.PatFasting         = (OpenDentBusiness.YN)PIn.Int(table.Rows[i]["PatFasting"].ToString());
				medLab.SpecimenID         = PIn.String(table.Rows[i]["SpecimenID"].ToString());
				medLab.SpecimenIDFiller   = PIn.String(table.Rows[i]["SpecimenIDFiller"].ToString());
				medLab.ObsTestID          = PIn.String(table.Rows[i]["ObsTestID"].ToString());
				medLab.ObsTestDescript    = PIn.String(table.Rows[i]["ObsTestDescript"].ToString());
				medLab.ObsTestLoinc       = PIn.String(table.Rows[i]["ObsTestLoinc"].ToString());
				medLab.ObsTestLoincText   = PIn.String(table.Rows[i]["ObsTestLoincText"].ToString());
				medLab.DateTimeCollected  = PIn.DateT (table.Rows[i]["DateTimeCollected"].ToString());
				medLab.TotalVolume        = PIn.String(table.Rows[i]["TotalVolume"].ToString());
				string actionCode=table.Rows[i]["ActionCode"].ToString();
				if(actionCode==""){
					medLab.ActionCode       =(ResultAction)0;
				}
				else try{
					medLab.ActionCode       =(ResultAction)Enum.Parse(typeof(ResultAction),actionCode);
				}
				catch{
					medLab.ActionCode       =(ResultAction)0;
				}
				medLab.ClinicalInfo       = PIn.String(table.Rows[i]["ClinicalInfo"].ToString());
				medLab.DateTimeEntered    = PIn.DateT (table.Rows[i]["DateTimeEntered"].ToString());
				medLab.OrderingProvNPI    = PIn.String(table.Rows[i]["OrderingProvNPI"].ToString());
				medLab.OrderingProvLocalID= PIn.String(table.Rows[i]["OrderingProvLocalID"].ToString());
				medLab.OrderingProvLName  = PIn.String(table.Rows[i]["OrderingProvLName"].ToString());
				medLab.OrderingProvFName  = PIn.String(table.Rows[i]["OrderingProvFName"].ToString());
				medLab.SpecimenIDAlt      = PIn.String(table.Rows[i]["SpecimenIDAlt"].ToString());
				medLab.DateTimeReported   = PIn.DateT (table.Rows[i]["DateTimeReported"].ToString());
				string resultStatus=table.Rows[i]["ResultStatus"].ToString();
				if(resultStatus==""){
					medLab.ResultStatus     =(ResultStatus)0;
				}
				else try{
					medLab.ResultStatus     =(ResultStatus)Enum.Parse(typeof(ResultStatus),resultStatus);
				}
				catch{
					medLab.ResultStatus     =(ResultStatus)0;
				}
				medLab.ParentObsID        = PIn.String(table.Rows[i]["ParentObsID"].ToString());
				medLab.ParentObsTestID    = PIn.String(table.Rows[i]["ParentObsTestID"].ToString());
				medLab.NotePat            = PIn.String(table.Rows[i]["NotePat"].ToString());
				medLab.NoteLab            = PIn.String(table.Rows[i]["NoteLab"].ToString());
				medLab.FileName           = PIn.String(table.Rows[i]["FileName"].ToString());
				medLab.OriginalPIDSegment = PIn.String(table.Rows[i]["OriginalPIDSegment"].ToString());
				retVal.Add(medLab);
			}
			return retVal;
		}
Exemple #11
0
		///<summary>Updates one MedLab in the database.</summary>
		public static void Update(MedLab medLab){
			string command="UPDATE medlab SET "
				+"ProvNum            =  "+POut.Long  (medLab.ProvNum)+", "
				+"SendingApp         = '"+POut.String(medLab.SendingApp)+"', "
				+"SendingFacility    = '"+POut.String(medLab.SendingFacility)+"', "
				+"PatNum             =  "+POut.Long  (medLab.PatNum)+", "
				+"PatIDLab           = '"+POut.String(medLab.PatIDLab)+"', "
				+"PatIDAlt           = '"+POut.String(medLab.PatIDAlt)+"', "
				+"PatAge             = '"+POut.String(medLab.PatAge)+"', "
				+"PatAccountNum      = '"+POut.String(medLab.PatAccountNum)+"', "
				+"PatFasting         =  "+POut.Int   ((int)medLab.PatFasting)+", "
				+"SpecimenID         = '"+POut.String(medLab.SpecimenID)+"', "
				+"SpecimenIDFiller   = '"+POut.String(medLab.SpecimenIDFiller)+"', "
				+"ObsTestID          = '"+POut.String(medLab.ObsTestID)+"', "
				+"ObsTestDescript    = '"+POut.String(medLab.ObsTestDescript)+"', "
				+"ObsTestLoinc       = '"+POut.String(medLab.ObsTestLoinc)+"', "
				+"ObsTestLoincText   = '"+POut.String(medLab.ObsTestLoincText)+"', "
				+"DateTimeCollected  =  "+POut.DateT (medLab.DateTimeCollected)+", "
				+"TotalVolume        = '"+POut.String(medLab.TotalVolume)+"', "
				+"ActionCode         = '"+POut.String(medLab.ActionCode.ToString())+"', "
				+"ClinicalInfo       = '"+POut.String(medLab.ClinicalInfo)+"', "
				+"DateTimeEntered    =  "+POut.DateT (medLab.DateTimeEntered)+", "
				+"OrderingProvNPI    = '"+POut.String(medLab.OrderingProvNPI)+"', "
				+"OrderingProvLocalID= '"+POut.String(medLab.OrderingProvLocalID)+"', "
				+"OrderingProvLName  = '"+POut.String(medLab.OrderingProvLName)+"', "
				+"OrderingProvFName  = '"+POut.String(medLab.OrderingProvFName)+"', "
				+"SpecimenIDAlt      = '"+POut.String(medLab.SpecimenIDAlt)+"', "
				+"DateTimeReported   =  "+POut.DateT (medLab.DateTimeReported)+", "
				+"ResultStatus       = '"+POut.String(medLab.ResultStatus.ToString())+"', "
				+"ParentObsID        = '"+POut.String(medLab.ParentObsID)+"', "
				+"ParentObsTestID    = '"+POut.String(medLab.ParentObsTestID)+"', "
				+"NotePat            =  "+DbHelper.ParamChar+"paramNotePat, "
				+"NoteLab            =  "+DbHelper.ParamChar+"paramNoteLab, "
				+"FileName           = '"+POut.String(medLab.FileName)+"', "
				+"OriginalPIDSegment = '"+POut.String(medLab.OriginalPIDSegment)+"' "
				+"WHERE MedLabNum = "+POut.Long(medLab.MedLabNum);
			if(medLab.NotePat==null) {
				medLab.NotePat="";
			}
			OdSqlParameter paramNotePat=new OdSqlParameter("paramNotePat",OdDbType.Text,medLab.NotePat);
			if(medLab.NoteLab==null) {
				medLab.NoteLab="";
			}
			OdSqlParameter paramNoteLab=new OdSqlParameter("paramNoteLab",OdDbType.Text,medLab.NoteLab);
			Db.NonQ(command,paramNotePat,paramNoteLab);
		}
Exemple #12
0
		///<summary>Inserts one MedLab into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(MedLab medLab,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				medLab.MedLabNum=ReplicationServers.GetKey("medlab","MedLabNum");
			}
			string command="INSERT INTO medlab (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="MedLabNum,";
			}
			command+="ProvNum,SendingApp,SendingFacility,PatNum,PatIDLab,PatIDAlt,PatAge,PatAccountNum,PatFasting,SpecimenID,SpecimenIDFiller,ObsTestID,ObsTestDescript,ObsTestLoinc,ObsTestLoincText,DateTimeCollected,TotalVolume,ActionCode,ClinicalInfo,DateTimeEntered,OrderingProvNPI,OrderingProvLocalID,OrderingProvLName,OrderingProvFName,SpecimenIDAlt,DateTimeReported,ResultStatus,ParentObsID,ParentObsTestID,NotePat,NoteLab,FileName,OriginalPIDSegment) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(medLab.MedLabNum)+",";
			}
			command+=
				     POut.Long  (medLab.ProvNum)+","
				+"'"+POut.String(medLab.SendingApp)+"',"
				+"'"+POut.String(medLab.SendingFacility)+"',"
				+    POut.Long  (medLab.PatNum)+","
				+"'"+POut.String(medLab.PatIDLab)+"',"
				+"'"+POut.String(medLab.PatIDAlt)+"',"
				+"'"+POut.String(medLab.PatAge)+"',"
				+"'"+POut.String(medLab.PatAccountNum)+"',"
				+    POut.Int   ((int)medLab.PatFasting)+","
				+"'"+POut.String(medLab.SpecimenID)+"',"
				+"'"+POut.String(medLab.SpecimenIDFiller)+"',"
				+"'"+POut.String(medLab.ObsTestID)+"',"
				+"'"+POut.String(medLab.ObsTestDescript)+"',"
				+"'"+POut.String(medLab.ObsTestLoinc)+"',"
				+"'"+POut.String(medLab.ObsTestLoincText)+"',"
				+    POut.DateT (medLab.DateTimeCollected)+","
				+"'"+POut.String(medLab.TotalVolume)+"',"
				+"'"+POut.String(medLab.ActionCode.ToString())+"',"
				+"'"+POut.String(medLab.ClinicalInfo)+"',"
				+    POut.DateT (medLab.DateTimeEntered)+","
				+"'"+POut.String(medLab.OrderingProvNPI)+"',"
				+"'"+POut.String(medLab.OrderingProvLocalID)+"',"
				+"'"+POut.String(medLab.OrderingProvLName)+"',"
				+"'"+POut.String(medLab.OrderingProvFName)+"',"
				+"'"+POut.String(medLab.SpecimenIDAlt)+"',"
				+    POut.DateT (medLab.DateTimeReported)+","
				+"'"+POut.String(medLab.ResultStatus.ToString())+"',"
				+"'"+POut.String(medLab.ParentObsID)+"',"
				+"'"+POut.String(medLab.ParentObsTestID)+"',"
				+    DbHelper.ParamChar+"paramNotePat,"
				+    DbHelper.ParamChar+"paramNoteLab,"
				+"'"+POut.String(medLab.FileName)+"',"
				+"'"+POut.String(medLab.OriginalPIDSegment)+"')";
			if(medLab.NotePat==null) {
				medLab.NotePat="";
			}
			OdSqlParameter paramNotePat=new OdSqlParameter("paramNotePat",OdDbType.Text,medLab.NotePat);
			if(medLab.NoteLab==null) {
				medLab.NoteLab="";
			}
			OdSqlParameter paramNoteLab=new OdSqlParameter("paramNoteLab",OdDbType.Text,medLab.NoteLab);
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command,paramNotePat,paramNoteLab);
			}
			else {
				medLab.MedLabNum=Db.NonQ(command,true,paramNotePat,paramNoteLab);
			}
			return medLab.MedLabNum;
		}
Exemple #13
0
		///<summary>Inserts one MedLab into the database.  Returns the new priKey.</summary>
		public static long Insert(MedLab medLab){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				medLab.MedLabNum=DbHelper.GetNextOracleKey("medlab","MedLabNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(medLab,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							medLab.MedLabNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(medLab,false);
			}
		}
Exemple #14
0
        ///<summary>Updates one MedLab 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(MedLab medLab, MedLab oldMedLab)
        {
            string command = "";

            if (medLab.ProvNum != oldMedLab.ProvNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProvNum = " + POut.Long(medLab.ProvNum) + "";
            }
            if (medLab.SendingApp != oldMedLab.SendingApp)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SendingApp = '" + POut.String(medLab.SendingApp) + "'";
            }
            if (medLab.SendingFacility != oldMedLab.SendingFacility)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SendingFacility = '" + POut.String(medLab.SendingFacility) + "'";
            }
            if (medLab.PatNum != oldMedLab.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(medLab.PatNum) + "";
            }
            if (medLab.PatIDLab != oldMedLab.PatIDLab)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatIDLab = '" + POut.String(medLab.PatIDLab) + "'";
            }
            if (medLab.PatIDAlt != oldMedLab.PatIDAlt)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatIDAlt = '" + POut.String(medLab.PatIDAlt) + "'";
            }
            if (medLab.PatAge != oldMedLab.PatAge)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatAge = '" + POut.String(medLab.PatAge) + "'";
            }
            if (medLab.PatAccountNum != oldMedLab.PatAccountNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatAccountNum = '" + POut.String(medLab.PatAccountNum) + "'";
            }
            if (medLab.PatFasting != oldMedLab.PatFasting)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatFasting = " + POut.Int((int)medLab.PatFasting) + "";
            }
            if (medLab.SpecimenID != oldMedLab.SpecimenID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SpecimenID = '" + POut.String(medLab.SpecimenID) + "'";
            }
            if (medLab.SpecimenIDFiller != oldMedLab.SpecimenIDFiller)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SpecimenIDFiller = '" + POut.String(medLab.SpecimenIDFiller) + "'";
            }
            if (medLab.ObsTestID != oldMedLab.ObsTestID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsTestID = '" + POut.String(medLab.ObsTestID) + "'";
            }
            if (medLab.ObsTestDescript != oldMedLab.ObsTestDescript)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsTestDescript = '" + POut.String(medLab.ObsTestDescript) + "'";
            }
            if (medLab.ObsTestLoinc != oldMedLab.ObsTestLoinc)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsTestLoinc = '" + POut.String(medLab.ObsTestLoinc) + "'";
            }
            if (medLab.ObsTestLoincText != oldMedLab.ObsTestLoincText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ObsTestLoincText = '" + POut.String(medLab.ObsTestLoincText) + "'";
            }
            if (medLab.DateTimeCollected != oldMedLab.DateTimeCollected)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeCollected = " + POut.DateT(medLab.DateTimeCollected) + "";
            }
            if (medLab.TotalVolume != oldMedLab.TotalVolume)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "TotalVolume = '" + POut.String(medLab.TotalVolume) + "'";
            }
            if (medLab.ActionCode != oldMedLab.ActionCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ActionCode = '" + POut.String(medLab.ActionCode.ToString()) + "'";
            }
            if (medLab.ClinicalInfo != oldMedLab.ClinicalInfo)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClinicalInfo = '" + POut.String(medLab.ClinicalInfo) + "'";
            }
            if (medLab.DateTimeEntered != oldMedLab.DateTimeEntered)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeEntered = " + POut.DateT(medLab.DateTimeEntered) + "";
            }
            if (medLab.OrderingProvNPI != oldMedLab.OrderingProvNPI)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OrderingProvNPI = '" + POut.String(medLab.OrderingProvNPI) + "'";
            }
            if (medLab.OrderingProvLocalID != oldMedLab.OrderingProvLocalID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OrderingProvLocalID = '" + POut.String(medLab.OrderingProvLocalID) + "'";
            }
            if (medLab.OrderingProvLName != oldMedLab.OrderingProvLName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OrderingProvLName = '" + POut.String(medLab.OrderingProvLName) + "'";
            }
            if (medLab.OrderingProvFName != oldMedLab.OrderingProvFName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OrderingProvFName = '" + POut.String(medLab.OrderingProvFName) + "'";
            }
            if (medLab.SpecimenIDAlt != oldMedLab.SpecimenIDAlt)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SpecimenIDAlt = '" + POut.String(medLab.SpecimenIDAlt) + "'";
            }
            if (medLab.DateTimeReported != oldMedLab.DateTimeReported)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeReported = " + POut.DateT(medLab.DateTimeReported) + "";
            }
            if (medLab.ResultStatus != oldMedLab.ResultStatus)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ResultStatus = '" + POut.String(medLab.ResultStatus.ToString()) + "'";
            }
            if (medLab.ParentObsID != oldMedLab.ParentObsID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ParentObsID = '" + POut.String(medLab.ParentObsID) + "'";
            }
            if (medLab.ParentObsTestID != oldMedLab.ParentObsTestID)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ParentObsTestID = '" + POut.String(medLab.ParentObsTestID) + "'";
            }
            if (medLab.NotePat != oldMedLab.NotePat)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "NotePat = " + DbHelper.ParamChar + "paramNotePat";
            }
            if (medLab.NoteLab != oldMedLab.NoteLab)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "NoteLab = " + DbHelper.ParamChar + "paramNoteLab";
            }
            if (medLab.FileName != oldMedLab.FileName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FileName = '" + POut.String(medLab.FileName) + "'";
            }
            if (medLab.OriginalPIDSegment != oldMedLab.OriginalPIDSegment)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OriginalPIDSegment = " + DbHelper.ParamChar + "paramOriginalPIDSegment";
            }
            if (command == "")
            {
                return(false);
            }
            if (medLab.NotePat == null)
            {
                medLab.NotePat = "";
            }
            OdSqlParameter paramNotePat = new OdSqlParameter("paramNotePat", OdDbType.Text, POut.StringParam(medLab.NotePat));

            if (medLab.NoteLab == null)
            {
                medLab.NoteLab = "";
            }
            OdSqlParameter paramNoteLab = new OdSqlParameter("paramNoteLab", OdDbType.Text, POut.StringParam(medLab.NoteLab));

            if (medLab.OriginalPIDSegment == null)
            {
                medLab.OriginalPIDSegment = "";
            }
            OdSqlParameter paramOriginalPIDSegment = new OdSqlParameter("paramOriginalPIDSegment", OdDbType.Text, POut.StringParam(medLab.OriginalPIDSegment));

            command = "UPDATE medlab SET " + command
                      + " WHERE MedLabNum = " + POut.Long(medLab.MedLabNum);
            Db.NonQ(command, paramNotePat, paramNoteLab, paramOriginalPIDSegment);
            return(true);
        }
Exemple #15
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);
        }
Exemple #16
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <MedLab> TableToList(DataTable table)
        {
            List <MedLab> retVal = new List <MedLab>();
            MedLab        medLab;

            foreach (DataRow row in table.Rows)
            {
                medLab                   = new MedLab();
                medLab.MedLabNum         = PIn.Long(row["MedLabNum"].ToString());
                medLab.ProvNum           = PIn.Long(row["ProvNum"].ToString());
                medLab.SendingApp        = PIn.String(row["SendingApp"].ToString());
                medLab.SendingFacility   = PIn.String(row["SendingFacility"].ToString());
                medLab.PatNum            = PIn.Long(row["PatNum"].ToString());
                medLab.PatIDLab          = PIn.String(row["PatIDLab"].ToString());
                medLab.PatIDAlt          = PIn.String(row["PatIDAlt"].ToString());
                medLab.PatAge            = PIn.String(row["PatAge"].ToString());
                medLab.PatAccountNum     = PIn.String(row["PatAccountNum"].ToString());
                medLab.PatFasting        = (OpenDentBusiness.YN)PIn.Int(row["PatFasting"].ToString());
                medLab.SpecimenID        = PIn.String(row["SpecimenID"].ToString());
                medLab.SpecimenIDFiller  = PIn.String(row["SpecimenIDFiller"].ToString());
                medLab.ObsTestID         = PIn.String(row["ObsTestID"].ToString());
                medLab.ObsTestDescript   = PIn.String(row["ObsTestDescript"].ToString());
                medLab.ObsTestLoinc      = PIn.String(row["ObsTestLoinc"].ToString());
                medLab.ObsTestLoincText  = PIn.String(row["ObsTestLoincText"].ToString());
                medLab.DateTimeCollected = PIn.DateT(row["DateTimeCollected"].ToString());
                medLab.TotalVolume       = PIn.String(row["TotalVolume"].ToString());
                string actionCode = row["ActionCode"].ToString();
                if (actionCode == "")
                {
                    medLab.ActionCode = (OpenDentBusiness.ResultAction) 0;
                }
                else
                {
                    try{
                        medLab.ActionCode = (OpenDentBusiness.ResultAction)Enum.Parse(typeof(OpenDentBusiness.ResultAction), actionCode);
                    }
                    catch {
                        medLab.ActionCode = (OpenDentBusiness.ResultAction) 0;
                    }
                }
                medLab.ClinicalInfo        = PIn.String(row["ClinicalInfo"].ToString());
                medLab.DateTimeEntered     = PIn.DateT(row["DateTimeEntered"].ToString());
                medLab.OrderingProvNPI     = PIn.String(row["OrderingProvNPI"].ToString());
                medLab.OrderingProvLocalID = PIn.String(row["OrderingProvLocalID"].ToString());
                medLab.OrderingProvLName   = PIn.String(row["OrderingProvLName"].ToString());
                medLab.OrderingProvFName   = PIn.String(row["OrderingProvFName"].ToString());
                medLab.SpecimenIDAlt       = PIn.String(row["SpecimenIDAlt"].ToString());
                medLab.DateTimeReported    = PIn.DateT(row["DateTimeReported"].ToString());
                string resultStatus = row["ResultStatus"].ToString();
                if (resultStatus == "")
                {
                    medLab.ResultStatus = (OpenDentBusiness.ResultStatus) 0;
                }
                else
                {
                    try{
                        medLab.ResultStatus = (OpenDentBusiness.ResultStatus)Enum.Parse(typeof(OpenDentBusiness.ResultStatus), resultStatus);
                    }
                    catch {
                        medLab.ResultStatus = (OpenDentBusiness.ResultStatus) 0;
                    }
                }
                medLab.ParentObsID        = PIn.String(row["ParentObsID"].ToString());
                medLab.ParentObsTestID    = PIn.String(row["ParentObsTestID"].ToString());
                medLab.NotePat            = PIn.String(row["NotePat"].ToString());
                medLab.NoteLab            = PIn.String(row["NoteLab"].ToString());
                medLab.FileName           = PIn.String(row["FileName"].ToString());
                medLab.OriginalPIDSegment = PIn.String(row["OriginalPIDSegment"].ToString());
                retVal.Add(medLab);
            }
            return(retVal);
        }
Exemple #17
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;
		}