private Patient SavePatient(PatientSearchResultDto patientSearchResult, long agencyKey) { CheckPhoneAndAddressRequiredFields(patientSearchResult); var agency = _agencyRepository.GetByKey(agencyKey); var personName = new PersonName( patientSearchResult.PrefixName, patientSearchResult.FirstName, patientSearchResult.MiddleName, patientSearchResult.LastName, patientSearchResult.SuffixName); var patientGender = (patientSearchResult.PatientGender == null) ? null : _mappingHelper.MapLookupField <PatientGender> (patientSearchResult.PatientGender); var patientProfile = new PatientProfileBuilder() .WithBirthDate(patientSearchResult.BirthDate) .WithPatientGender(patientGender) .Build(); var patient = _patientFactory.CreatePatient(agency, personName, patientProfile); PopulatePatientAddresses(patient, patientSearchResult); PopulatePatientPhones(patient, patientSearchResult); _patientRepository.MakePersistent(patient); return(patient); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(CreateBillingOfficeRequest request) { var response = CreateTypedResponse(); var agency = _agencyRepository.GetByKey(request.AgencyKey); var staff = _staffRepository.GetByKey(request.StaffKey); var billingOffice = _billingOfficeFactory.CreateBillingOffice( agency, staff, Guid.NewGuid().ToString(), new BillingOfficeProfile(request.Name, null, null)); var billingOfficeDto = Mapper.Map <BillingOffice, BillingOfficeDto> (billingOffice); response.DataTransferObject = billingOfficeDto; return(response); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(CreateNewStaffRequest request) { var agencyKey = request.AgencyKey; var firstName = request.FirstName; var middleInitial = request.MiddleInitial; var lastName = request.LastName; var agency = _agencyRepository.GetByKey(agencyKey); if (agency == null) { throw new ArgumentException(string.Format("Agency Key: {0} was not found.", agencyKey)); } var staffDto = new StaffNameDto { FirstName = firstName, MiddleInitial = middleInitial, LastName = lastName }; var duplicateStaff = _staffRepository.FindDuplicateStaff(firstName, middleInitial, lastName); if (duplicateStaff != null) { staffDto.AddDataErrorInfo( string.IsNullOrEmpty(middleInitial) ? new DataErrorInfo(string.Format("Duplicate Staff {0} {1}. Please enter M.I.", firstName, lastName), ErrorLevel.Error) : new DataErrorInfo( string.Format("Cannot add Duplicate Staff {0} {1} {2}.", firstName, middleInitial, lastName), ErrorLevel.Error)); } else { var staff = _staffFactory.CreateStaff( agency, new StaffProfileBuilder().WithStaffName( new PersonNameBuilder().WithFirst(firstName).WithLast(lastName).WithMiddle(middleInitial))); staffDto = Mapper.Map <Staff, StaffNameDto> (staff); } var response = CreateTypedResponse(); response.StaffNameDto = staffDto; return(response); }
/// <summary> /// Creates the new. /// </summary> /// <param name="dto">The dto to create new for.</param> /// <returns>A <see cref="Rem.Domain.Clinical.ProgramModule.Program"/></returns> protected override Program CreateNew(ProgramDto dto) { Check.IsNotNull(dto.StartDate, "Start Date is required."); var agency = _agencyRepository.GetByKey(dto.AgencyKey); if (agency == null) { throw new InvalidOperationException("Agency does not exist"); } var ageGroup = _mappingHelper.MapLookupField <AgeGroup> (dto.AgeGroup); var genderSpecification = _mappingHelper.MapLookupField <GenderSpecification> (dto.GenderSpecification); var treatmentApproach = _mappingHelper.MapLookupField <TreatmentApproach> (dto.TreatmentApproach); var programCategory = _mappingHelper.MapLookupField <ProgramCategory> (dto.ProgramCategory); var programCharacteristics = new ProgramCharacteristics(ageGroup, genderSpecification, treatmentApproach, programCategory); var entity = _programFactory.CreateProgram(agency, dto.Name, dto.StartDate.Value, programCharacteristics); return(entity); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(CreateNewLocationRequest request) { var agencyKey = request.AgencyKey; var locationName = request.LocationName; var locationProfile = new LocationProfileBuilder().WithLocationName(new LocationNameBuilder().WithName(locationName)); var agency = _agencyRepository.GetByKey(agencyKey); if (agency == null) { throw new ArgumentException(string.Format("Agency Key: {0} was not found.", agencyKey)); } var location = _locationFactory.CreateLocation(agency, locationProfile); var locationDto = Mapper.Map <Location, LocationDisplayNameDto> (location); var response = CreateTypedResponse(); response.LocationDisplayNameDto = locationDto; return(response); }