示例#1
0
        /// <summary>
        /// Create timestamp part
        /// </summary>
        public static decimal CreateTimestamp(IDbConnection conn, IDbTransaction tx, TimestampPart tsPart, decimal?tsSetId)
        {
            IDbCommand cmd = CreateCommandStoredProc(conn, tx);

            try
            {
                cmd.CommandText = "crt_ts";

                // Create a time-set, we'll use the identifier of the first time-component
                // as the site identifier
                cmd.Parameters.Add(CreateParameterIn(cmd, "ts_value_in", DbType.DateTime, tsPart.Precision == "D" ? tsPart.Value.Date : tsPart.Value));
                cmd.Parameters.Add(CreateParameterIn(cmd, "ts_precision_in", DbType.StringFixedLength, tsPart.Precision));
                cmd.Parameters.Add(CreateParameterIn(cmd, "ts_cls_in", DbType.StringFixedLength, m_timestampPartMap[tsPart.PartType]));
                cmd.Parameters.Add(CreateParameterIn(cmd, "ts_set_id_in", DbType.Decimal, (object)tsSetId ?? DBNull.Value));

                // Get the identifier
                decimal tsId = Convert.ToDecimal(cmd.ExecuteScalar());
                if (tsSetId == null)
                {
                    tsSetId = tsId;
                }
                return(tsId);
            }
            finally
            {
                cmd.Dispose();
            }
        }
示例#2
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);
        }
        /// <summary>
        /// Create a timestamp
        /// </summary>
        public TS CreateTS(TimestampPart part, List <IResultDetail> dtls)
        {
            if (part == null)
            {
                return(null);
            }
            DatePrecision prec = default(DatePrecision);

            foreach (var kv in ComponentUtil.m_precisionMap)
            {
                if (kv.Value.Equals(part.Precision))
                {
                    prec = kv.Key;
                }
            }
            return(new TS(part.Value, prec));
        }
示例#4
0
        /// <summary>
        /// Build the filter
        /// </summary>
        public string BuildFilter(IComponent data, bool forceExact)
        {
            // HACK: Come back and fix this ... Should build other filter parameters such as author, etc based on the
            // content of the registration event rather than hard-coding to the

            // Get the subject of the query
            //var subjectOfQuery = (data as HealthServiceRecordContainer).FindComponent(HealthServiceRecordSiteRoleType.SubjectOf) as Person;
            var hsr = data as RegistrationEvent;

            // Are we actually doing anything with this?
            if (hsr.EffectiveTime != null)
            {
                // Matching?
                StringBuilder sb = new StringBuilder("SELECT DISTINCT HSR_ID, HSR_VRSN_ID FROM HSR_VRSN_TBL INNER JOIN HSR_TBL USING (HSR_ID) WHERE OBSLT_UTC IS NULL AND STATUS_CS_ID NOT IN (16,64) ");
                sb.AppendFormat("AND HSR_CLS IN (4, 8) "); // only registrations

                if (hsr.EffectiveTime != null)
                {
                    // Before and after
                    TimestampPart low   = hsr.EffectiveTime.Parts.Find(o => o.PartType == TimestampPart.TimestampPartType.LowBound),
                                  high  = hsr.EffectiveTime.Parts.Find(o => o.PartType == TimestampPart.TimestampPartType.HighBound),
                                  stand = hsr.EffectiveTime.Parts.Find(o => o.PartType == TimestampPart.TimestampPartType.Standlone);
                    if (low != null && high != null)
                    {
                        sb.AppendFormat(" AND CRTN_UTC BETWEEN '{0:yyyy-MM-dd HH:mm:ssz}' AND '{1:yyyy-MM-dd HH:mm:ssz}' ", low.Value, high.Value);
                    }
                    else if (stand != null)
                    {
                        sb.AppendFormat(" AND CRTN_UTC = '{0:yyyy-MM-dd HH:mm:ssZ}' ", stand.Value);
                    }
                    else if (low != null)
                    {
                        sb.AppendFormat(" AND CRTN_UTC > '{0:yyyy-MM-dd HH:mm:ssZ}' ", low.Value);
                    }
                    else if (high != null)
                    {
                        sb.AppendFormat(" AND CRTN_UTC > '{0:yyyy-MM-dd HH:mm:ssZ}' ", high.Value);
                    }
                }
                return(sb.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
        /// <summary>
        /// Create a timestamp
        /// </summary>
        public TS CreateTS(TimestampPart part)
        {
            if (part == null)
            {
                return(null);
            }
            DatePrecision prec = default(DatePrecision);

            foreach (var kv in m_precisionMap)
            {
                if (kv.Value.Equals(part.Precision))
                {
                    prec = kv.Key;
                }
            }
            return(new TS(part.Value, prec));
        }
 /// <summary>
 /// Find client by name
 /// </summary>
 /// TODO: Make this more friendly for other DBMS other than PGSQL
 public Client[] FindClient(NameSet name, string genderCode, TimestampPart birthTime)
 {
     throw new NotImplementedException("Find not supported");
 }