/// <summary> /// Persist the specified component to the database /// </summary> public MARC.HI.EHRS.SVC.Core.DataTypes.VersionedDomainIdentifier Persist(System.Data.IDbConnection conn, System.Data.IDbTransaction tx, System.ComponentModel.IComponent data, bool isUpdate) { ISystemConfigurationService configServce = ApplicationContext.ConfigurationService; //ApplicationContext.Current.GetService(typeof(ISystemConfigurationService)) as ISystemConfigurationService; // First, we must determine if we're going to be performing an update or a put Place loc = data as Place; // Do we have the shrid? if (loc.Id == default(decimal)) // nope { // Attempt to get the SHRID int iId = 0; Place resLoc = null; if (loc.AlternateIdentifiers.Count > 0) { while (resLoc == null && iId < loc.AlternateIdentifiers.Count) { resLoc = GetLocation(conn, tx, loc.AlternateIdentifiers[iId]); iId++; } } if (resLoc == null) // We need to create a client { CreateLocation(conn, tx, loc); } else { // Validate the name given matches the legal name. Has to be more than // 80% match if ((loc.Name == null) ^ (resLoc.Name == null) || loc.Name != null && resLoc.Name != null && !loc.Name.ToLower().Equals(resLoc.Name.ToLower())) { throw new DataException("The provided name does not match the name of location in data store"); } loc.Id = resLoc.Id; bool nUpdate = resLoc.LocationType != null && loc.LocationType != null && resLoc.LocationType.Code != loc.LocationType.Code || QueryUtil.MatchAddress(resLoc.Address, loc.Address) != 1.0f; loc.Name = resLoc.Name ?? loc.Name; loc.Address = resLoc.Address ?? loc.Address; loc.LocationType = resLoc.LocationType ?? loc.LocationType; // Register alternative identifiers foreach (var id in loc.AlternateIdentifiers) { if (resLoc.AlternateIdentifiers.Count(o => o.Domain == id.Domain) == 0) // register { CreateAlternateIdentifier(conn, tx, loc.Id, id); } } if (nUpdate) { UpdateLocation(conn, tx, loc); } } } // Persist the site with the container if known if (loc.Site.Container is RegistrationEvent) { LinkHealthServiceRecord(conn, tx, (loc.Site.Container as RegistrationEvent).Id, loc.Site as HealthServiceRecordSite); } // Return the versioned identifier return(new VersionedDomainIdentifier() { Domain = configServce.OidRegistrar.GetOid(ClientRegistryOids.LOCATION_CRID).Oid, Identifier = loc.Id.ToString() }); }