public async Task Handle(MedicalfileAddedEvent message, CancellationToken token)
        {
            var medicalfile = MedicalfileAggregate.New(new List <DomainEvent>
            {
                message
            });
            await _medicalfileCommandRepository.Add(medicalfile, token);

            await _medicalfileCommandRepository.Commit(token);
        }
Example #2
0
 public static GetMedicalfileResult ToResult(this MedicalfileAggregate medicalFile)
 {
     return(new GetMedicalfileResult
     {
         CreateDateTime = medicalFile.CreateDateTime,
         Id = medicalFile.Id,
         PatientFirstname = medicalFile.PatientFirstname,
         PatientId = medicalFile.PatientId,
         PatientLastname = medicalFile.PatientLastname,
         PatientNiss = medicalFile.PatientNiss,
         UpdateDateTime = medicalFile.UpdateDateTime
     });
 }
        public async Task <GetMedicalfileResult> Handle(AddMedicalfileCommand request, CancellationToken cancellationToken)
        {
            var id          = MedicalfileAggregate.BuildId(request.PrescriberId, request.PatientId);
            var medicalfile = await _eventStoreRepository.GetLastAggregate <MedicalfileAggregate>(id, MedicalfileAggregate.GetStreamName(id));

            if (medicalfile != null && !string.IsNullOrWhiteSpace(medicalfile.Id))
            {
                throw new BadRequestException(Global.ConcurrentMedicalfile);
            }

            var patient = await _patientQueryRepository.GetById(request.PatientId, cancellationToken);

            if (patient == null)
            {
                throw new UnknownPatientException(request.PatientId, string.Format(Global.UnknownPatient, request.PatientId));
            }

            var medicalFile = MedicalfileAggregate.New(request.PrescriberId, request.PatientId, patient.NationalIdentityNumber, patient.Firstname, patient.Lastname);
            await _commitAggregateHelper.Commit(medicalFile, medicalFile.GetStreamName(), Constants.QueueNames.Medicalfile);

            return(medicalFile.ToResult());
        }
Example #4
0
 public Task Add(MedicalfileAggregate medicalfile, CancellationToken token)
 {
     _medicalFiles.Add((MedicalfileAggregate)medicalfile.Clone());
     return(Task.CompletedTask);
 }