public async Task <Result <AddPatientResponse> > Handle(AddPatientCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { //var sqlPatient = "exec pr_OpenDecryptedSession;" + // "Insert Into Patient(ptn_pk,PersonId,PatientIndex,PatientType,FacilityId,Active,DateOfBirth,NationalId,DeleteFlag,CreatedBy,CreateDate,AuditData,DobPrecision)" + // $"Values(0, {request.PersonId}, {DateTime.Now.Year + '-' + request.PersonId}, 258, 13028, 1," + // $"'{request.DateOfBirth.ToString("yyyy-MM-dd")}', ENCRYPTBYKEY(KEY_GUID('Key_CTC'), '99999999'), 0, 1, GETDATE()," + // $"NULL, 1);" + // $"SELECT [Id],[ptn_pk],[PersonId],[PatientIndex],[PatientType],[FacilityId],[Active],[DateOfBirth]," + // $"[DobPrecision],CAST(DECRYPTBYKEY(NationalId) AS VARCHAR(50)) [NationalId],[DeleteFlag],[CreatedBy]," + // $"[CreateDate],[AuditData],[RegistrationDate] FROM [dbo].[Patient] WHERE Id = SCOPE_IDENTITY();" + // $"exec [dbo].[pr_CloseDecryptedSession];"; //var patientInsert = await _unitOfWork.Repository<Patient>().FromSql(sqlPatient); RegisterPersonService registerPersonService = new RegisterPersonService(_unitOfWork); var patient = await registerPersonService.AddPatient(request.PersonId, request.DateOfBirth, request.UserId); _unitOfWork.Dispose(); return(Result <AddPatientResponse> .Valid(new AddPatientResponse() { PatientId = patient.Id })); } } catch (Exception e) { return(Result <AddPatientResponse> .Invalid(e.Message)); } }
public async Task <IActionResult> Post([FromBody] AddPatientCommand addPatientCommand) { var response = await _mediator.Send(addPatientCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }
public async Task <ActionResult <PatientDto> > AddPatient([FromBody] PatientForCreationDto patientForCreation) { // add error handling var command = new AddPatientCommand(patientForCreation); var commandResponse = await _mediator.Send(command); var response = new Response <PatientDto>(commandResponse); return(CreatedAtRoute("GetPatient", new { commandResponse.PatientId }, response)); }
/** * \brief <b>Brief Description</b> - Execute <b><i>class method</i></b> - Entry point into the update patient menu * \details <b>Details</b> * * This takes in the scheduling, demographics and billing libraries * * \return <b>void</b> */ public void Execute(Scheduling scheduling, Demographics demographics, Billing billing) { // display the getting patient menu and get the requested patient Patient patient = GetPatient.Get(MenuCodes.PATIENTS, "Patients", 1); Patient updatedPatient = new Patient(); do { // check if the user canceled during the patient selection screen if (patient == null) { break; } // run the get patient menu but instead of adding it to the database it returns it AddPatientCommand addPatientCommand = new AddPatientCommand(); updatedPatient = addPatientCommand.Execute(patient.ShowInfo(), true, demographics); // check if the user canceled during data entry if (updatedPatient != null) { // update the patient information in the database updatedPatient.PatientID = patient.PatientID; demographics.UpdatePatient(updatedPatient); // display a success message Container.DisplayContent(new List <Pair <string, string> >() { { new Pair <string, string>("Patient updated successfully.", "") } }, 0, 1, MenuCodes.PATIENTS, "Patients", Description); // wait for user to read message and confirm Console.ReadKey(); break; } else { // display error message Container.DisplayContent(new List <Pair <string, string> >() { { new Pair <string, string>("An error was encountered while updating patient.", "") } }, 0, 1, MenuCodes.PATIENTS, "Patients", Description); // wait for user to read message and confirm Console.ReadKey(); break; } } while (patient != null && updatedPatient != null); }
public async Task AddPatientCommand_Adds_New_Patient_To_Db() { // Arrange var fakePatientOne = new FakePatientForCreationDto { }.Generate(); // Act var command = new AddPatientCommand(fakePatientOne); var patientReturned = await SendAsync(command); var patientCreated = await ExecuteDbContextAsync(db => db.Patients.SingleOrDefaultAsync()); // Assert patientReturned.Should().BeEquivalentTo(fakePatientOne, options => options.ExcludingMissingMembers()); patientCreated.Should().BeEquivalentTo(fakePatientOne, options => options.ExcludingMissingMembers()); }
public async Task <Result <AddPatientResponse> > Handle(AddPatientCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { RegisterPersonService registerPersonService = new RegisterPersonService(_unitOfWork); var registeredPerson = await registerPersonService.GetPerson(request.PersonId); var gender = await _unitOfWork.Repository <LookupItemView>().Get(x => x.ItemId == registeredPerson.Sex && x.MasterName == "Gender") .ToListAsync(); var maritalStatus = await registerPersonService.GetPersonMaritalStatus(request.PersonId); var maritalStatusName = "Single"; if (maritalStatus.Count > 0) { var matList = await _unitOfWork.Repository <LookupItemView>() .Get(x => x.ItemId == maritalStatus[0].MaritalStatusId && x.MasterName == "MaritalStatus").ToListAsync(); if (matList.Count > 0) { maritalStatusName = matList[0].ItemName; } } var mstResult = await registerPersonService.InsertIntoBlueCard(registeredPerson.FirstName, registeredPerson.LastName, registeredPerson.LastName, request.EnrollmentDate, maritalStatusName, "", "", gender[0].ItemName, "EXACT", registeredPerson.DateOfBirth, request.UserId, request.PosId); var patient = await registerPersonService.AddPatient(request.PersonId, request.UserId, mstResult[0].Ptn_Pk); return(Result <AddPatientResponse> .Valid(new AddPatientResponse() { PatientId = patient.Id })); } } catch (Exception e) { return(Result <AddPatientResponse> .Invalid(e.Message)); } }
public async Task <Result <AddPatientResponse> > Handle(AddPatientCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { RegisterPersonService registerPersonService = new RegisterPersonService(_unitOfWork); var patient = await registerPersonService.AddPatient(request.PersonId, request.UserId); return(Result <AddPatientResponse> .Valid(new AddPatientResponse() { PatientId = patient.Id })); } } catch (Exception e) { return(Result <AddPatientResponse> .Invalid(e.Message)); } }
public static AddPatientCommand ToAddPatientCommand(this JObject jObj) { var result = new AddPatientCommand(); var values = jObj.ToObject <Dictionary <string, object> >(); if (values.TryGet(MedikitApiConstants.PatientNames.Firstname, out string firstname)) { result.Firstname = firstname; } if (values.TryGet(MedikitApiConstants.PatientNames.Lastname, out string lastname)) { result.Lastname = lastname; } if (values.TryGet(MedikitApiConstants.PatientNames.Niss, out string niss)) { result.NationalIdentityNumber = niss; } if (values.TryGet(MedikitApiConstants.PatientNames.Gender, out GenderTypes gender)) { result.Gender = gender; } if (values.TryGet(MedikitApiConstants.PatientNames.BirthDate, out DateTime birthDate)) { result.BirthDate = birthDate; } if (values.TryGet(MedikitApiConstants.PatientNames.Base64EncodedImage, out string base64EncodedImage)) { result.Base64EncodedImage = base64EncodedImage; } if (values.TryGet(MedikitApiConstants.PatientNames.EidCardNumber, out string eidCardNumber)) { result.EidCardNumber = eidCardNumber; } if (values.TryGet(MedikitApiConstants.PatientNames.EidCardValidity, out DateTime eidCardValidity)) { result.EidCardValidity = eidCardValidity; } if (values.ContainsKey(MedikitApiConstants.PatientNames.Address)) { var address = new AddPatientCommand.Address(); var addressDic = ((JObject)values[MedikitApiConstants.PatientNames.Address]).ToObject <Dictionary <string, object> >(); if (addressDic.TryGet(MedikitApiConstants.AddressNames.Street, out string street)) { address.Street = street; } if (addressDic.TryGet(MedikitApiConstants.AddressNames.StreetNumber, out int streetNumber)) { address.StreetNumber = streetNumber; } if (addressDic.TryGet(MedikitApiConstants.AddressNames.Country, out string country)) { address.Country = country; } if (addressDic.TryGet(MedikitApiConstants.AddressNames.PostalCode, out string postalCode)) { address.PostalCode = postalCode; } if (addressDic.TryGetValue(MedikitApiConstants.AddressNames.Coordinates, out object coordinates)) { var coords = new List <double>(); var jArr = coordinates as JArray; if (jArr != null) { foreach (var r in jArr) { if (double.TryParse(r.ToString(), out double d)) { coords.Add(d); } } } address.Coordinates = coords; } result.PatientAddress = address; } if (values.ContainsKey(MedikitApiConstants.PatientNames.ContactInformations)) { var jArr = values[MedikitApiConstants.PatientNames.ContactInformations] as JArray; var contactInfos = new List <AddPatientCommand.ContactInformation>(); foreach (JObject o in jArr) { var ci = new AddPatientCommand.ContactInformation(); var dic = o.ToObject <Dictionary <string, object> >(); if (dic.TryGet(MedikitApiConstants.ContactInfoNames.Type, out ContactInformationTypes type)) { ci.Type = type; } if (dic.TryGet(MedikitApiConstants.ContactInfoNames.Value, out string value)) { ci.Value = value; } contactInfos.Add(ci); } result.ContactInformations = contactInfos; } return(result); }
public Task <string> AddPatient(AddPatientCommand command, CancellationToken token) { return(_mediator.Send(command, token)); }