Example #1
0
        /// <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();
            }
        }
Example #2
0
        /// <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 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();
            }
        }