Пример #1
0
        private bool IsScaleUnique(TerminologyMedDra term, int scaleId)
        {
            int count = 0;

            count = UnitOfWork.Repository <MedDRAScale>().Queryable().Where(s => s.TerminologyMedDra.Id == term.Id && s.GradingScale.Id == scaleId).Count();
            return(count == 0);
        }
        public async Task <PatientClinicalEventIdentifierDto> Handle(AddClinicalEventToPatientCommand message, CancellationToken cancellationToken)
        {
            var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] {
                "PatientClinicalEvents.SourceTerminologyMedDra",
                "PatientMedications.Concept",
                "PatientFacilities.Facility"
            });

            if (patientFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate patient");
            }

            TerminologyMedDra sourceTermFromRepo = null;

            if (message.SourceTerminologyMedDraId.HasValue)
            {
                if (message.SourceTerminologyMedDraId > 0)
                {
                    sourceTermFromRepo = await _terminologyMeddraRepository.GetAsync(message.SourceTerminologyMedDraId);;
                    if (sourceTermFromRepo == null)
                    {
                        throw new KeyNotFoundException("Unable to locate terminology for MedDRA");
                    }
                }
            }

            var clinicalEventDetail = await PrepareClinicalEventDetailAsync(message.Attributes);

            if (!clinicalEventDetail.IsValid())
            {
                clinicalEventDetail.InvalidAttributes.ForEach(element => throw new DomainException(element));
            }

            var newPatientClinicalEvent = patientFromRepo.AddClinicalEvent(message.OnsetDate, message.ResolutionDate, sourceTermFromRepo, message.SourceDescription);

            _modelExtensionBuilder.UpdateExtendable(newPatientClinicalEvent, clinicalEventDetail.CustomAttributes, "Admin");

            _patientRepository.Update(patientFromRepo);

            // TODO Move to domain event
            await _workFlowService.CreateWorkFlowInstanceAsync(
                workFlowName : "New Active Surveilliance Report",
                contextGuid : newPatientClinicalEvent.PatientClinicalEventGuid,
                patientIdentifier : String.IsNullOrWhiteSpace(message.PatientIdentifier)?patientFromRepo.FullName : $"{patientFromRepo.FullName} ({message.PatientIdentifier})",
                sourceIdentifier : newPatientClinicalEvent.SourceTerminologyMedDra?.DisplayName ?? newPatientClinicalEvent.SourceDescription,
                facilityIdentifier : patientFromRepo.CurrentFacilityCode);

            await LinkMedicationsToClinicalEvent(patientFromRepo, newPatientClinicalEvent.OnsetDate, newPatientClinicalEvent.PatientClinicalEventGuid);

            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- Clinical Event {message.SourceDescription} created");

            var mappedPatientClinicalEvent = _mapper.Map <PatientClinicalEventIdentifierDto>(newPatientClinicalEvent);

            return(CreateLinks(mappedPatientClinicalEvent));
        }
Пример #3
0
        public void ChangeTerminology(TerminologyMedDra terminologyMedDra)
        {
            if (TerminologyMedDraId == terminologyMedDra.Id)
            {
                throw new DomainException("Report terminology not changed as it is the same");
            }

            TerminologyMedDra   = terminologyMedDra;
            TerminologyMedDraId = terminologyMedDra.Id;
        }
Пример #4
0
        public async Task <bool> Handle(ChangeClinicalEventDetailsCommand message, CancellationToken cancellationToken)
        {
            var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] {
                "PatientClinicalEvents.SourceTerminologyMedDra",
                "PatientConditions.TerminologyMedDra.ConditionMedDras.Condition"
            });

            if (patientFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate patient");
            }

            TerminologyMedDra sourceTermFromRepo = null;

            if (message.SourceTerminologyMedDraId.HasValue)
            {
                sourceTermFromRepo = await _terminologyMeddraRepository.GetAsync(message.SourceTerminologyMedDraId);;
                if (sourceTermFromRepo == null)
                {
                    throw new KeyNotFoundException("Unable to locate terminology for MedDRA");
                }
            }

            var clinicalEventToUpdate   = patientFromRepo.PatientClinicalEvents.Single(pce => pce.Id == message.PatientClinicalEventId);
            var clinicalEventAttributes = await PrepareClinicalEventAttributesWithNewValuesAsync(clinicalEventToUpdate, message.Attributes);

            var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            patientFromRepo.ChangeClinicalEventDetails(message.PatientClinicalEventId, message.OnsetDate, message.ResolutionDate, sourceTermFromRepo, message.SourceDescription);

            _modelExtensionBuilder.ValidateAndUpdateExtendable(clinicalEventToUpdate, clinicalEventAttributes, userName);

            _patientRepository.Update(patientFromRepo);

            // TODO Move to domain event
            await UpdateReportInstanceIdentifiers(patientFromRepo, clinicalEventToUpdate);

            _logger.LogInformation($"----- Clinical Event {message.PatientClinicalEventId} details updated");

            return(await _unitOfWork.CompleteAsync());
        }
Пример #5
0
        private void StoreBase(string termType, string fileName, int elementCount)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(fileName);

            string parentTermType = "";

            switch (termType)
            {
            case "HLGT":
                parentTermType = "SOC";
                break;

            case "HLT":
                parentTermType = "HLGT";
                break;

            case "PT":
                parentTermType = "HLT";
                break;

            case "LLT":
                parentTermType = "PT";
                break;

            default:
                break;
            }

            var    lineCount = 0;
            string line;

            string childCode;
            string term;
            string parentCode;

            while ((line = file.ReadLine()) != null)
            {
                lineCount += 1;
                string[] array = line.Split('$');

                childCode  = "";
                term       = "";
                parentCode = "";

                if (elementCount == 2)
                {
                    childCode = array[0];
                    term      = array[1];
                }
                if (elementCount == 3)
                {
                    childCode  = array[0];
                    term       = array[1];
                    parentCode = array[2];
                }

                // If we get here, write record to database
                TerminologyMedDra terminology = null;
                TerminologyMedDra parent      = null;

                PVIMSDbContext db = new PVIMSDbContext();

                if (String.IsNullOrEmpty(parentCode))
                {
                    terminology = db.TerminologyMedDras.SingleOrDefault(tm => tm.MedDraCode == childCode);
                }
                else
                {
                    terminology = db.TerminologyMedDras.SingleOrDefault(tm => tm.MedDraCode == childCode && tm.Parent.MedDraCode == parentCode);
                    parent      = db.TerminologyMedDras.SingleOrDefault(tm => tm.MedDraCode == parentCode && tm.MedDraTermType == parentTermType);
                }

                if (terminology == null)
                {
                    // Addition
                    _additions.Add(childCode);

                    terminology = new TerminologyMedDra()
                    {
                        MedDraCode     = childCode,
                        MedDraTerm     = term,
                        MedDraTermType = termType,
                        MedDraVersion  = _version,
                        Parent         = parent
                    };
                    db.TerminologyMedDras.Add(terminology);
                }
                else
                {
                    if (terminology.MedDraTermType.ToLower().Trim() == termType.ToLower().Trim())
                    {
                        if (terminology.MedDraTerm == term)
                        {
                            _refreshCount += 1;
                        }
                        else
                        {
                            _updates.Add(childCode);
                            terminology.MedDraTermType = termType;
                            terminology.MedDraTerm     = term;
                            terminology.MedDraVersion  = _version;
                            terminology.Parent         = parent;
                        }
                    }
                    else
                    {
                        _movements.Add(childCode);
                        terminology.MedDraTermType = termType;
                        terminology.MedDraTerm     = term;
                        terminology.MedDraVersion  = _version;
                        terminology.Parent         = parent;
                    }
                }
                db.SaveChanges();
                db = null;
            } // while ((line = file.ReadLine()) != null)

            file.Close();
            file = null;
        }
Пример #6
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string err = "<ul>";

            if (lstTermResult.SelectedIndex == -1)
            {
                err += "<li>Please select an adverse event...</li>";
            }

            if (err != "<ul>")
            {
                err += "</ul>";
                divError.Visible    = true;
                spnErrors.InnerHtml = err;
                return;
            }

            var id = Convert.ToInt32(lstTermResult.SelectedItem.Value);
            TerminologyMedDra sourceTerm = UnitOfWork.Repository <TerminologyMedDra>().Get(id);

            // Validation
            if (_formMode == FormMode.AddMode)
            {
                if (!IsScaleUnique(sourceTerm, Convert.ToInt32(ddlScale.Value)))
                {
                    err += "<li>Scale has already been added for this adverse event...</li>";
                }

                if (err != "<ul>")
                {
                    err += "</ul>";
                    divError.Visible    = true;
                    spnErrors.InnerHtml = err;
                    return;
                }

                if (_scale == null)
                {
                    id = Convert.ToInt32(ddlScale.Value);
                    var scale = UnitOfWork.Repository <SelectionDataItem>().Queryable().SingleOrDefault(s => s.Id == id);

                    _scale = new MedDRAScale {
                        TerminologyMedDra = sourceTerm, GradingScale = scale
                    };
                    UnitOfWork.Repository <MedDRAScale>().Save(_scale);

                    for (var i = 1; i < 6; i++)
                    {
                        var grading = new MedDRAGrading()
                        {
                            Scale = _scale, Grade = "Grade " + i.ToString(), Description = "** NOT DEFINED **"
                        };
                        UnitOfWork.Repository <MedDRAGrading>().Save(grading);
                    }
                }
            }

            var url = String.Format("ManageGradingEdit.aspx?id=" + _scale.Id.ToString());

            Response.Redirect(url);
        }