/// <summary> /// Create a location /// </summary> private void CreateLocation(System.Data.IDbConnection conn, System.Data.IDbTransaction tx, Place loc) { IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx); try { cmd.CommandText = "crt_plc"; // Insert the code decimal?codeId = loc.LocationType != null ? (decimal?)DbUtil.CreateCodedValue(conn, tx, loc.LocationType) : null, addrSetId = loc.Address != null ? (decimal?)DbUtil.CreateAddressSet(conn, tx, loc.Address) : null; // parameters cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_name_in", DbType.StringFixedLength, (object)loc.Name ?? DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_cls_cs_in", DbType.StringFixedLength, ((object)loc.Class ?? "PLC"))); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_addr_set_id_in", DbType.Decimal, (object)addrSetId ?? DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_typ_cd_id_in", DbType.Decimal, (object)codeId ?? DBNull.Value)); // Execute the parameter loc.Id = Convert.ToDecimal(cmd.ExecuteScalar()); // Register an alternate identifier if they exist foreach (var id in loc.AlternateIdentifiers) { CreateAlternateIdentifier(conn, tx, loc.Id, id); } } finally { cmd.Dispose(); } }
/// <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> /// Update location /// </summary> private void UpdateLocation(IDbConnection conn, IDbTransaction tx, Place loc) { IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx); try { cmd.CommandText = "upd_plc"; // parameters cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_id_in", DbType.Decimal, loc.Id)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_addr_set_id_in", DbType.Decimal, loc.Address == null ? DBNull.Value : (Object)DbUtil.CreateAddressSet(conn, tx, loc.Address))); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "plc_typ_cd_id_in", DbType.Decimal, loc.LocationType == null ? DBNull.Value : (Object)DbUtil.CreateCodedValue(conn, tx, loc.LocationType))); // Execute cmd.ExecuteNonQuery(); } finally { cmd.Dispose(); } }
/// <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 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(); } }
/// <summary> /// Create a participant /// </summary> private void CreatePtcpt(System.Data.IDbConnection conn, System.Data.IDbTransaction tx, HealthcareParticipant ptcpt) { IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx); try { // Create name set decimal?nameSetId = null, addrSetId = null, typeCodeId = null; // Create name if (ptcpt.LegalName != null) { nameSetId = DbUtil.CreateNameSet(conn, tx, ptcpt.LegalName); } if (ptcpt.PrimaryAddress != null) { addrSetId = DbUtil.CreateAddressSet(conn, tx, ptcpt.PrimaryAddress); } if (ptcpt.Type != null) { typeCodeId = DbUtil.CreateCodedValue(conn, tx, ptcpt.Type); } // Does // Create person if (ptcpt.Classifier == HealthcareParticipant.HealthcareParticipantType.Person) { cmd.CommandText = "crt_hc_ptcpt_psn"; cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_name_set_id_in", DbType.Decimal, (object)nameSetId ?? DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_addr_set_id_in", DbType.Decimal, (object)addrSetId ?? DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_tel_in", DbType.StringFixedLength, DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_typ_cd_id_in", DbType.Decimal, (object)typeCodeId ?? DBNull.Value)); } else { cmd.CommandText = "crt_hc_ptcpt_org"; cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_name_in", DbType.StringFixedLength, ptcpt.LegalName != null && ptcpt.LegalName.Parts.Count > 0 ? (object)ptcpt.LegalName.Parts[0].Value : DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_addr_set_id_in", DbType.Decimal, (object)addrSetId ?? DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_work_tel_in", DbType.StringFixedLength, DBNull.Value)); cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "ptcpt_typ_cd_id_in", DbType.Decimal, (object)typeCodeId ?? DBNull.Value)); } // Execute a scalar ptcpt.Id = Convert.ToDecimal(cmd.ExecuteScalar()); // Register an alternate identifier if they exist // normalize alt identifiers, remove duplicates for (int i = ptcpt.AlternateIdentifiers.Count - 1; i > 0; i--) { if (ptcpt.AlternateIdentifiers.Count(o => o.Domain.Equals(ptcpt.AlternateIdentifiers[i].Domain) || o.Identifier.Equals(ptcpt.AlternateIdentifiers[i].Identifier)) > 1) { ptcpt.AlternateIdentifiers.RemoveAt(i); } } foreach (var id in ptcpt.AlternateIdentifiers) { CreateAlternateIdentifier(conn, tx, ptcpt.Id, id); } // Register all telecom addresses if (ptcpt.TelecomAddresses != null) { foreach (var tel in ptcpt.TelecomAddresses) { CreateTelecommunicationsAddress(conn, tx, tel, ptcpt.Id); } } } finally { cmd.Dispose(); } }