Ejemplo n.º 1
0
        private static OpenHR001Location[] GetLocations()
        {
            OpenHR001Location[] locations = OpenHRPatients
                                            .SelectMany(pat => pat.OpenHealthRecord.adminDomain.location)
                                            .DistinctBy(loc => loc.id)
                                            .OrderBy(loc => loc.name)
                                            .ToArray();

            return(locations);
        }
Ejemplo n.º 2
0
        private static OpenHROrganisation[] GetOrganisations()
        {
            List <OpenHROrganisation> structuredOrganisations = new List <OpenHROrganisation>();

            OpenHR001Organisation[] organisations = OpenHRPatients
                                                    .SelectMany(t => t.OpenHealthRecord.adminDomain.organisation.Where(s => new Guid(s.id) == new Guid(t.OpenHealthRecord.author.organisation)))
                                                    .DistinctBy(t => t.id)
                                                    .OrderBy(t => t.name)
                                                    .ToArray();

            int organisationId = 1;
            int locationId     = 1;
            int userId         = 1;

            foreach (OpenHR001Organisation organisation in organisations)
            {
                OpenHRPatient[] openHRAtOrganisation = OpenHRPatients
                                                       .Where(t => new Guid(t.OpenHealthRecord.author.organisation) == new Guid(organisation.id))
                                                       .ToArray();

                OpenHR001User[] users = openHRAtOrganisation
                                        .SelectMany(t => t.OpenHealthRecord.adminDomain.user)
                                        .DistinctBy(t => new Guid(t.id))
                                        .ToArray();

                List <OpenHRUser> structuredUsers = new List <OpenHRUser>();

                int organisationUserCount = 1;

                foreach (OpenHR001User user in users)
                {
                    OpenHRUser structuredUser = new OpenHRUser();
                    structuredUser.OpenHRUserId = userId++;
                    structuredUser.User         = user;
                    structuredUser.UserInRole   = openHRAtOrganisation.SelectMany(t => t.OpenHealthRecord.adminDomain.userInRole).FirstOrDefault(t => new Guid(t.user) == new Guid(user.id));
                    structuredUser.Role         = openHRAtOrganisation.SelectMany(t => t.OpenHealthRecord.adminDomain.role).FirstOrDefault(t => new Guid(t.id) == new Guid(structuredUser.UserInRole.id));
                    structuredUser.Person       = openHRAtOrganisation.SelectMany(t => t.OpenHealthRecord.adminDomain.person).FirstOrDefault(t => new Guid(t.id) == new Guid(structuredUser.User.userPerson));
                    structuredUser.Organisation = organisation;

                    if (organisationUserCount <= _maxSessionHoldersPerOrganisation)
                    {
                        structuredUser.IsSessionHolder = true;
                    }

                    organisationUserCount++;

                    structuredUsers.Add(structuredUser);
                }

                OpenHRLocation[] locations = openHRAtOrganisation
                                             .SelectMany(t => t.OpenHealthRecord.adminDomain.location)
                                             .Where(t => (new Guid(t.id) == new Guid(organisation.mainLocation)) || (organisation.locations.Select(s => new Guid(s.location)).Contains(new Guid(t.id))))
                                             .DistinctBy(t => new Guid(t.id))
                                             .Select(t => new OpenHRLocation(locationId++, t))
                                             .ToArray();

                structuredOrganisations.Add(new OpenHROrganisation(
                                                organisationId: organisationId++,
                                                organisation: organisation,
                                                locations: locations,
                                                users: structuredUsers.ToArray()));
            }

            return(structuredOrganisations.ToArray());
        }