/// <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> /// 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); } }