コード例 #1
0
        /// <summary>
        /// Add a new patient to the repository
        /// </summary>
        /// <param name="patientDetail">The details of the patient to add</param>
        public async Task <int> AddPatientAsync(PatientDetailForCreation patientDetail)
        {
            var facility = _facilityRepository.Get(f => f.FacilityName == patientDetail.CurrentFacilityName);

            if (facility == null)
            {
                throw new ArgumentException(nameof(patientDetail.CurrentFacilityName));
            }
            var patientStatus = _patientStatusRepository.Get(f => f.Description == "Active");

            var newPatient = new Patient
            {
                FirstName   = patientDetail.FirstName,
                MiddleName  = patientDetail.MiddleName,
                Surname     = patientDetail.Surname,
                DateOfBirth = patientDetail.DateOfBirth,
            };

            newPatient.ChangePatientFacility(facility);
            newPatient.SetPatientStatus(patientStatus);

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

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

            AddClinicalEvents(newPatient, patientDetail.ClinicalEvents);

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

            if (patientDetail.CohortGroupId > 0)
            {
                AddCohortEnrollment(newPatient, patientDetail);
            }

            await _patientRepository.SaveAsync(newPatient);

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

            return(newPatient.Id);
        }
コード例 #2
0
        /// <summary>
        /// Enrol patient into cohort
        /// </summary>
        private void AddCohortEnrollment(Patient patient, PatientDetailForCreation patientDetail)
        {
            var cohortGroup = _cohortGroupRepository.Get(cg => cg.Id == patientDetail.CohortGroupId);
            var enrolment   = new CohortGroupEnrolment
            {
                Patient     = patient,
                EnroledDate = Convert.ToDateTime(patientDetail.EnroledDate),
                CohortGroup = cohortGroup
            };

            patient.CohortEnrolments.Add(enrolment);
        }
コード例 #3
0
ファイル: FormHandler.cs プロジェクト: MSH/PViMS-2
        private void PreparePatientDetailsFromFormA()
        {
            _patientDetailForCreation = new PatientDetailForCreation();
            _patientDetailForCreation.CustomAttributes = _modelExtensionBuilder.BuildModelExtension <Patient>();

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

            // Prepare patient attributes
            _patientDetailForCreation.SetAttributeValue("Medical Record Number", GetAttributeValueFromObject(1, "asmNumber"));
            _patientDetailForCreation.SetAttributeValue("Gender", TransformToGender(GetAttributeValueFromObject(1, "gender")));
            _patientDetailForCreation.SetAttributeValue("Address", GetAttributeValueFromObject(1, "address"));
            _patientDetailForCreation.SetAttributeValue("Patient Contact Number", GetAttributeValueFromObject(1, "contactNumber"));
            _patientDetailForCreation.SetAttributeValue("Patient Identity Number", GetAttributeValueFromObject(1, "patientIdentityNumber"));

            // Clinical
            _patientDetailForCreation.Conditions.AddRange(PrepareConditionDetail(0));
            _patientDetailForCreation.LabTests.AddRange(PrepareLabTestDetail(1));
            _patientDetailForCreation.Medications.AddRange(PrepareMedicationDetail());

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

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

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

            if (!_patientDetailForCreation.IsValid())
            {
                _patientDetailForCreation.InvalidAttributes.ForEach(element => _validationErrors.Add(element));
            }
        }
コード例 #4
0
        private async Task <PatientDetailForCreation> PreparePatientDetailAsync(AddPatientCommand message)
        {
            var patientDetail = new PatientDetailForCreation(message.FirstName, message.LastName, message.MiddleName, message.FacilityName, string.Empty, message.DateOfBirth, message.CohortGroupId, message.EnroledDate, message.EncounterTypeId, message.PriorityId, message.EncounterDate);

            patientDetail.CustomAttributes = _modelExtensionBuilder.BuildModelExtension <Patient>();

            // Update patient custom attributes from source
            foreach (var newAttribute in message.Attributes)
            {
                var customAttribute = await _customAttributeRepository.GetAsync(ca => ca.Id == newAttribute.Key);

                if (customAttribute == null)
                {
                    throw new KeyNotFoundException($"Unable to locate custom attribute {newAttribute.Key}");
                }

                var attributeDetail = patientDetail.CustomAttributes.SingleOrDefault(ca => ca.AttributeKey == customAttribute.AttributeKey);

                if (attributeDetail == null)
                {
                    throw new KeyNotFoundException($"Unable to locate custom attribute on patient {newAttribute.Key}");
                }

                attributeDetail.Value = newAttribute.Value;
            }

            // Prepare primary condition
            var sourceTermFromRepo = await _terminologyMeddraRepository.GetAsync(tm => tm.Id == message.MeddraTermId);

            var conditionDetail = new ConditionDetail()
            {
                CustomAttributes = _modelExtensionBuilder.BuildModelExtension <PatientCondition>(),
                MeddraTermId     = sourceTermFromRepo.Id,
                ConditionSource  = sourceTermFromRepo.MedDraTerm,
                OnsetDate        = message.StartDate,
                OutcomeDate      = message.OutcomeDate,
                Comments         = message.Comments,
                CaseNumber       = message.CaseNumber
            };

            patientDetail.Conditions.Add(conditionDetail);

            return(patientDetail);
        }
コード例 #5
0
ファイル: FormHandler.cs プロジェクト: MSH/PViMS-2
        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;
        }