/// <summary> /// Import authority groups. /// </summary> /// <remarks> /// Creates any authority groups that do not already exist. /// This method performs an additive import. It will never remove an existing authority group or /// remove authority tokens from an existing group. /// </remarks> /// <param name="groupDefs"></param> /// <param name="context"></param> public IList <AuthorityGroup> Import(IEnumerable <AuthorityGroupDefinition> groupDefs, IUpdateContext context) { // first load all the existing tokens into memory // there should not be that many tokens ( < 500), so this should not be a problem IAuthorityTokenBroker tokenBroker = context.GetBroker <IAuthorityTokenBroker>(); IList <AuthorityToken> existingTokens = tokenBroker.FindAll(); // load existing groups IAuthorityGroupBroker groupBroker = context.GetBroker <IAuthorityGroupBroker>(); IList <AuthorityGroup> existingGroups = groupBroker.FindAll(); foreach (AuthorityGroupDefinition groupDef in groupDefs) { AuthorityGroup group = CollectionUtils.SelectFirst(existingGroups, g => g.Name == groupDef.Name); // if group does not exist, create it if (group == null) { group = new AuthorityGroup { Name = groupDef.Name, Description = groupDef.Description, DataGroup = groupDef.DataGroup }; context.Lock(group, DirtyState.New); existingGroups.Add(group); } // process all token nodes contained in group foreach (string tokenName in groupDef.Tokens) { AuthorityToken token = CollectionUtils.SelectFirst(existingTokens, t => t.Name == tokenName); // ignore non-existent tokens if (token == null) { continue; } // add the token to the group group.AuthorityTokens.Add(token); } } return(existingGroups); }
/// <summary> /// Import authority groups. /// </summary> /// <remarks> /// Creates any authority groups that do not already exist. /// This method performs an additive import. It will never remove an existing authority group or /// remove authority tokens from an existing group. /// </remarks> /// <param name="groupDefs"></param> /// <param name="context"></param> public IList<AuthorityGroup> Import(IEnumerable<AuthorityGroupDefinition> groupDefs, IUpdateContext context) { // first load all the existing tokens into memory // there should not be that many tokens ( < 500), so this should not be a problem IAuthorityTokenBroker tokenBroker = context.GetBroker<IAuthorityTokenBroker>(); IList<AuthorityToken> existingTokens = tokenBroker.FindAll(); // load existing groups IAuthorityGroupBroker groupBroker = context.GetBroker<IAuthorityGroupBroker>(); IList<AuthorityGroup> existingGroups = groupBroker.FindAll(); foreach (AuthorityGroupDefinition groupDef in groupDefs) { AuthorityGroup group = CollectionUtils.SelectFirst(existingGroups, g => g.Name == groupDef.Name); // if group does not exist, create it if (group == null) { group = new AuthorityGroup { Name = groupDef.Name, Description = groupDef.Description, DataGroup = groupDef.DataGroup }; context.Lock(group, DirtyState.New); existingGroups.Add(group); } // process all token nodes contained in group foreach (string tokenName in groupDef.Tokens) { AuthorityToken token = CollectionUtils.SelectFirst(existingTokens, t => t.Name == tokenName); // ignore non-existent tokens if (token == null) continue; // add the token to the group group.AuthorityTokens.Add(token); } } return existingGroups; }
/// <summary> /// Import external practitioner from CSV format. /// </summary> /// <param name="rows"> /// Each string in the list must contain 4 CSV fields, as follows: /// 0 - Facility ID /// 1 - Facility Name /// 2 - Information Authority ID /// 3 - Information Authoirty Name /// </param> /// <param name="context"></param> public override void Import(List <string> rows, IUpdateContext context) { _enumBroker = context.GetBroker <IEnumBroker>(); _authorities = new List <InformationAuthorityEnum>(_enumBroker.Load <InformationAuthorityEnum>(true)); List <Facility> facilities = new List <Facility>(); foreach (string line in rows) { // expect 4 fields in the row string[] fields = ParseCsv(line, 4); string facilityId = fields[0]; string facilityName = fields[1]; string facilityDescription = fields[2]; string informationAuthorityId = fields[3]; string informationAuthorityName = fields[4]; // first check if we have it in memory Facility facility = CollectionUtils.SelectFirst(facilities, delegate(Facility f) { return(f.Code == facilityId && f.Name == facilityName); }); // if not, check the database if (facility == null) { FacilitySearchCriteria where = new FacilitySearchCriteria(); where.Code.EqualTo(facilityId); where.Name.EqualTo(facilityName); IFacilityBroker broker = context.GetBroker <IFacilityBroker>(); facility = CollectionUtils.FirstElement(broker.Find(where)); // if not, create a new instance if (facility == null) { facility = new Facility(facilityId, facilityName, facilityDescription, GetAuthority(informationAuthorityId, informationAuthorityName)); context.Lock(facility, DirtyState.New); } facilities.Add(facility); } } }
/// <summary> /// Import external practitioner from CSV format. /// </summary> /// <param name="rows"> /// Each string in the list must contain 4 CSV fields, as follows: /// 0 - Facility ID /// 1 - Facility Name /// 2 - Information Authority ID /// 3 - Information Authoirty Name /// </param> /// <param name="context"></param> public override void Import(List<string> rows, IUpdateContext context) { _enumBroker = context.GetBroker<IEnumBroker>(); _authorities = new List<InformationAuthorityEnum>(_enumBroker.Load<InformationAuthorityEnum>(true)); List<Facility> facilities = new List<Facility>(); foreach (string line in rows) { // expect 4 fields in the row string[] fields = ParseCsv(line, 4); string facilityId = fields[0]; string facilityName = fields[1]; string facilityDescription = fields[2]; string informationAuthorityId = fields[3]; string informationAuthorityName = fields[4]; // first check if we have it in memory Facility facility = CollectionUtils.SelectFirst(facilities, delegate(Facility f) { return f.Code == facilityId && f.Name == facilityName; }); // if not, check the database if (facility == null) { FacilitySearchCriteria where = new FacilitySearchCriteria(); where.Code.EqualTo(facilityId); where.Name.EqualTo(facilityName); IFacilityBroker broker = context.GetBroker<IFacilityBroker>(); facility = CollectionUtils.FirstElement(broker.Find(where)); // if not, create a new instance if (facility == null) { facility = new Facility(facilityId, facilityName, facilityDescription, GetAuthority(informationAuthorityId, informationAuthorityName)); context.Lock(facility, DirtyState.New); } facilities.Add(facility); } } }
protected override void Import(ExternalPractitionerData data, IUpdateContext context) { var prac = LoadExternalPractitioner( data.LicenseNumber, data.BillingNumber, context); var name = new PersonName(data.FamilyName, data.GivenName, data.MiddleName, null, null, null); if (prac == null) { // Creating a new practitioenr: Import prac = new ExternalPractitioner(name, data.LicenseNumber, data.BillingNumber, data.IsVerified, data.LastVerifiedTime, data.LastEditedTime, new HashedSet <ExternalPractitionerContactPoint>(), new Dictionary <string, string>(), null); context.Lock(prac, DirtyState.New); } else { prac.Name = name; prac.MarkEdited(); } prac.MarkDeactivated(data.Deactivated); if (data.ContactPoints != null) { foreach (var cpData in data.ContactPoints) { var cp = CollectionUtils.SelectFirst(prac.ContactPoints, p => p.Name == cpData.Name) ?? new ExternalPractitionerContactPoint(prac); UpdateExternalPractitionerContactPoint(cpData, cp, context); } } ExtendedPropertyUtils.Update(prac.ExtendedProperties, data.ExtendedProperties); }
private static AuthorityToken ProcessToken(AuthorityTokenDefinition tokenDef, ICollection <AuthorityToken> existingTokens, IUpdateContext context) { // look for an existing instance of the token, or a token that should be renamed to this token var token = existingTokens.FirstOrDefault(t => t.Name == tokenDef.Token || tokenDef.FormerIdentities.Contains(t.Name)); if (token != null) { // update the name (in the case it is a rename) token.Name = tokenDef.Token; // update the description token.Description = tokenDef.Description; } else { // the token does not already exist, so create it token = new AuthorityToken(tokenDef.Token, tokenDef.Description); context.Lock(token, DirtyState.New); existingTokens.Add(token); } return(token); }
private static AuthorityToken ProcessToken(AuthorityTokenDefinition tokenDef, ICollection<AuthorityToken> existingTokens, IUpdateContext context) { // look for an existing instance of the token, or a token that should be renamed to this token var token = existingTokens.FirstOrDefault(t => t.Name == tokenDef.Token || tokenDef.FormerIdentities.Contains(t.Name)); if (token != null) { // update the name (in the case it is a rename) token.Name = tokenDef.Token; // update the description token.Description = tokenDef.Description; } else { // the token does not already exist, so create it token = new AuthorityToken(tokenDef.Token, tokenDef.Description); context.Lock(token, DirtyState.New); existingTokens.Add(token); } return token; }