/// <summary> /// Create an HSR record /// </summary> private VersionedDomainIdentifier CreateHSRRecord(IDbConnection conn, IDbTransaction tx, ChangeSummary hsr) { IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx); cmd.CommandText = "crt_hsr"; // Get the terminology service ISystemConfigurationService iscs = ApplicationContext.ConfigurationService; //ApplicationContext.Current.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // Parameters // classifier = 0x400 = Change Summary cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "hsr_cls_in", DbType.Decimal, RegistrationEventType.ComponentEvent | RegistrationEventType.Revise)); // event type code cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "evt_typ_cd_id_in", DbType.Decimal, DbUtil.CreateCodedValue(conn, tx, hsr.ChangeType))); // refuted indicator cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "refuted_ind_in", DbType.Boolean, false)); decimal?efftTimeId = null; if (hsr.EffectiveTime != null) { efftTimeId = DbUtil.CreateTimeset(conn, tx, hsr.EffectiveTime); } cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "efft_ts_set_id_in", DbType.Decimal, efftTimeId == null ? (object)DBNull.Value : efftTimeId.Value)); // status code cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "status_cs_in", DbType.Decimal, hsr.Status == null ? (object)DBNull.Value : (int)hsr.Status)); // authored time cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "aut_utc_in", DbType.DateTime, hsr.Timestamp == default(DateTime) ? (object)DBNull.Value : hsr.Timestamp)); // language code cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "lang_cs_in", DbType.String, hsr.LanguageCode)); // Execute the command IDataReader resultRdr = cmd.ExecuteReader(); try { // Create the return value VersionedDomainIdentifier id = new VersionedDomainIdentifier(); if (!resultRdr.Read()) { return(null); } id.Version = Convert.ToString(resultRdr["VRSN_ID"]); id.Identifier = Convert.ToString(resultRdr["ID"]); id.Domain = iscs.OidRegistrar.GetOid(ClientRegistryOids.EVENT_OID).Oid; return(id); } finally { resultRdr.Close(); } }
/// <summary> /// Create an HSR version /// </summary> private decimal CreateHSRVersion(IDbConnection conn, IDbTransaction tx, RegistrationEvent hsr) { IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx); try { cmd.CommandText = "crt_hsr_vrsn"; cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "hsr_id_in", DbType.Decimal, hsr.Id)); decimal?codeId = null; if (hsr.EventType != null) { codeId = DbUtil.CreateCodedValue(conn, tx, hsr.EventType); } cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "evt_typ_cd_id_in", DbType.Decimal, codeId.HasValue ? (object)codeId.Value : DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "refuted_ind_in", DbType.Boolean, hsr.Refuted)); // Effective time if needed decimal?hsrEfftTsId = null; if (hsr.EffectiveTime != null) { hsrEfftTsId = DbUtil.CreateTimeset(conn, tx, hsr.EffectiveTime); } // Parameters cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "efft_ts_set_id_in", DbType.Decimal, (object)hsrEfftTsId ?? DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "status_cs_in", DbType.Decimal, hsr.Status == StatusType.Unknown ? (object)DBNull.Value : (int)hsr.Status)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "aut_utc_in", DbType.DateTime, hsr.Timestamp == default(DateTime) ? (object)DBNull.Value : hsr.Timestamp)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "lang_cs_in", DbType.StringFixedLength, (object)hsr.LanguageCode ?? DBNull.Value)); return(Convert.ToDecimal(cmd.ExecuteScalar())); } finally { cmd.Dispose(); } }
/// <summary> /// Create the HSR record /// </summary> internal VersionedDomainIdentifier CreateHSRRecord(IDbConnection conn, IDbTransaction tx, RegistrationEvent hsr) { IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx); cmd.CommandText = "crt_hsr"; // Get the terminology service //ITerminologyService its = ApplicationContext.CurrentContext.GetService(typeof(ITerminologyService)) as ITerminologyService; ISystemConfigurationService iscs = ApplicationContext.ConfigurationService; //ApplicationContext.Current.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // Validate the language code //if (its != null) //{ // var validationError = its.Validate(hsr.LanguageCode, null, CodeSystemName.ISO639); // if (validationError.Outcome != MARC.HI.EHRS.SVC.Core.Terminology.ValidationOutcome.ValidWithWarning && // validationError.Outcome != MARC.HI.EHRS.SVC.Core.Terminology.ValidationOutcome.Valid) // throw new ConstraintException("Language MUST be a valid ISO639 Country code in the format XX-XX"); //} // Parameters // classifier cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "hsr_cls_in", DbType.Decimal, (int)hsr.EventClassifier)); // event type code cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "evt_typ_cd_id_in", DbType.Decimal, DbUtil.CreateCodedValue(conn, tx, hsr.EventType))); // refuted indicator cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "refuted_ind_in", DbType.Boolean, hsr.Refuted)); decimal?efftTimeId = null; if (hsr.EffectiveTime != null) { efftTimeId = DbUtil.CreateTimeset(conn, tx, hsr.EffectiveTime); } cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "efft_ts_set_id_in", DbType.Decimal, efftTimeId == null ? (object)DBNull.Value : efftTimeId.Value)); // status code cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "status_cs_in", DbType.Decimal, hsr.Status == null ? (object)DBNull.Value : (int)hsr.Status)); // authored time cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "aut_utc_in", DbType.DateTime, hsr.Timestamp == default(DateTime) ? (object)DBNull.Value : hsr.Timestamp)); // language code cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "lang_cs_in", DbType.String, hsr.LanguageCode)); // Execute the command IDataReader resultRdr = cmd.ExecuteReader(); try { // Create the return value VersionedDomainIdentifier id = new VersionedDomainIdentifier(); if (!resultRdr.Read()) { return(null); } id.Version = Convert.ToString(resultRdr["VRSN_ID"]); id.Identifier = Convert.ToString(resultRdr["ID"]); id.Domain = iscs.OidRegistrar.GetOid(ClientRegistryOids.REGISTRATION_EVENT).Oid; return(id); } finally { resultRdr.Close(); } }