/// <summary> /// Convert a list of locations to a locationPath directly. /// </summary> /// <remarks>Object should ideally inherit from <see cref="ILocationPath"/>, but if it doesn't or can't. Then use this when you need location path.</remarks> /// <param name="locations">List of locations.</param> /// <returns>Location based locationPath.</returns> public static LocationPath ToLocationPath(this IEnumerable <Location> locations) { var document = new LocationPath(); document.UpdateLocationPath(locations); return(document); }
public async Task <ActionResult <PutPatientDetailsResponse> > UpdatePatientDetails(string examinationId, [FromBody][ExaminationValidationModelBinderContext("examinationId")] PutPatientDetailsRequest putPatientDetailsRequest) { if (!ModelState.IsValid) { return(BadRequestEnums(new PutPatientDetailsResponse())); } var examination = await _examinationRetrievalService.Handle(new ExaminationRetrievalQuery(examinationId, null)); if (examination == null) { return(NotFound(new PutPatientDetailsResponse())); } // Do they have update permission on the examination being updated if (!CanAsync(Permission.UpdateExamination, examination)) { return(Forbid()); } var patientDetails = Mapper.Map <PatientDetails>(putPatientDetailsRequest); var locations = (await _locationParentsService.Handle( new LocationParentsQuery(patientDetails.MedicalExaminerOfficeResponsible))).ToList(); var locationPath = new LocationPath(); locationPath.UpdateLocationPath(locations); // Do they have permission at this location to update the examination. I.e. they're changing the Medical Examiner Office. if (!CanAsync(Permission.UpdateExamination, locationPath)) { return(Forbid()); } var myUser = await CurrentUser(); var result = await _patientDetailsUpdateService.Handle(new PatientDetailsUpdateQuery( examinationId, patientDetails, myUser, locations)); var patientCard = Mapper.Map <PatientCardItem>(result); return(Ok(new PutPatientDetailsResponse { Header = patientCard })); }