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