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 request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void HandleRequest(CreateNewPatientRequest request, CreateNewPatientResponse response) { var session = SessionProvider.GetSession(); var agency = session.Load <Agency> (request.AgencyKey); var name = new PersonNameBuilder() .WithFirst(request.FirstName) .WithMiddle(request.MiddleName) .WithLast(request.LastName) .WithSuffix(request.Suffix == null ? null : request.Suffix.Name) .Build(); PatientGender patientGender = null; if (request.Gender != null) { patientGender = _mappingHelper.MapLookupField <PatientGender> (request.Gender); } var patientProfile = new PatientProfileBuilder() .WithPatientGender(patientGender) .WithBirthDate(request.BirthDate) .Build(); var patient = _patientFactory.CreatePatient(agency, name, patientProfile); if (Success) { response.PatientDto = Mapper.Map <Patient, PatientDto> (patient); } }