Example #1
0
        private void PreparePatientDetailsFromFormC()
        {
            var identifier_asm = GetAttributeValueFromObject(1, "asmNumber");

            List <CustomAttributeParameter> parameters = new List <CustomAttributeParameter>();

            parameters.Add(new CustomAttributeParameter()
            {
                AttributeKey = "Medical Record Number", AttributeValue = identifier_asm
            });

            var patientFromRepo = _patientService.GetPatientUsingAttributes(parameters);

            if (patientFromRepo == null)
            {
                throw new Exception($"Unable to locate patient record for {identifier_asm}");
            }
            IExtendable patientExtended = patientFromRepo;

            _patientDetailForUpdate = new PatientDetailForUpdate();
            _patientDetailForUpdate.CustomAttributes = _modelExtensionBuilder.BuildModelExtension(patientExtended);

            // Attachments
            _patientDetailForUpdate.Attachments.Add(new AttachmentDetail()
            {
                Description = _formForCreation.FormIdentifier,
                ImageSource = _formForCreation.Attachment
            });

            if (_formForCreation.HasSecondAttachment)
            {
                _patientDetailForUpdate.Attachments.Add(new AttachmentDetail()
                {
                    Description = _formForCreation.FormIdentifier,
                    ImageSource = _formForCreation.Attachment_2
                });
            }

            // Encounter
            _patientDetailForUpdate.EncounterTypeId = 3;
            _patientDetailForUpdate.EncounterDate   = String.IsNullOrWhiteSpace(GetAttributeValueFromObject(4, "currentDate")) ? DateTime.Today : Convert.ToDateTime(GetAttributeValueFromObject(4, "currentDate"));
            _patientDetailForUpdate.PriorityId      = 1;

            if (!_patientDetailForUpdate.IsValid())
            {
                _patientDetailForUpdate.InvalidAttributes.ForEach(element => _validationErrors.Add(element));
            }
        }
Example #2
0
        public void SetForm(FormForCreationDto formForCreation)
        {
            _formForCreation = formForCreation;
            var formControlValues = formForCreation.FormValues.Select(fv => fv.FormControlValue).ToList();

            foreach (var formValue in formControlValues)
            {
                if (formValue.StartsWith("["))
                {
                    // Handle array
                    _formArrayValues.Add(JsonConvert.DeserializeObject <Dictionary <string, string>[]>(formValue));
                }
                else
                {
                    // Handle object
                    _formValues.Add(JsonConvert.DeserializeObject <Dictionary <string, string> >(formValue));
                }
            }

            _patientDetailForCreation = null;
            _patientDetailForUpdate   = null;
        }
Example #3
0
        private void PreparePatientDetailsFromFormB()
        {
            var identifier_asm = GetAttributeValueFromObject(1, "asmNumber");

            List <CustomAttributeParameter> parameters = new List <CustomAttributeParameter>();

            parameters.Add(new CustomAttributeParameter()
            {
                AttributeKey = "Medical Record Number", AttributeValue = identifier_asm
            });

            var patientFromRepo = _patientService.GetPatientUsingAttributes(parameters);

            if (patientFromRepo == null)
            {
                throw new Exception($"Unable to locate patient record for {identifier_asm}");
            }
            IExtendable patientExtended = patientFromRepo;

            _patientDetailForUpdate = new PatientDetailForUpdate();
            _patientDetailForUpdate.CustomAttributes = _modelExtensionBuilder.BuildModelExtension(patientExtended);

            // Prepare patient first class
            _patientDetailForUpdate.FirstName   = GetAttributeValueFromObject(1, "patientFirstName");
            _patientDetailForUpdate.Surname     = GetAttributeValueFromObject(1, "patientLastName");
            _patientDetailForUpdate.DateOfBirth = String.IsNullOrWhiteSpace(GetAttributeValueFromObject(1, "birthDate")) ? (DateTime?)null : Convert.ToDateTime(GetAttributeValueFromObject(1, "birthDate"));

            // Prepare patient attributes
            _patientDetailForUpdate.SetAttributeValue("Medical Record Number", GetAttributeValueFromObject(1, "asmNumber"));
            if (!String.IsNullOrWhiteSpace(GetAttributeValueFromObject(1, "patientIdentityNumber")))
            {
                _patientDetailForUpdate.SetAttributeValue("Patient Identity Number", GetAttributeValueFromObject(1, "patientIdentityNumber"));
            }
            if (!String.IsNullOrWhiteSpace(GetAttributeValueFromObject(1, "patientIdentityNumber")))
            {
                _patientDetailForUpdate.SetAttributeValue("Patient Identity Number", GetAttributeValueFromObject(1, "patientIdentityNumber"));
            }
            if (TransformToGender(GetAttributeValueFromObject(1, "gender")) != "0")
            {
                _patientDetailForUpdate.SetAttributeValue("Gender", TransformToGender(GetAttributeValueFromObject(1, "gender")));
            }

            // Clinical
            _patientDetailForUpdate.LabTests.AddRange(PrepareLabTestDetail(3));
            _patientDetailForUpdate.ClinicalEvents.AddRange(PrepareClinicalEventDetail(1));

            // Attachments
            _patientDetailForUpdate.Attachments.Add(new AttachmentDetail()
            {
                Description = _formForCreation.FormIdentifier,
                ImageSource = _formForCreation.Attachment
            });

            if (_formForCreation.HasSecondAttachment)
            {
                _patientDetailForUpdate.Attachments.Add(new AttachmentDetail()
                {
                    Description = _formForCreation.FormIdentifier,
                    ImageSource = _formForCreation.Attachment_2
                });
            }

            // Encounter
            _patientDetailForUpdate.EncounterTypeId = 2;
            _patientDetailForUpdate.EncounterDate   = String.IsNullOrWhiteSpace(GetAttributeValueFromObject(6, "currentDate")) ? DateTime.Today : Convert.ToDateTime(GetAttributeValueFromObject(6, "currentDate"));
            _patientDetailForUpdate.PriorityId      = 1;

            if (!_patientDetailForUpdate.IsValid())
            {
                _patientDetailForUpdate.InvalidAttributes.ForEach(element => _validationErrors.Add(element));
            }
        }
Example #4
0
        /// <summary>
        /// Update an existing patient in the repository
        /// </summary>
        /// <param name="patientDetail">The details of the patient to add</param>
        public async Task UpdatePatientAsync(PatientDetailForUpdate patientDetail)
        {
            var identifier_asm    = patientDetail.CustomAttributes.SingleOrDefault(ca => ca.AttributeKey == "Medical Record Number")?.Value.ToString();
            var identifierChanged = false;

            if (String.IsNullOrWhiteSpace(identifier_asm))
            {
                throw new Exception("Unable to locate patient in repo for update");
            }

            List <CustomAttributeParameter> parameters = new List <CustomAttributeParameter>();

            parameters.Add(new CustomAttributeParameter()
            {
                AttributeKey = "Medical Record Number", AttributeValue = identifier_asm
            });

            var patientFromRepo = GetPatientUsingAttributes(parameters);

            if (patientFromRepo == null)
            {
                throw new ArgumentException(nameof(patientDetail));
            }

            if (!String.IsNullOrWhiteSpace(patientDetail.FirstName))
            {
                if (!patientFromRepo.FirstName.Equals(patientDetail.FirstName, StringComparison.OrdinalIgnoreCase))
                {
                    identifierChanged = true;
                }
                patientFromRepo.FirstName = patientDetail.FirstName;
            }

            if (!String.IsNullOrWhiteSpace(patientDetail.Surname))
            {
                if (!patientFromRepo.Surname.Equals(patientDetail.Surname, StringComparison.OrdinalIgnoreCase))
                {
                    identifierChanged = true;
                }
                patientFromRepo.Surname = patientDetail.Surname;
            }

            if (!String.IsNullOrWhiteSpace(patientDetail.MiddleName))
            {
                patientFromRepo.MiddleName = patientDetail.MiddleName;
            }

            if (patientDetail.DateOfBirth.HasValue)
            {
                if (!patientFromRepo.DateOfBirth.Equals(patientDetail.DateOfBirth))
                {
                    identifierChanged = true;
                }
                patientFromRepo.DateOfBirth = patientDetail.DateOfBirth;
            }

            // Custom Property handling
            _typeExtensionHandler.UpdateExtendable(patientFromRepo, patientDetail.CustomAttributes, "Admin");

            // Clinical data
            AddConditions(patientFromRepo, patientDetail.Conditions);
            await AddLabTestsAsync(patientFromRepo, patientDetail.LabTests);
            await AddMedicationsAsync(patientFromRepo, patientDetail.Medications);

            AddClinicalEvents(patientFromRepo, patientDetail.ClinicalEvents);

            // Other data
            AddAttachments(patientFromRepo, patientDetail.Attachments);

            _patientRepository.Update(patientFromRepo);

            // Register encounter
            if (patientDetail.EncounterTypeId > 0)
            {
                await AddEncounterAsync(patientFromRepo, new EncounterDetail()
                {
                    EncounterDate   = patientDetail.EncounterDate,
                    EncounterTypeId = patientDetail.EncounterTypeId,
                    PatientId       = patientFromRepo.Id,
                    PriorityId      = patientDetail.PriorityId
                });
            }

            if (identifierChanged)
            {
                var userName     = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var userFromRepo = await _userRepository.GetAsync(u => u.UserName == userName);

                var auditLog = new AuditLog()
                {
                    AuditType  = AuditType.DataValidation,
                    User       = userFromRepo,
                    ActionDate = DateTime.Now,
                    Details    = $"Identifier (name or date of birth) changed for patient {identifier_asm}"
                };
                await _auditLogRepository.SaveAsync(auditLog);
            }
        }