Ejemplo n.º 1
0
        public async Task <CreatePatientResponse> CreatePatient(CreatePatientRequest request)
        {
            string resource    = $"/api/patients";
            var    restRequest = new RestRequest(resource, Method.POST);

            restRequest.AddParameter("application/json", JsonConvert.SerializeObject(request), ParameterType.RequestBody);
            IRestResponse response = await MakeCall(restRequest);

            return(JsonConvert.DeserializeObject <CreatePatientResponse>(response.Content));
        }
        public async Task <IActionResult> PostAsync(CreatePatientRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Patients/Post was requested.");


            var response = await unitOfWork.Patients.CreateAsync(_mapper.Map <PatientDTO>(request));

            unitOfWork.Save();
            return(Ok(_mapper.Map <PatientResponse>(response)));
        }
Ejemplo n.º 3
0
        public async Task <CreatePatientResponse> Create(CreatePatientRequest request)
        {
            try
            {
                var patient = new Patient(request.FirstName, request.LastName, request.Email);
                _dbContext.Patients.Add(patient);
                await _dbContext.SaveChangesAsync();

                return(new CreatePatientResponse(patient));
            }
            catch (Exception ex)
            {
                // log details somewhere. i.e. inner exception, stacktrace, etc...
                return(new CreatePatientResponse("There was an error creating a new Patient"));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] CreatePatientRequest request)
        {
            var patientCommand = mapper.Map <CreatePatientCommand>(request);

            patientCommand.CreatedBy = Guid.Parse(User.Claims.FirstOrDefault(x => x.Type == "id").Value);

            var patientCreateResponse = await patientApi.SavePatient(patientCommand);

            var patientCreateContent = await patientCreateResponse.Content.DeserializeStringContent <string>();

            if (!patientCreateResponse.IsSuccessStatusCode)
            {
                return(BadRequest(patientCreateContent));
            }

            return(CreatedAtAction(nameof(GetPatientById), new { id = patientCreateContent }, patientCreateContent));
        }
        /// <summary>
        ///     Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void Handle(CreatePatientRequest request, SaveDtoResponse <PatientDto> response)
        {
            var patientFactory = new PatientFactory();
            var patient        = patientFactory.Create(request.PatientDto.OrganizationKey, request.PatientDto.Name, request.PatientDto.DateOfBirth, _lookupProvider.Find <Gender> (request.PatientDto.Gender.Code));

            if (patient != null)
            {
                if (request.PatientDto.Religion != null && !string.IsNullOrEmpty(request.PatientDto.Religion.Code))
                {
                    patient.ReviseReligion(_lookupProvider.Find <Religion> (request.PatientDto.Religion.Code));
                }
                if (request.PatientDto.Ethnicity != null && !string.IsNullOrEmpty(request.PatientDto.Ethnicity.Code))
                {
                    patient.ReviseEthnicity(_lookupProvider.Find <Ethnicity> (request.PatientDto.Ethnicity.Code));
                }

                var patientDto = Mapper.Map <Patient, PatientDto> (patient);

                response.DataTransferObject = patientDto;
            }
        }
        protected override void Handle(CreatePatientRequest request, SaveDtoResponse <PatientDto> response)
        {
            var organization   = _organizationRepository.GetByKey(UserContext.OrganizationKey);
            var patientFactory = _patientFactory;
            var patient        = patientFactory.Create(organization, request.PatientDto.Name,
                                                       request.PatientDto.DateOfBirth,
                                                       Lookup.Find <Gender> (request.PatientDto.Gender.Code));

            if (patient != null)
            {
                if (request.PatientDto.Religion != null)
                {
                    patient.ReviseReligion(Lookup.Find <Religion>(request.PatientDto.Religion.Code));
                }
                if (request.PatientDto.Ethnicity != null)
                {
                    patient.ReviseEthnicity(Lookup.Find <Ethnicity>(request.PatientDto.Ethnicity.Code));
                }

                var patientDto = Mapper.Map <Patient, PatientDto>(patient);

                response.DataTransferObject = patientDto;
            }
        }
 public async Task <PatientDto> CreateAsync(CreatePatientRequest patient)
 {
     return((await _httpService.HttpPostAsync <CreatePatientResponse>("patients", patient)).Patient);
 }
        public async Task <ActionResult> Post([FromBody] CreatePatientRequest request)
        {
            var response = await _patientService.Create(request);

            return(GetApiResponse(response));
        }