Exemple #1
0
        private async Task PublishUpdateHearingParticipantsEvent(Hearing hearing, List <ExistingParticipantDetails> existingParticipants, List <NewParticipant> newParticipants,
                                                                 List <Guid> removedParticipantIds, List <LinkedParticipantDto> linkedParticipants)
        {
            var eventNewParticipants = hearing.GetParticipants()
                                       .Where(x => newParticipants.Any(y => y.Person.Username == x.Person.Username)).ToList();

            var eventExistingParticipants = hearing.GetParticipants()
                                            .Where(x => existingParticipants.Any(y => y.ParticipantId == x.Id)).ToList();

            var eventLinkedParticipants = new List <Infrastructure.Services.Dtos.LinkedParticipantDto>();

            foreach (var linkedParticipant in linkedParticipants)
            {
                var primaryLinkedParticipant   = hearing.GetParticipants().SingleOrDefault(x => x.Person.ContactEmail == linkedParticipant.ParticipantContactEmail);
                var secondaryLinkedParticipant = hearing.GetParticipants().SingleOrDefault(x => x.Person.ContactEmail == linkedParticipant.LinkedParticipantContactEmail);

                eventLinkedParticipants.Add(new Infrastructure.Services.Dtos.LinkedParticipantDto
                {
                    LinkedId      = secondaryLinkedParticipant.Id,
                    ParticipantId = primaryLinkedParticipant.Id,
                    Type          = linkedParticipant.Type
                });
            }

            var hearingParticipantsUpdatedIntegrationEvent = new HearingParticipantsUpdatedIntegrationEvent(hearing.Id, eventExistingParticipants, eventNewParticipants,
                                                                                                            removedParticipantIds, eventLinkedParticipants);
            await _eventPublisher.PublishAsync(hearingParticipantsUpdatedIntegrationEvent);
        }
Exemple #2
0
        /// <summary>
        /// Map an existing hearing to a CreateVideoHearingCommand for the purpose of multi-booking days
        /// </summary>
        /// <param name="hearing">Original hearing</param>
        /// <param name="newDate">New hearing date</param>
        /// <param name="randomGenerator">generator for unique sips</param>
        /// <param name="sipAddressStem">sip address stem</param>
        /// <param name="totalDays">Total number of days of multi-booking hearing</param>
        /// <param name="hearingDay">Day number of multi-booking hearing</param>
        /// <returns>command to create a new video hearing</returns>
        public static CreateVideoHearingCommand CloneToCommand(Hearing hearing, DateTime newDate,
                                                               IRandomGenerator randomGenerator, string sipAddressStem, int totalDays, int hearingDay)
        {
            var reps = hearing.GetParticipants().Where(x => x.HearingRole.UserRole.IsRepresentative)
                       .Cast <Representative>().ToList();
            var nonReps      = hearing.GetParticipants().Where(x => !x.HearingRole.UserRole.IsRepresentative).ToList();
            var participants = new List <NewParticipant>();

            participants.AddRange(reps.Select(r => new NewParticipant
            {
                Person      = r.Person,
                Representee = r.Representee,
                CaseRole    = r.CaseRole,
                DisplayName = r.DisplayName,
                HearingRole = r.HearingRole
            }));
            participants.AddRange(nonReps.Select(r => new NewParticipant
            {
                Person      = r.Person,
                CaseRole    = r.CaseRole,
                DisplayName = r.DisplayName,
                HearingRole = r.HearingRole
            }));

            var cases = hearing.GetCases().Select(c => new Case(c.Number, $"{c.Name} Day {hearingDay} of {totalDays}")
            {
                IsLeadCase = c.IsLeadCase
            }).ToList();

            var newEndpoints = hearing.GetEndpoints().Select(x =>
            {
                var sip = randomGenerator.GetWeakDeterministic(DateTime.UtcNow.Ticks, 1, 10);
                var pin = randomGenerator.GetWeakDeterministic(DateTime.UtcNow.Ticks, 1, 4);
                return(new NewEndpoint
                {
                    Pin = pin,
                    Sip = $"{sip}{sipAddressStem}",
                    DisplayName = x.DisplayName,
                    DefenceAdvocateUsername = x.DefenceAdvocate?.Person?.Username
                });
            }).ToList();

            var linkedParticipantDtos = GetLinkedParticipantDtos(hearing);

            var duration = 480;
            var command  = new CreateVideoHearingCommand(hearing.CaseType, hearing.HearingType, newDate,
                                                         duration, hearing.HearingVenue, participants, cases, true,
                                                         hearing.AudioRecordingRequired, newEndpoints, linkedParticipantDtos)
            {
                HearingRoomName  = hearing.HearingRoomName,
                OtherInformation = hearing.OtherInformation,
                CreatedBy        = hearing.CreatedBy,
                SourceId         = hearing.Id
            };

            return(command);
        }
Exemple #3
0
        public HearingIsReadyForVideoIntegrationEvent(Hearing hearing)
        {
            Hearing = HearingDtoMapper.MapToDto(hearing);
            var hearingParticipants = hearing.GetParticipants();

            Participants = hearingParticipants.Select(ParticipantDtoMapper.MapToDto).ToList();
        }
Exemple #4
0
        private async Task PublishParticipantsAddedEvent(IEnumerable <NewParticipant> newParticipants, Hearing hearing)
        {
            var participants = hearing.GetParticipants().Where(x => newParticipants.Any(y => y.Person.Username == x.Person.Username));

            if (participants != null && participants.Any())
            {
                await _eventPublisher.PublishAsync(new ParticipantsAddedIntegrationEvent(hearing.Id, participants));
            }
        }
        public HearingDetailsResponse MapHearingToDetailedResponse(Hearing videoHearing)
        {
            var caseMapper        = new CaseToResponseMapper();
            var participantMapper = new ParticipantToResponseMapper();

            var cases = videoHearing.GetCases()
                        .Select(x => caseMapper.MapCaseToResponse(x))
                        .ToList();

            var participants = videoHearing.GetParticipants()
                               .Select(x => participantMapper.MapParticipantToResponse(x))
                               .ToList();

            var endpoints = videoHearing.GetEndpoints()
                            .Select(EndpointToResponseMapper.MapEndpointToResponse)
                            .ToList();

            var response = new HearingDetailsResponse
            {
                Id = videoHearing.Id,
                ScheduledDuration        = videoHearing.ScheduledDuration,
                ScheduledDateTime        = videoHearing.ScheduledDateTime,
                HearingTypeName          = videoHearing.HearingType.Name,
                CaseTypeName             = videoHearing.CaseType.Name,
                HearingVenueName         = videoHearing.HearingVenueName,
                Cases                    = cases,
                Participants             = participants,
                HearingRoomName          = videoHearing.HearingRoomName,
                OtherInformation         = videoHearing.OtherInformation,
                CreatedBy                = videoHearing.CreatedBy,
                CreatedDate              = videoHearing.CreatedDate,
                UpdatedBy                = videoHearing.UpdatedBy,
                UpdatedDate              = videoHearing.UpdatedDate,
                ConfirmedBy              = videoHearing.ConfirmedBy,
                ConfirmedDate            = videoHearing.ConfirmedDate,
                Status                   = videoHearing.Status.MapToContractEnum(),
                QuestionnaireNotRequired = videoHearing.QuestionnaireNotRequired,
                AudioRecordingRequired   = videoHearing.AudioRecordingRequired,
                CancelReason             = videoHearing.CancelReason,
                GroupId                  = videoHearing.SourceId,
                Endpoints                = endpoints
            };

            return(response);
        }