public PatientServiceUnitTest() { // Setup _patient = new Patient() { Id = Guid.NewGuid(), FirstName = "John", LastName = "Smith", LastFourOfSSN = "1234", DateOfBirth = DateTime.Now.AddDays(-7), }; _patientContact = new PatientContact() { Patient = _patient, PatientId = _patient.Id, PhoneNumber = "666-666-6666", }; _mockPatientDbService = new MockPatientDbService(); _mockPatientDbService.AddPatient(_patient); _mockPatientDbService.AddPatientContact(_patientContact); _patientController = new PatientController( new NullLogger <PatientController>(), _mockPatientDbService ); _patientController.ProblemDetailsFactory = new MockProblemDetailsFactory(); }
/// <summary> /// 新增患者 /// </summary> /// <param name="input">患者信息</param> /// <returns>是否成功</returns> public async Task <OutputBase> Add(AdminPatientDto input) { if (await _repository.GetPatientCotactByPhone(input.Phone) != null) { return(OutputBase.Fail("该手机号已经注册")); } var patient = new Patient { Brithdate = input.Brithdate, DialysisPatientId = 0,//默认 DoctorId = input.DoctorId == -1 ? null : input.DoctorId, HospitalId = input.HospitalId, PatientName = input.PatientName, PinyinCode = Utility.GetFirstPY(input.PatientName), Remark = input.Remark, Sex = input.Sex, UserStatus = input.UserStatus }; var patientId = _repository.Add(patient); var contact = new PatientContact { MobilePhone = input.Phone, Relationship = CommConstant.OneselfRelationship, ContatctName = input.PatientName, DialysisContactId = 0,//默认 HospitalId = input.HospitalId, PatientId = patientId }; _patientContactRepository.Add(contact); return(_unitWork.Commit() ? OutputBase.Success("新增成功") : OutputBase.Fail("新增失败")); }
public void TestCreatePatientContactInvalidPatient() { // Act Patient patient = new Patient() { Id = Guid.NewGuid(), FirstName = "Jacob", LastName = "Johnson", DateOfBirth = DateTime.Now, LastFourOfSSN = "1234", }; PatientContact patientContact = new PatientContact() { Patient = patient, PatientId = patient.Id, PhoneNumber = "666-666-6666", }; IActionResult result = _patientController.CreatePatientContact(patient.Id, patientContact); // Assert Assert.IsType <ObjectResult>(result); Assert.IsType <ProblemDetails>(((ObjectResult)result).Value); Assert.Equal(StatusCodes.Status404NotFound, ((ObjectResult)result).StatusCode); Assert.DoesNotContain(_mockPatientDbService.PatientContactList, pc => pc == patientContact); }
/// <summary> /// 更新患者 /// </summary> /// <param name="input">患者信息</param> /// <returns>是否成功</returns> public async Task <OutputBase> Update(AdminPatientDto input) { var patientContact = await _repository.GetPatientCotactById(input.Id); if (input.Phone != patientContact.MobilePhone && await _repository.GetPatientCotactByPhone(input.Phone) != null) { return(OutputBase.Fail("该手机号已经注册")); } var patient = new Patient { Id = input.Id, Brithdate = input.Brithdate, DoctorId = input.DoctorId == -1 ? null : input.DoctorId, HospitalId = input.HospitalId, PatientName = input.PatientName, PinyinCode = Utility.GetFirstPY(input.PatientName), Remark = input.Remark, Sex = input.Sex, UserStatus = input.UserStatus }; await _repository.UpdatePatient(patient); var contact = new PatientContact { MobilePhone = input.Phone, ContatctName = input.PatientName, //Password = input.Password, PatientId = input.Id }; await _patientContactRepository.Update(contact); return(_unitWork.Commit() ? OutputBase.Success("更新成功") : OutputBase.Fail("更新失败")); }
private bool MapProperties(PatientContact patientContact, PatientContactContactInformationDto patientContactDto) { var result = true; var phoneMapResult = new AggregateNodeCollectionMapper <PatientContactPhoneDto, PatientContact, PatientContactPhone> ( patientContactDto.PhoneNumbers, patientContact, patientContact.PhoneNumbers) .MapAddedItem( (dto, entity) => entity.AddContactPhone( dto.PhoneNumber, _mappingHelper.MapLookupField <PatientContactPhoneType> (dto.PatientContactPhoneType), dto.PhoneExtensionNumber, dto.ConfidentialIndicator)) .MapChangedItem(MapPhoneProperties) .MapRemovedItem((dto, entity, node) => entity.RemoveContactPhone(node)) .Map(); result &= phoneMapResult; patientContact.ReviseCityName(patientContactDto.CityName); patientContact.ReviseCountry(_mappingHelper.MapLookupField <Country> (patientContactDto.Country)); patientContact.ReviseCountyArea(_mappingHelper.MapLookupField <CountyArea> (patientContactDto.CountyArea)); patientContact.ReviseEmailAddress(patientContactDto.EmailAddress); patientContact.ReviseFirstStreetAddress(patientContactDto.FirstStreetAddress); patientContact.ReviseSecondStreetAddress(patientContactDto.SecondStreetAddress); patientContact.RevisePostalCode(patientContactDto.PostalCode); patientContact.ReviseStateProvince(_mappingHelper.MapLookupField <StateProvince> (patientContactDto.StateProvince)); return(result); }
public void TestUpdatePatientContactInvalidContact() { // Act Patient patient = new Patient() { Id = Guid.NewGuid(), FirstName = "Jack", LastName = "Johnson", DateOfBirth = DateTime.Now, LastFourOfSSN = "1234", }; PatientContactDTO patientContactDTO = new PatientContactDTO() { PhoneNumber = "111-111-1111", }; _mockPatientDbService.AddPatient(patient); IActionResult result = _patientController.UpdatePatientContact(patient.Id, patientContactDTO); // Assert PatientContact patientContact = _mockPatientDbService.PatientContactList.Find(p => p.PatientId == patient.Id); Assert.IsType <ObjectResult>(result); Assert.IsType <ProblemDetails>(((ObjectResult)result).Value); Assert.Equal(StatusCodes.Status404NotFound, ((ObjectResult)result).StatusCode); Assert.NotEqual(_patientContact, patientContact); }
public async Task <IActionResult> Initialize() { //initialize the MS Graph API client to connect to Graph var graphClient = GraphServiceClientFactory .GetAuthenticatedGraphClient(async() => { return(await _tokenAcquisition .GetAccessTokenForUserAsync(GraphConstants.Scopes)); }); //Get Data - see function below IEnumerable <Patients> sql = await GetDataFromDB(); foreach (Patients patient in sql) { try { //make a new MS Contact Object using the patient data from sql query Contact contact = new PatientContact().NewContact(patient); //send the Contact Object to Microsoft People await graphClient.Me.Contacts .Request() .AddAsync(contact); } catch (ServiceException ex) { return(RedirectToAction("Index") .WithError("Error With the Contact", ex.Error.Message)); } } return(RedirectToAction("Index", "Home")); }
public static void Initialize( IPatientDbService patientDbService, IHttpClientFactory httpClientFactory) { HttpClient httpClient; httpClient = httpClientFactory.CreateClient(); ICollection <Patient> patients = new List <Patient>(); ICollection <PatientContact> patientContacts = new List <PatientContact>(); JsonElement patientsElement = JsonDocument .Parse(GetRandomPatientData(httpClient).Result) .RootElement.GetProperty("results"); foreach (JsonElement patientElement in patientsElement.EnumerateArray()) { Patient patient = GetPatientFromJsonElement(patientElement); PatientContact patientContact = GetPatientContactFromJsonElement(patientElement, patient); patients.Add(patient); patientContacts.Add(patientContact); } patientDbService.AddPatientRange(patients.Cast <Patient>()); patientDbService.AddPatientContactRange(patientContacts.Cast <PatientContact>()); }
public IActionResult UpdatePatientContact( [GuidNotEmpty] Guid id, [FromBody] PatientContactDTO patientContactDTO) { Patient patient = null; PatientContact patientContact = null; patient = _patientDbService.FindPatient(id); if (patient == null) { return(ReturnProblem("Patient not found.", StatusCodes.Status404NotFound)); } patientContact = _patientDbService.FindPatientContact(id); if (patientContact == null) { return(ReturnProblem("Patient contact not found.", StatusCodes.Status404NotFound)); } patientContact.PatientId = id; patientContact.Patient = patient; patientContact.PhoneNumber = patientContactDTO.PhoneNumber; patientContact.EmailAddress = patientContactDTO.EmailAddress; _patientDbService.UpdatePatientContact(patientContact); return(NoContent()); }
public void TestCreatePatientContactValidContact() { // Act Patient patient = new Patient() { Id = Guid.NewGuid(), FirstName = _patient.FirstName, LastName = _patient.LastName, DateOfBirth = _patient.DateOfBirth, LastFourOfSSN = _patient.LastFourOfSSN, }; PatientContact patientContact = new PatientContact() { Patient = patient, PatientId = patient.Id, PhoneNumber = "666-666-6666", }; _mockPatientDbService.AddPatient(patient); IActionResult result = _patientController.CreatePatientContact(patient.Id, patientContact); // Assert Assert.IsType <NoContentResult>(result); Assert.Contains(_mockPatientDbService.PatientContactList, patientContact => patientContact.PatientId == patient.Id); }
/// <summary> /// 新增患者联系人 /// </summary> /// <param name="patientContact">患者联系人</param> /// <returns></returns> public void Add(PatientContact patientContact) { patientContact.Id = _idGenerator.CreateId(); patientContact.Password = CommConstant.InitialPassword; patientContact.AddTime = DateTime.Now; patientContact.UpdateTime = DateTime.Now; _context.PatientContact.Add(patientContact); }
/// <summary> /// 更新患者联系人 /// </summary> /// <param name="patientContact">患者联系人</param> /// <returns></returns> public async Task Update(PatientContact patientContact) { var contact = await _context.PatientContact.Where(i => i.PatientId == patientContact.PatientId).FirstOrDefaultAsync(); //contact.Password = patientContact.Password; contact.MobilePhone = patientContact.MobilePhone; contact.ContatctName = patientContact.ContatctName; contact.UpdateTime = DateTime.Now; }
public ActionResult DeleteConfirmed(int id) { PatientContact patientContact = _ehiDataRepository.GetPatient(id); patientContact.Status = true; _ehiDataRepository.Update(patientContact); _ehiDataRepository.SaveAsync(patientContact); return(RedirectToAction("Index")); }
public CommandDefinition GetRemovePatientContactCommand(PatientContact patientContact) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(@"DELETE FROM PatientContacts WHERE PatientId = "); stringBuilder.Append(patientContact.PatientId); stringBuilder.Append(@";"); return(new CommandDefinition(stringBuilder.ToString())); }
public CommandDefinition GetAddPatientContactCommand(PatientContact patientContact) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(@"INSERT INTO Patient (Id, FirstName, LastName, LastFourOfSSN, DateOfBirth, RowVersion) VALUES ("); stringBuilder.Append(patientContact); stringBuilder.Append(@");"); return(new CommandDefinition(stringBuilder.ToString())); }
public ActionResult Edit(PatientContact patientContact) { if (ModelState.IsValid) { _ehiDataRepository.Update(patientContact); _ehiDataRepository.SaveAsync(patientContact); return(RedirectToAction("Index")); } return(View(patientContact)); }
public void RemovePatientContact(PatientContact patientContact) { try { _patientDbContext.PatientContacts.Remove(patientContact); _patientDbContext.SaveChanges(); } catch (DbUpdateConcurrencyException e) { _logger.LogError(e, "A database concurrency error occured."); throw; } catch (Exception e) { _logger.LogError(e, "An error occured in the database service."); throw; } }
private void MapPhoneProperties( PatientContactPhoneDto patientContactPhoneDto, PatientContact patientContact, PatientContactPhone patientContactPhone) { var result = new PropertyMapper <PatientContactPhone> (patientContactPhone, patientContactPhoneDto) .MapProperty(p => p.PhoneNumber, patientContactPhoneDto.PhoneNumber) .MapProperty(p => p.PhoneExtensionNumber, patientContactPhoneDto.PhoneExtensionNumber) .MapProperty( p => p.PatientContactPhoneType, _mappingHelper.MapLookupField <PatientContactPhoneType> (patientContactPhoneDto.PatientContactPhoneType)) .MapProperty(p => p.ConfidentialIndicator, patientContactPhoneDto.ConfidentialIndicator) .Map(); _mappingResult &= result; }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PatientContact patientContact = _ehiDataRepository.GetPatient(id); if (patientContact == null) { return(HttpNotFound()); } return(View(patientContact)); }
public IActionResult GetPatientContact([GuidNotEmpty] Guid id) { PatientContact patientContact = null; if (_patientDbService.FindPatient(id) == null) { return(ReturnProblem("Patient not found.", StatusCodes.Status404NotFound)); } patientContact = _patientDbService.FindPatientContact(id); return(patientContact == null ? ReturnProblem("Patient contact not found.", StatusCodes.Status404NotFound) : Ok(patientContact)); }
//update contact public void UpdateContact(PatientContact contact) { var sql = "UPDATE Contacts set [PatientId] = @PatientId, [ParentName]=@ParentName, [LastName]=@LastName, [ChildName]=@ChildName, [Tel]=@Tel, [Tel2]=@Tel2, [Email]=@Email where [PatientId] = @PatientId"; this.db.Query <string>(sql, new { PatientId = contact.PatientId, ParentName = contact.ParentName, LastName = contact.LastName, ChildName = contact.ChildName, Tel = contact.Tel, Tel2 = contact.Tel2, Email = contact.Email }); }
public void CreatePatientContact_GivenValidArguments_CreatesContact() { using (var serviceLocatorFixture = new ServiceLocatorFixture()) { // Setup SetupServiceLocatorFixture(serviceLocatorFixture); var patientContactRepository = new Mock <IPatientContactRepository> (); var patientContactFactory = new PatientContactFactory(patientContactRepository.Object); var patient = new Mock <Patient> (); PatientContact patientContact = patientContactFactory.CreatePatientContact(patient.Object, "Fred", "Smith"); Assert.IsNotNull(patientContact); } }
public void TestCreatePatientContactAlreadyExists() { // Act PatientContact patientContact = new PatientContact() { Patient = _patient, PatientId = _patient.Id, PhoneNumber = "666-666-6666", }; IActionResult result = _patientController.CreatePatientContact(_patient.Id, patientContact); // Assert Assert.IsType <ObjectResult>(result); Assert.IsType <ProblemDetails>(((ObjectResult)result).Value); Assert.Equal(StatusCodes.Status400BadRequest, ((ObjectResult)result).StatusCode); }
//add patient contact public PatientContact AddContact(PatientContact contact) { var sql = "INSERT INTO Contacts ([PatientId], [ParentName], [LastName], [ChildName], [Tel], [Tel2], [Email]) VALUES (@PatientId, @ParentName, @ChildName, @LastName, @Tel, @Tel2, @Email)"; var getContact = "SELECT * From Contacts WHERE PatientId = @PatientId"; //delete all contacts var deleteContactSql = "DELETE * FROM Contacts WHERE PatientId = @PatientId"; this.db.Query <string>(deleteContactSql, new { PatientId = contact.PatientId }); this.db.Query <PatientContact>(sql, new { PatientId = contact.PatientId, ParentName = contact.ParentName, LastName = contact.LastName, ChildName = contact.ChildName, Tel = contact.Tel, Tel2 = contact.Tel2, Email = contact.Email }); return(this.db.Query <PatientContact>(getContact, new { PatientId = contact.PatientId }).SingleOrDefault()); }
public CommandDefinition GetUpdatePatientContactCommand(PatientContact patientContact) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(@"UPDATE PatientContacts SET "); stringBuilder.Append(@"PhoneNumber = "); stringBuilder.Append(patientContact.PhoneNumber); stringBuilder.Append(@", EmailAddress = "); stringBuilder.Append(patientContact.EmailAddress); stringBuilder.Append(@", RowVersion = "); stringBuilder.Append(patientContact.RowVersion); stringBuilder.Append(@" WHERE PatientId = "); stringBuilder.Append(patientContact.PatientId); stringBuilder.Append(@";"); return(new CommandDefinition(stringBuilder.ToString())); }
public void CreatePatientContact_GivenValidArguments_ContactIsEditable() { using (var serviceLocatorFixture = new ServiceLocatorFixture()) { // Setup SetupServiceLocatorFixture(serviceLocatorFixture); var patientContactRepository = new Mock <IPatientContactRepository>(); var patientContactFactory = new PatientContactFactory( patientContactRepository.Object); var patient = new Mock <Patient>(); PatientContact patientContact = patientContactFactory.CreatePatientContact( patient.Object, "Fred", "Smith"); patientContact.ReviseNote("some note"); } }
public IActionResult CreatePatientContact( [GuidNotEmpty] Guid id, [FromBody] PatientContact patientContact) { if (_patientDbService.FindPatient(id) == null) { return(ReturnProblem("Patient not found.", StatusCodes.Status404NotFound)); } if (_patientDbService.FindPatientContact(id) != null) { return(ReturnProblem("Patient contact already exists.", StatusCodes.Status400BadRequest)); } _patientDbService.AddPatientContact(patientContact); return(NoContent()); }
public void TestUpdatePatientContactValidContact() { // Act string phoneNumber = "111-111-1111"; PatientContactDTO patientContactDTO = new PatientContactDTO() { PhoneNumber = phoneNumber, }; IActionResult result = _patientController.UpdatePatientContact(_patient.Id, patientContactDTO); // Assert PatientContact patientContact = _mockPatientDbService.PatientContactList.Find(p => p.PatientId == _patient.Id); Assert.IsType <NoContentResult>(result); Assert.Equal(_patientContact, patientContact); }
public IActionResult DeletePatientContact([GuidNotEmpty] Guid id) { PatientContact patientContact = null; if (_patientDbService.FindPatient(id) == null) { return(ReturnProblem("Patient not found.", StatusCodes.Status404NotFound)); } patientContact = _patientDbService.FindPatientContact(id); if (patientContact == null) { return(ReturnProblem("Patient contact not found.", StatusCodes.Status404NotFound)); } _patientDbService.RemovePatientContact(patientContact); return(NoContent()); }
private bool MapProperties(PatientContact patientContact, PatientContactProfileDto patientContactDto) { patientContact.RenamePatientContact(patientContactDto.FirstName, patientContactDto.MiddleName, patientContactDto.LastName); patientContact.ReviseCanContactIndicator(patientContactDto.CanContactIndicator); patientContact.ReviseConsentExpirationDate(patientContactDto.ConsentExpirationDate); patientContact.ReviseConsentOnFileIndicator(patientContactDto.ConsentOnFileIndicator); patientContact.ReviseLegalAuthorizationType( _mappingHelper.MapLookupField <LegalAuthorizationType> (patientContactDto.LegalAuthorizationType)); patientContact.ReviseNote(patientContactDto.Note); patientContact.RevisePrimaryIndicator(patientContactDto.PrimaryIndicator); patientContact.RevisePatientContactRelationshipType(_mappingHelper.MapLookupField <PatientContactRelationshipType> (patientContactDto.PatientContactRelationshipType)); patientContact.ReviseSocialSecurityNumber(patientContactDto.SocialSecurityNumber); patientContact.ReviseEmergencyIndicator(patientContactDto.EmergencyIndicator); patientContact.ReviseDesignatedFollowUpIndicator(patientContactDto.DesignatedFollowUpIndicator); patientContact.ReviseGender(_mappingHelper.MapLookupField <Gender> (patientContactDto.Gender)); patientContact.ReviseBirthDate(patientContactDto.BirthDate); return(true); }