private void FlowsheetItemSelector_Load(object sender, EventArgs e) { try { var query = new ImpacRdbQuery(typeof(ObsDef)); query.AddClause(ObsDefDataRow.TypeEntityColumn, EntityQueryOp.EQ, (int)MedDefs.ObdType.ViewFilter); query.AddClause(ObsDefDataRow.ActiveEntityColumn, EntityQueryOp.EQ, true); query.AddOrderBy(ObsDefDataRow.LabelEntityColumn); _tabNames = _pm.GetEntities <ObsDef>(query); InitDropDown(lookUpEditFlowsheetTab, _tabNames, Value.TabGuid); LoadTabViews(); InitDropDown(lookUpEditFlowsheetViews, _tabViews, Value.ItemGuids != null ? Value.ViewGuid : Guid.Empty); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("FlowsheetItemSelector: " + ex); } if (Value.ItemGuids == null) { return; } // disable the logic in treeTabViewItems_AfterCheck in this case, because // we will set the Checked flag on each node individually _initializingItemState = true; int pos = 0; SetCheckedItems(treeTabViewItems.Nodes, Value.ItemGuids, ref pos); _initializingItemState = false; }
/// <summary> /// Remove fraction-specific notes that will be orphaned when the excess fractions are removed /// (The same Notes record can be referenced from the same fraction# SiteFractionDetails /// record in more than one version of a Site.) /// </summary> /// <param name="pm"></param> /// <param name="sfdsToRemove"></param> /// <param name="revisionedSite"></param> private static void RemoveFxNotesThatWillBeOrphaned(ImpacPersistenceManager pm, IEnumerable <SiteFractionDetails> sfdsToRemove, PrescriptionSite revisionedSite) { // Normal usage is for Plan-of-the-Day i.e., a single Site_FractionDetails record will be removed // and if there is a fraction-specific note for that Site_FractionDetails recore then it will be removed. // Usage of fraction-specific notes in general is probably uncommon. // Usage with Plan-of-the-Day should be even less common given that the feature removes fractions. // Considering the above, performance tuning of the functionality below offers little if any benefit. List <int?> fxNoteIdsInsfdsToRemove = sfdsToRemove.Where(d => d.FxNote_ID != null).Select(d => d.FxNote_ID).ToList(); // Notes records are not in the cache (yet) if (fxNoteIdsInsfdsToRemove.Count > 0) { // Determine whether any of the fx Notes records will be orphaned when the fraction details record is removed // Get the SIT_IDs for the historic versions of the Site var historicSitesInSetQuery = new ImpacRdbQuery(typeof(PrescriptionSite)); historicSitesInSetQuery.AddClause(PrescriptionSite.SIT_SET_IDEntityColumn, EntityQueryOp.EQ, revisionedSite.SIT_SET_ID); historicSitesInSetQuery.AddClause(PrescriptionSite.VersionEntityColumn, EntityQueryOp.GT, 0); var historicSites = pm.GetEntities <PrescriptionSite>(historicSitesInSetQuery); var historicSIT_IDs = historicSites.Select(s => s.SIT_ID).ToList(); // Get the FxNote_IDs in the fraction details for the historic versions of the Site var historicSFDsQuery = new ImpacRdbQuery(typeof(SiteFractionDetails)); historicSFDsQuery.AddClause(SiteFractionDetails.SIT_IDEntityColumn, EntityQueryOp.In, historicSIT_IDs); var historicSFDs = pm.GetEntities <SiteFractionDetails>(historicSFDsQuery); List <int?> historicSFDFx_NoteIDs = historicSFDs.Where(n => n.FxNote_ID != null).Select(n => n.FxNote_ID).ToList(); for (int i = 0; i < fxNoteIdsInsfdsToRemove.Count; i++) { int fxNoteId = fxNoteIdsInsfdsToRemove[i].GetValueOrDefault(); // Until we find evidence otherwise this fxNoteId will be orphaned bool isGoingToBeOrphaned = true; if (historicSFDFx_NoteIDs.Count > 0) { // If this fxNoteId is an fx note for an historic version of the Site then it will NOT be orphaned if (historicSFDFx_NoteIDs.Exists(h => h == fxNoteId)) { isGoingToBeOrphaned = false; } } if (isGoingToBeOrphaned) { // Either there are no fx notes for historic versions of the Site // or there are but this fxNoteId isn't an fx note for any of them Notes note = Notes.GetEntityByID(fxNoteId, pm); note.Delete(); } } } }
/// <summary> Performs the query requested. </summary> /// <param name="context"></param> protected override void DoWork(CodeActivityContext context) { //Get argument values. ImpacPersistenceManager pm = PersistenceManager.Expression != null ? PersistenceManager.Get(context) : PM; QueryStrategy strategy = Strategy.Get(context) ?? QueryStrategy.Normal; string sqlQuery = Query.Get(context); //Defect-11131:Medication field in eScribe get error when the PC Regional Settings are changed to DD/MM/YY--Check the MAX date format, if exist possible issue format, change the format to standard format. if ((sqlQuery.IndexOf(DateTime.MaxValue.ToString("dd/MM/yyyy")) > 0) || (sqlQuery.IndexOf(DateTime.MaxValue.ToString("MM/dd/yyyy")) > 0)) { if (sqlQuery.IndexOf(DateTime.MaxValue.ToString("dd/MM/yyyy")) > 0) { sqlQuery = sqlQuery.Replace(DateTime.MaxValue.ToString("dd/MM/yyyy"), DateTime.MaxValue.ToString("yyyy/MM/dd")); } if (sqlQuery.IndexOf(DateTime.MaxValue.ToString("MM/dd/yyyy")) > 0) { sqlQuery = sqlQuery.Replace(DateTime.MaxValue.ToString("MM/dd/yyyy"), DateTime.MaxValue.ToString("yyyy/MM/dd")); } } //Create and execute the query var passthroughQuery = new PassthruRdbQuery(typeof(T), sqlQuery); EntityList <T> entities = pm.GetEntities <T>(passthroughQuery, strategy); //Assign the result set. Result.Set(context, entities); }
/// <summary> /// Overriden method for looking up details by ID (since we're not using the primary key of obsdef) /// </summary> /// <param name="ids"></param> /// <param name="pm"></param> /// <returns></returns> protected override IDictionary <Guid, ObsDef> GetEntitiesDictFromIds(IEnumerable <Guid> ids, ImpacPersistenceManager pm) { var query = new ImpacRdbQuery(typeof(ObsDef)); query.AddClause(ObsDefDataRow.OBD_GUIDEntityColumn, EntityQueryOp.In, ids.ToList()); return(pm.GetEntities <ObsDef>(query, QueryStrategy.Normal).ToDictionary(e => e.OBD_GUID, e => e)); }
private void CdsReferenceSelector_Load(object sender, EventArgs e) { try { var query = new ImpacRdbQuery(typeof(CDSReference)); query.AddClause(CDSReferenceDataRow.InactiveEntityColumn, EntityQueryOp.EQ, false); query.AddOrderBy(CDSReferenceDataRow.TitleEntityColumn); EntityList <CDSReference> list = _pm.GetEntities <CDSReference>(query); bsCdsReference.DataSource = list; gridCdsReference.ForceInitialize(); for (int i = 0; i < gridViewCdsReference.RowCount; i++) { int index = gridViewCdsReference.GetDataSourceRowIndex(i); var cdsRef = (CDSReference)bsCdsReference[index]; if (cdsRef != null && cdsRef.CDSR_ID == Value) { gridViewCdsReference.FocusedRowHandle = i; break; } } } catch (Exception) { bsCdsReference.Clear(); } }
/// <summary> /// Overriden method for looking up details by ID (since we're not using the primary key of Prompt) /// </summary> protected override IDictionary <int, Prompt> GetEntitiesDictFromIds(IEnumerable <int> ids, ImpacPersistenceManager pm) { var query = new ImpacRdbQuery(typeof(Prompt)); query.AddClause(PromptDataRow.PGroupEntityColumn, EntityQueryOp.EQ, "ESC7"); query.AddClause(PromptDataRow.EnumEntityColumn, EntityQueryOp.In, ids.ToList()); return(pm.GetEntities <Prompt>(query, QueryStrategy.Normal).ToDictionary(e => (int)e.Enum, e => e)); }
/// <summary> /// Activity heavy lifting. /// </summary> /// <param name="context"></param> protected override void DoWork(CodeActivityContext context) { // Activity inputs int patId = PatId.Get(context); int pciId = PciId.Get(context); ImpacPersistenceManager pm = PersistenceManager.Expression != null ? PersistenceManager.Get(context) : PM; // Activity output FieldsDeleted.Set(context, 0); // Initialize the Activity output to 0 // Get the available session fields for given PCI_ID var query = new ImpacRdbQuery(typeof(PatTxCal)); query.AddClause(PatTxCal.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId); query.AddClause(PatTxCal.PCI_IDEntityColumn, EntityQueryOp.EQ, pciId); var sessionItems = pm.GetEntities <PatTxCal>(query); // Delete fields in the given session int fieldsDeleted = 0; try { // Store PatCItem record PatCItem patCItem = null; byte patCItemStatus = 0; if (sessionItems.Count > 0) { // The Delete() member of PatTxField sets PatCItem.Status to "Pending" if the Status is "Approved" // Save state of PatCItem record patCItem = sessionItems[0].PatCItemEntity; patCItemStatus = patCItem.Status_Enum; } while (sessionItems.Count > 0) { sessionItems[sessionItems.Count - 1].Delete(); pm.SaveChanges(); fieldsDeleted++; } if (patCItem != null) { patCItem.Status_Enum = patCItemStatus; pm.SaveChanges(); } } catch { fieldsDeleted = -1; } finally { // Update Activity output FieldsDeleted.Set(context, fieldsDeleted); } }
/// <summary> /// Overriden method for looking up details by ID (since we're not using the primary key of obsdef) /// </summary> /// <param name="ids"></param> /// <param name="pm"></param> /// <returns></returns> protected override IDictionary <int, CPlan> GetEntitiesDictFromIds(IEnumerable <int> ids, ImpacPersistenceManager pm) { var query = new ImpacRdbQuery(typeof(CPlan)); //Defect 12161, Change logic to use CPL_SET_ID rather than CPL_ID to trigger IQ query.AddClause(CPlanDataRow.CPL_Set_IDEntityColumn, EntityQueryOp.In, ids.ToList()); query.AddClause(CPlanDataRow.VersionEntityColumn, EntityQueryOp.EQ, 0); return(pm.GetEntities <CPlan>(query, QueryStrategy.Normal).ToDictionary(e => (int)e.CPL_Set_ID, e => e)); }
private void NoteTypeSelector_Load(object sender, EventArgs e) { try { ImpacPersistenceManager pm = ImpacPersistenceManagerFactory.CreatePersistenceManager(); var query = new ImpacRdbQuery(typeof(Prompt)); query.AddClause(PromptDataRow.PGroupEntityColumn, EntityQueryOp.EQ, "#NT1"); var noteTypes = pm.GetEntities <Prompt>(query).Select(ent => new NoteType { Text = ent.Text, Enum = ent.Enum }).ToList(); foreach (var noteType in noteTypes) { noteType.Text = IQNoteTypeVarConfig.FixNoteTypeName(noteType.Enum, noteType.Text); } // sort the notes types by name noteTypes.Sort((n1, n2) => n1.Text.CompareTo(n2.Text)); listNoteTypes.DisplayMember = "Text"; listNoteTypes.ValueMember = "Enum"; listNoteTypes.DataSource = noteTypes; listNoteTypes.SelectionMode = IsMultiSelect ? SelectionMode.MultiSimple : SelectionMode.One; if (!IsMultiSelect) { checkAll.Enabled = false; } listNoteTypes.SelectedIndex = -1; // Select the current value if there is one and if the mode is single-select if (!IsMultiSelect && Value != null && Value.Count > 0) { for (int i = 0; i < listNoteTypes.ItemCount; i++) { var item = (NoteType)listNoteTypes.GetItem(i); if (item == null) { continue; } if (item.Enum != Value[0]) { continue; } listNoteTypes.SelectedIndex = i; break; } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("NoteTypeSelector: " + ex); } }
/// <summary> /// Handles form Loading /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void IntentPromptSelectorForm_Load(object sender, EventArgs e) { if (!DesignMode) { //pm = ImpacPersistenceManagerFactory.CreatePersistenceManager(); var query = new ImpacRdbQuery(typeof(Prompt)); query.AddClause(PromptDataRow.PGroupEntityColumn, EntityQueryOp.EQ, "MEDA"); query.AddOrderBy(PromptDataRow.TextEntityColumn, ListSortDirection.Ascending); _promptValues = _pm.GetEntities <Prompt>(query); bsPropmt.DataSource = _promptValues; } }
private void GetStaffTypes() { var query = new ImpacRdbQuery(typeof(Prompt)); query.AddClause(PromptDataRow.PGroupEntityColumn, EntityQueryOp.EQ, "STF0"); query.AddClause(PromptDataRow.TextEntityColumn, EntityQueryOp.NE, "Location"); var staffTypes = _pm.GetEntities <Prompt>(query); foreach (var staffType in staffTypes) { var item = new KeyLabelInfo { Key = staffType.Pro_ID, Label = staffType.Text }; _items.Add(item); } }
private void FlowsheetTabSelector_Load(object sender, EventArgs e) { try { var query = new ImpacRdbQuery(typeof(ObsDef)); query.AddClause(ObsDefDataRow.TypeEntityColumn, EntityQueryOp.EQ, (int)MedDefs.ObdType.ViewFilter); _tabNames = _pm.GetEntities <ObsDef>(query); listTabNames.DisplayMember = "Label"; listTabNames.ValueMember = "OBD_GUID"; listTabNames.DataSource = _tabNames; // Select the current value if there is one and if the mode is sinlge-select if (TabGuid == Guid.Empty) { return; } for (int i = 0; i < listTabNames.ItemCount; i++) { var item = (ObsDef)listTabNames.GetItem(i); if (item == null) { continue; } if (item.OBD_GUID != TabGuid) { continue; } listTabNames.SelectedIndex = i; break; } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("FlowsheetTabSelector: " + ex); } }
/// <summary> /// Activity heavy lifting. /// </summary> /// <param name="context"></param> protected override void DoWork(CodeActivityContext context) { // Activity inputs int patId = PatId.Get(context); int sitId = SitId.Get(context); int pciId = PciId.Get(context); int statusEnum = StatusEnum.Expression != null?StatusEnum.Get(context) : 5; if ((statusEnum != 5) && (statusEnum != 7)) { statusEnum = 7; } bool useAfs = UseAfs.Expression != null?UseAfs.Get(context) : false; bool useMfs = UseMfs.Expression != null?UseMfs.Get(context) : false; ImpacPersistenceManager pm = PersistenceManager.Expression != null ? PersistenceManager.Get(context) : PM; // Activity output FieldsInserted.Set(context, -1); // Initialize the Activity output to -1 (indication of error) // Do not continue if both AFS and MFS are set to true (there is no way to resolve this at run time) if (useAfs && useMfs) { return; } // Get the Sit_Set_Id of the Site (Sit_Id) given var query = new ImpacRdbQuery(typeof(PrescriptionSite)); query.AddClause(PrescriptionSiteDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId); query.AddClause(PrescriptionSiteDataRow.SIT_IDEntityColumn, EntityQueryOp.EQ, sitId); var site = pm.GetEntities <PrescriptionSite>(query); if (site.Count != 1) { return; } int sitSetId = (int)site[0].SIT_SET_ID.GetValueOrDefault(0); // Get the list of treatment fields from the given Rad Rx to insert query = new ImpacRdbQuery(typeof(Field)); query.AddClause(FieldDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId); query.AddClause(FieldDataRow.SIT_Set_IDEntityColumn, EntityQueryOp.EQ, sitSetId); query.AddClause(FieldDataRow.VersionEntityColumn, EntityQueryOp.EQ, 0); query.AddOrderBy(FieldDataRow.DisplaySequenceEntityColumn); var txField = pm.GetEntities <Field>(query); if (txField.Count == 0) { return; } // Make sure we have a (1) session to insert the fields in to query = new ImpacRdbQuery(typeof(PatCItem)); query.AddClause(PatCItemDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId); query.AddClause(PatCItemDataRow.PCI_IDEntityColumn, EntityQueryOp.EQ, pciId); var calendarSession = pm.GetEntities <PatCItem>(query); if (calendarSession.Count != 1) { return; } // Add new entry to PatTxCal for each treatment field int fieldsInserted = 0; try { for (int f = 0; f < txField.Count; f++) { PatTxCal sessionItem = PatTxCal.Create(pm); sessionItem.PCI_ID = calendarSession[0].PCI_ID; sessionItem.Status_enum = (byte)statusEnum; sessionItem.Pat_ID1 = patId; sessionItem.FLD_Set_ID = txField[f].FLD_SET_ID; sessionItem.TxSequence = (short)(f + 1); sessionItem.ProFormaPF = 0; if (useAfs) { if (f == 0) { sessionItem.AFS_Begin = true; } else { sessionItem.AFS = true; } } if (useMfs) { if (f == 0) { sessionItem.MFS_Begin = true; } else { sessionItem.MFS = true; } } sessionItem.PF_Only = txField[f].Type_Enum == 3 || txField[f].Type_Enum == 4 || txField[f].Type_Enum == 5 || txField[f].Type_Enum == 9; //FLD.Type_Enum: 3=Setup, 4=kV Setup, 5=CT, 9=MVCT pm.SaveChanges(); fieldsInserted++; } } catch { fieldsInserted = -1; } finally { FieldsInserted.Set(context, fieldsInserted); } }
/// <summary> /// Activity heavy lifting. /// </summary> /// <param name="context"></param> protected override void DoWork(CodeActivityContext context) { // Activity inputs int patId1 = PatId.Get(context); EntityList <PrescriptionSite> rxSite = RxSite.Get(context); string regionName = RegionName.Get(context); double doseCoeff = DoseCoeff.Expression != null?DoseCoeff.Get(context) : 1.000; ImpacPersistenceManager pm = PersistenceManager.Expression != null ? PersistenceManager.Get(context) : PM; // Activity output DoseSiteCreated.Set(context, false); // Initialize the Activity output to False // Make sure rxSite is not supplied as a null (e.g. Nothing) if (rxSite == null) { return; } // Make sure none of the given Sites is Null if (rxSite.Count == 0) { return; } for (int i = 0; i < rxSite.Count; i++) { if (rxSite[i] == null) { return; } } // Only continue if doseCoeff given is within valid range if ((doseCoeff < 0.0) || (doseCoeff > 9.9990)) { return; } // Name for the Region cannot be empty or null if (string.IsNullOrEmpty(regionName)) { return; } // Trim regionName to max allowed chars const int maxSiteNameLength = 20; if (regionName.Length > maxSiteNameLength) { regionName = regionName.Substring(0, maxSiteNameLength); } // First check if supplied siteName exists already in the database var query = new ImpacRdbQuery(typeof(Region)); query.AddClause(Region.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1); query.AddClause(Region.Region_NameEntityColumn, EntityQueryOp.EQ, regionName); EntityList <Region> queryRegion = pm.GetEntities <Region>(query); if (queryRegion.Count > 0) { return; } // Check if any of the tip revision or historic Rx sites are already using the name var rxSitesQuery = new ImpacRdbQuery(typeof(PrescriptionSite)); rxSitesQuery.AddClause(PrescriptionSiteDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1); rxSitesQuery.AddClause(PrescriptionSiteDataRow.SiteNameEntityColumn, EntityQueryOp.EQ, regionName); if (pm.GetEntities <PrescriptionSite>(rxSitesQuery).Count > 0) { return; } // Create an entry in the Region table (new REG_ID will be used later) Region region = Region.Create(pm); region.Pat_ID1 = patId1; region.Region_Name = regionName; try { pm.SaveChanges(); } catch { return; } // Go through each Rx Site given and collect the treatment field properties var txField = new EntityList <Field>(); foreach (var t in rxSite) { query = new ImpacRdbQuery(typeof(PrescriptionSite)); query.AddClause(PrescriptionSite.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1); query.AddClause(PrescriptionSite.SIT_IDEntityColumn, EntityQueryOp.EQ, t.SIT_ID); query.AddClause(PrescriptionSite.VersionEntityColumn, EntityQueryOp.EQ, 0); EntityList <PrescriptionSite> site = pm.GetEntities <PrescriptionSite>(query); if (site.Count == 1) { query = new ImpacRdbQuery(typeof(Field)); query.AddClause(Field.SIT_Set_IDEntityColumn, EntityQueryOp.EQ, site[0].SIT_SET_ID); query.AddClause(Field.VersionEntityColumn, EntityQueryOp.EQ, 0); txField.AddRange(pm.GetEntities <Field>(query)); } } // Now add for each field an entry in the Coeff table with a link to the Region entry earlier int fieldsInserted = 0; try { foreach (var t in txField) { Coeff coeff = Coeff.Create(pm); coeff.Pat_ID1 = patId1; coeff.FLD_SET_ID = t.FLD_SET_ID; coeff.REG_ID = region.REG_ID; coeff.Reg_Coeff = doseCoeff; coeff.IsFromDataImport = false; coeff.IsModifiedAfterDataImport = false; pm.SaveChanges(); fieldsInserted++; } } finally { DoseSiteCreated.Set(context, fieldsInserted == txField.Count); } }