public async Task <IActionResult> Post([FromBody] CreateConsultationRequest request) { var consultationCommand = mapper.Map <CreateConsultationCommand>(request); consultationCommand.CreatedBy = Guid.Parse(User.Claims.FirstOrDefault(x => x.Type == "id").Value); var getPatientTask = patientApi.GetPatient(request.PatientId); var getClinicTask = clinicApi.GetClinic(request.ClinicId); await Task.WhenAll(getPatientTask, getClinicTask); var getPatientResultTask = getPatientTask.Result.Content.DeserializeStringContent <DTO.Patient.GetPatientResponse>(); var getClinicResultTask = getClinicTask.Result.Content.DeserializeStringContent <DTO.Clinic.GetClinicResponse>(); await Task.WhenAll(getPatientResultTask, getClinicResultTask); consultationCommand.ClinicName = getClinicResultTask.Result.Name; consultationCommand.PatientName = getPatientResultTask.Result.FirstName + " " + getPatientResultTask.Result.LastName; var consultationCreateResponse = await consultationApi.SaveConsultation(consultationCommand); var consultationCreateContent = await consultationCreateResponse.Content.DeserializeStringContent <string>(); if (!consultationCreateResponse.IsSuccessStatusCode) { return(BadRequest(consultationCreateContent)); } return(CreatedAtAction(nameof(GetConsultationById), new { id = consultationCreateContent }, consultationCreateContent)); }
public CreateConsultationRequestValidator( IClinicApi clinicApi, IPatientApi patientApi) { RuleFor(x => x.ClinicId) .NotEmpty() .WithMessage("Provide ClinicId") .MustAsync(async(clinicId, cancellationToken) => { var clinic = await clinicApi.GetClinic(clinicId); if (!clinic.IsSuccessStatusCode) { return(false); } return(true); }) .WithMessage("Clinic does not exists"); RuleFor(x => x.PatientId) .NotEmpty() .WithMessage("Provide PatientId") .MustAsync(async(patientId, cancellationToken) => { var patient = await patientApi.GetPatient(patientId); if (!patient.IsSuccessStatusCode) { return(false); } return(true); }) .WithMessage("Patient does not exists"); }
public async Task <IActionResult> GetPatientById([FromRoute] Guid id) { var patientRequest = await patientApi.GetPatient(id); if (!patientRequest.IsSuccessStatusCode) { return(NotFound()); } var patient = await patientRequest.Content.DeserializeStringContent <GetPatientResponse>(); return(Ok(patient)); }