private static void Visit(IVertex node, ColorsSet colors,
                                  TimestampSet discovery, TimestampSet finish, LinkedList list, ref int time)
        {
            colors.Set(node, VertexColor.Gray);

            discovery.Register(node, time++);

            foreach (IVertex child in node.Adjacencies)
            {
                if (colors.ColorOf(child) == VertexColor.White)
                {
                    Visit(child, colors, discovery, finish, list, ref time);
                }
            }

            finish.Register(node, time++);

#if DEBUG
            System.Diagnostics.Debug.Assert(discovery.TimeOf(node) < finish.TimeOf(node));
#endif

            list.AddFirst(node);

            colors.Set(node, VertexColor.Black);
        }
Esempio n. 2
0
        /// <summary>
        /// Count recent activity
        /// </summary>
        public static int CountRecentActivity(TimeSpan since)
        {
            try
            {
                ClientRegistryAdminInterfaceClient client = new ClientRegistryAdminInterfaceClient();
                DateTime high = DateTime.Now,
                         low  = DateTime.Now.Subtract(since);

                TimestampSet sinceRange = new TimestampSet()
                {
                    part = new TimestampPart[] {
                        new TimestampPart()
                        {
                            value = low, type = TimestampPartType.LowBound
                        },
                        new TimestampPart()
                        {
                            value = high, type = TimestampPartType.HighBound
                        }
                    }
                };

                return(client.GetRecentActivity(sinceRange, 0, 0, true).count);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Create a timeset
        /// </summary>
        public static decimal CreateTimeset(IDbConnection conn, IDbTransaction tx, TimestampSet dateTime)
        {
            decimal?tsSetId = null;

            if (dateTime.Parts.Count == 0)
            {
                throw new ConstraintException("Timestamp set must contain at least one part");
            }

            // Create the parts
            foreach (var tsPart in dateTime.Parts)
            {
                // database commands
                if (tsSetId == null)
                {
                    tsSetId = CreateTimestamp(conn, tx, tsPart, tsSetId);
                }
                else
                {
                    CreateTimestamp(conn, tx, tsPart, tsSetId);
                }
            }

            return(tsSetId.Value);
        }
Esempio n. 4
0
        /// <summary>
        /// Get an effective time set
        /// </summary>
        public static TimestampSet GetEffectiveTimestampSet(IDbConnection conn, IDbTransaction tx, decimal tsId)
        {
            // Load the timestampset
            TimestampSet retVal = new TimestampSet();

            IDbCommand cmd = CreateCommandStoredProc(conn, tx);

            try
            {
                cmd.CommandText = "get_ts_set";
                cmd.Parameters.Add(CreateParameterIn(cmd, "ts_set_id_in", DbType.Decimal, tsId));
                IDataReader reader = cmd.ExecuteReader();
                try
                {
                    // Read all components
                    while (reader.Read())
                    {
                        TimestampPart pt = new TimestampPart();

                        // Classifier
                        switch (Convert.ToChar(reader["ts_cls"]))
                        {
                        case 'L':
                            pt.PartType = TimestampPart.TimestampPartType.LowBound;
                            break;

                        case 'U':
                            pt.PartType = TimestampPart.TimestampPartType.HighBound;
                            break;

                        case 'S':
                            pt.PartType = TimestampPart.TimestampPartType.Standlone;
                            break;

                        case 'W':
                            pt.PartType = TimestampPart.TimestampPartType.Width;
                            break;
                        }

                        // Value
                        pt.Precision = Convert.ToString(reader["ts_precision"]);
                        Trace.TraceInformation("{0} - {1}", reader["ts_id"].ToString(), reader["ts_date"].ToString());
                        pt.Value = pt.Precision == "D" || pt.Precision == "Y" || pt.Precision == "M" ? DateTime.Parse(reader["ts_date"].ToString()).Date : Convert.ToDateTime(reader["ts_value"]);
                        retVal.Parts.Add(pt);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            finally
            {
                cmd.Dispose();
            }

            return(retVal);
        }
Esempio n. 5
0
        /// <summary>
        /// Create an IVL from the TimeStampSet
        /// </summary>
        public IVL <TS> CreateIVL(TimestampSet timestampSet, List <IResultDetail> dtls)
        {
            if (timestampSet.Parts == null)
            {
                return new IVL <TS>()
                       {
                           NullFlavor = MARC.Everest.DataTypes.NullFlavor.NoInformation
                       }
            }
            ;

            // Return value
            IVL <TS> retVal = new IVL <TS>();

            foreach (var part in timestampSet.Parts)
            {
                switch (part.PartType)
                {
                case TimestampPart.TimestampPartType.HighBound:
                    retVal.High = CreateTS(part, dtls);
                    break;

                case TimestampPart.TimestampPartType.LowBound:
                    retVal.Low = CreateTS(part, dtls);
                    break;

                case TimestampPart.TimestampPartType.Standlone:
                    retVal.Value = CreateTS(part, dtls);
                    break;

                case TimestampPart.TimestampPartType.Width:
                    retVal.Width      = (decimal)part.Value.Subtract(DateTime.MinValue).TotalDays;
                    retVal.Width.Unit = "d";
                    break;
                }
            }

            if (retVal.Low != null && retVal.High != null && retVal.Low.Equals(retVal.High))
            {
                retVal.Value = retVal.Low;

                retVal.Low  = null;
                retVal.High = null;
            }
            return(retVal);
        }
        public static IVertex[] Sort(IVertex[] graphNodes)
        {
            ColorsSet    colors    = new ColorsSet(graphNodes);
            TimestampSet discovery = new TimestampSet();
            TimestampSet finish    = new TimestampSet();
            LinkedList   list      = new LinkedList();

            int time = 0;

            foreach (IVertex node in graphNodes)
            {
                if (colors.ColorOf(node) == VertexColor.White)
                {
                    Visit(node, colors, discovery, finish, list, ref time);
                }
            }

            return((IVertex[])list.ToArray(typeof(IVertex)));
        }
Esempio n. 7
0
        /// <summary>
        /// Get recent changes
        /// </summary>
        public static Models.PatientMatch[] GetRecentActivity(TimeSpan since, int offset, int count)
        {
            try
            {
                ClientRegistryAdminInterfaceClient client = new ClientRegistryAdminInterfaceClient();

                DateTime high = DateTime.Now,
                         low  = DateTime.Now.Subtract(since);

                TimestampSet sinceRange = new TimestampSet()
                {
                    part = new TimestampPart[] {
                        new TimestampPart()
                        {
                            value = low, type = TimestampPartType.LowBound
                        },
                        new TimestampPart()
                        {
                            value = high, type = TimestampPartType.HighBound
                        }
                    }
                };

                var registrations = client.GetRecentActivity(sinceRange, offset, count, false);
                ClientRegistryAdmin.Models.PatientMatch[] retVal = new PatientMatch[registrations.count];
                for (int i = 0; i < registrations.registration.Length; i++)
                {
                    ClientRegistryAdmin.Models.PatientMatch pm = ConvertRegistrationEvent(registrations.registration[i]);
                    // Address?
                    retVal[offset + i] = pm;
                }
                return(retVal);
            }
            catch
            {
                return(null);
            }
        }
        /// <summary>
        /// Create an MDM ivl_ts type
        /// </summary>
        protected TimestampSet CreateTimestamp(IVL <TS> ivl_ts, List <IResultDetail> dtls)
        {
            TimestampSet tss = new TimestampSet();

            // value
            if (ivl_ts.Value != null && !ivl_ts.Value.IsNull && !String.IsNullOrEmpty(ivl_ts.Value.Value))
            {
                if (!HasTimezone(ivl_ts.Value))
                {
                    dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, String.Format(ERR_NOTZ, ivl_ts.Value), null));
                }
                else if ((ivl_ts.Low == null || ivl_ts.Low.IsNull) && (ivl_ts.High == null || ivl_ts.High.IsNull))
                {
                    //dtls.Add(new ResultDetail(ResultDetailType.Warning, this.m_localeService.GetString("MSGW00D"), null, null));
                    //ivl_ts = ivl_ts.Value.ToIVL();
                    if (ivl_ts.Value.IsInvalidDate)
                    {
                        dtls.Add(new FormalConstraintViolationResultDetail(ResultDetailType.Error, String.Format("Date string {0} cannot be converted to a Timestamp", ivl_ts.Value.Value), null, null));
                    }
                    else
                    {
                        tss.Parts.Add(new TimestampPart(TimestampPart.TimestampPartType.Standlone, ivl_ts.Value.DateValue, m_precisionMap[ivl_ts.Value.DateValuePrecision.Value]));
                    }
                }
                else
                {
                    dtls.Add(new ResultDetail(ResultDetailType.Error, this.m_localeService.GetString("MSGE027"), null, null));
                }
            }
            else
            {
                // low
                if (ivl_ts.Low != null && !ivl_ts.Low.IsNull)
                {
                    if (!HasTimezone(ivl_ts.Low))
                    {
                        dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, String.Format(ERR_NOTZ, ivl_ts.Low), null));
                    }
                    else
                    {
                        if (ivl_ts.Low.IsInvalidDate)
                        {
                            dtls.Add(new FormalConstraintViolationResultDetail(ResultDetailType.Error, String.Format("Date string {0} cannot be converted to a Timestamp", ivl_ts.Low.Value), null, null));
                        }
                        else
                        {
                            tss.Parts.Add(new TimestampPart(TimestampPart.TimestampPartType.LowBound, ivl_ts.Low.DateValue, m_precisionMap[ivl_ts.Low.DateValuePrecision.Value]));
                        }
                    }
                }
                // high
                if (ivl_ts.High != null && !ivl_ts.High.IsNull)
                {
                    if (!HasTimezone(ivl_ts.High))
                    {
                        dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, String.Format(ERR_NOTZ, ivl_ts.High), null));
                    }
                    else
                    {
                        if (ivl_ts.High.IsInvalidDate)
                        {
                            dtls.Add(new FormalConstraintViolationResultDetail(ResultDetailType.Error, String.Format("Date string {0} cannot be converted to a Timestamp", ivl_ts.High.Value), null, null));
                        }
                        else
                        {
                            tss.Parts.Add(new TimestampPart(TimestampPart.TimestampPartType.HighBound, ivl_ts.High.DateValue, m_precisionMap[ivl_ts.High.DateValuePrecision.Value]));
                        }
                    }
                }
            }

            // check that some data exists
            if (tss.Parts.Count == 0)
            {
                dtls.Add(new ResultDetail(ResultDetailType.Error, ERR_NOTS_PARTS, (string)null));
                return(null);
            }
            return(tss);
        }
        /// <summary>
        /// Get recent activity
        /// </summary>
        public RegistrationEventCollection GetRecentActivity(TimestampSet timeRange, int offset, int count, bool identifierOnly)
        {
            // Get all Services
            IAuditorService          auditSvc = ApplicationContext.CurrentContext.GetService(typeof(IAuditorService)) as IAuditorService;
            IDataRegistrationService regSvc   = ApplicationContext.CurrentContext.GetService(typeof(IDataRegistrationService)) as IDataRegistrationService;
            IDataPersistenceService  repSvc   = ApplicationContext.CurrentContext.GetService(typeof(IDataPersistenceService)) as IDataPersistenceService;

            // Audit message
            AuditData audit = this.ConstructAuditData(ActionType.Read, EventIdentifierType.Export);

            audit.EventTypeCode = new CodeValue("ADM_GetRegistrations");

            try
            {
                // Result identifiers
                VersionedDomainIdentifier[] vids = null;
                var dummyQuery = new QueryEvent();
                dummyQuery.Add(new RegistrationEvent()
                {
                    EventClassifier = RegistrationEventType.Register, EffectiveTime = timeRange
                }, "SUBJ", SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.SubjectOf, null);
                vids = regSvc.QueryRecord(dummyQuery);

                RegistrationEventCollection retVal = new RegistrationEventCollection();
                Object syncLock = new object();

                retVal.Count = vids.Length;

                // Now fetch each one asynchronously
                if (!identifierOnly)
                {
                    using (WaitThreadPool thdPool = new WaitThreadPool(Environment.ProcessorCount * 2))
                    {
                        foreach (var id in vids.Skip(offset).Take(count))
                        {
                            thdPool.QueueUserWorkItem(
                                delegate(object state)
                            {
                                try
                                {
                                    var itm = repSvc.GetContainer(state as VersionedDomainIdentifier, true);
                                    lock (syncLock)
                                        retVal.Event.Add(itm as RegistrationEvent);
                                }
                                catch (Exception e)
                                {
                                    Trace.TraceError("Could not fetch result {0} : {1}", (state as VersionedDomainIdentifier).Identifier, e.ToString());
                                }
                            }
                                , id);
                        }

                        // Wait until fetch is done
                        thdPool.WaitOne(new TimeSpan(0, 0, 30), false);
                    }
                    //retVal.Event.Sort((a, b) => b.Timestamp.CompareTo(a.Timestamp));
                    // Add audit data
                    foreach (var res in retVal.Event)
                    {
                        audit.AuditableObjects.Add(new AuditableObject()
                        {
                            IDTypeCode    = AuditableObjectIdType.ReportNumber,
                            LifecycleType = AuditableObjectLifecycle.Export,
                            ObjectId      = String.Format("{0}^^^&{1}&ISO", res.AlternateIdentifier.Identifier, res.AlternateIdentifier.Domain),
                            Role          = AuditableObjectRole.MasterFile,
                            Type          = AuditableObjectType.SystemObject,
                            QueryData     = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("loadFast=true"))
                        });
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                Trace.TraceError("Could not execute GetRegistrations : {0}", e.ToString());
                audit.Outcome = OutcomeIndicator.EpicFail;
#if DEBUG
                throw new FaultException(new FaultReason(e.ToString()), new FaultCode(e.GetType().Name));
#else
                throw new FaultException(new FaultReason(e.Message), new FaultCode(e.GetType().Name));
#endif
            }
            finally
            {
                if (auditSvc != null)
                {
                    auditSvc.SendAudit(audit);
                }
            }
        }