public async Task <GetPatientQueryResult> Handle(GetPatientByIdQuery query, CancellationToken token) { var patient = await _patientQueryRepository.GetById(query.Id, token); if (patient == null) { throw new UnknownPatientException(query.Id, string.Format(Global.UnknownPatient, query.Id)); } return(patient.ToResult()); }
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()); }