コード例 #1
0
        public ActionResult <PatientMedications> AssignMedication([FromBody] PatientMedications p_med)
        {
            _repository.AssociateMedication(p_med);
            _repository.SaveChanges();

            return(Created("https://cotecapi.com/medications", p_med));
        }
コード例 #2
0
ファイル: Patient.cs プロジェクト: MSH/PViMS-2
        public PatientMedication AddMedication(Concept concept, DateTime startDate, DateTime?endDate, string dose, string doseFrequency, string doseUnit, Product product, string medicationSource)
        {
            if (DateOfBirth.HasValue)
            {
                if (startDate.Date < DateOfBirth.Value.Date)
                {
                    throw new DomainException("Start Date should be after patient Date Of Birth");
                }
            }

            if (DateOfBirth.HasValue && endDate.HasValue)
            {
                if (endDate.Value.Date < DateOfBirth.Value.Date)
                {
                    throw new DomainException("End Date should be after Date Of Birth");
                }
            }

            if (CheckMedicationStartDateAgainstStartDateWithNoEndDate(concept.Id, startDate, 0))
            {
                throw new DomainException("Duplication of medication. Please check start and end dates");
            }
            else
            {
                if (CheckMedicationStartDateWithinRange(concept.Id, startDate, 0))
                {
                    throw new DomainException("Duplication of medication. Please check start and end dates");
                }
                else
                {
                    if (endDate.HasValue)
                    {
                        if (CheckMedicationStartDateWithNoEndDateBeforeStart(concept.Id, startDate, 0))
                        {
                            throw new DomainException("Duplication of medication. Please check start and end dates");
                        }
                    }
                }
            }

            if (endDate.HasValue)
            {
                if (CheckMedicationEndDateAgainstStartDateWithNoEndDate(concept.Id, endDate.Value, 0))
                {
                    throw new DomainException("Duplication of medication. Please check start and end dates");
                }
                else
                {
                    if (CheckMedicationEndDateWithinRange(concept.Id, endDate.Value, 0))
                    {
                        throw new DomainException("Duplication of medication. Please check start and end dates");
                    }
                }
            }

            var newPatientMedication = new PatientMedication(concept, startDate, endDate, dose, doseFrequency, doseUnit, product, medicationSource);

            PatientMedications.Add(newPatientMedication);
            return(newPatientMedication);
        }
コード例 #3
0
ファイル: Patient.cs プロジェクト: MSH/PViMS-2
        public void ArchiveMedication(int patientMedicationId, string reason, User user)
        {
            var patientMedication = PatientMedications.SingleOrDefault(t => t.Id == patientMedicationId);

            if (patientMedication == null)
            {
                throw new KeyNotFoundException($"Unable to locate medication {patientMedicationId} for patient {Id}");
            }

            patientMedication.Archive(user, reason);
        }
コード例 #4
0
ファイル: Patient.cs プロジェクト: MSH/PViMS-2
 private Boolean CheckMedicationStartDateWithNoEndDateBeforeStart(int conceptId, DateTime startDate, long patientMedicationId)
 {
     if (patientMedicationId > 0)
     {
         return(PatientMedications
                .OrderBy(pc => pc.StartDate)
                .Where(pc => pc.Id != patientMedicationId &&
                       pc.Concept?.Id == conceptId &&
                       startDate < pc.StartDate &&
                       pc.Archived == false)
                .Any());
     }
     else
     {
         return(PatientMedications
                .OrderBy(pc => pc.StartDate)
                .Where(pc => pc.Concept?.Id == conceptId &&
                       startDate < pc.StartDate &&
                       pc.Archived == false)
                .Any());
     }
 }
コード例 #5
0
        public async Task <ActionResult <PatientViewModel> > PostPatient(PatientViewModel patient)
        {
            var newPatient = patient.ConvertToPatient();

            _context.Patients.Add(newPatient);
            await _context.SaveChangesAsync();

            newPatient.PatientAilments    = new List <PatientAilments>();
            newPatient.PatientMedications = new List <PatientMedications>();

            foreach (var ailment in patient.Ailments)
            {
                var Ailment = await _context.Ailments.FirstOrDefaultAsync(a => a.Id == ailment.Id);

                var patientAilment = new PatientAilments()
                {
                    Patient = newPatient, PatientId = newPatient.PatientId, Ailment = Ailment, AilmentId = Ailment.Id
                };
                newPatient.PatientAilments.Add(patientAilment);
            }

            foreach (var medication in patient.Medications)
            {
                var Medication = await _context.Medications.FirstOrDefaultAsync(m => m.Id == medication.Id);

                var patientMedication = new PatientMedications()
                {
                    Patient = newPatient, PatientId = newPatient.PatientId, Medication = Medication, MedicationId = Medication.Id
                };
                newPatient.PatientMedications.Add(patientMedication);
            }

            _context.Patients.Update(newPatient);
            await _context.SaveChangesAsync();

            return(new PatientViewModel(newPatient));
            //CreatedAtAction("GetPatient", new { id = patient.PatientId }, patient);
        }
コード例 #6
0
ファイル: Patient.cs プロジェクト: MSH/PViMS-2
 private Boolean CheckMedicationEndDateWithinRange(int conceptId, DateTime endDate, long patientMedicationId)
 {
     if (patientMedicationId > 0)
     {
         return(PatientMedications
                .OrderBy(pc => pc.StartDate)
                .Where(pc => pc.Id != patientMedicationId &&
                       pc.Concept?.Id == conceptId &&
                       endDate >= pc.StartDate &&
                       endDate <= pc.EndDate &&
                       pc.Archived == false)
                .Any());
     }
     else
     {
         return(PatientMedications
                .OrderBy(pc => pc.StartDate)
                .Where(pc => pc.Concept?.Id == conceptId &&
                       endDate >= pc.StartDate &&
                       endDate <= pc.EndDate &&
                       pc.Archived == false)
                .Any());
     }
 }
コード例 #7
0
        /*--------------------------------
         *      ENTITY MEDICATIONS
         *--------------------------------*/

        /// <summary>
        /// Assign a medication to a patient, given the patient's Dni.
        /// </summary>
        /// <param name="patientMedication">new patient medication.</param>
        public void AssociateMedication(PatientMedications patientMedication)
        {
            _context.PatientMedications.Add(patientMedication);
        }
コード例 #8
0
        public bool HasClinicalData()
        {
            var hasData = false;

            if (PatientClinicalEvents.Count() > 0 || PatientConditions.Count() > 0 || PatientLabTests.Count() > 0 || PatientMedications.Count() > 0 || Encounters.Count() > 0)
            {
                hasData = true;
            }
            ;

            return(hasData);
        }
コード例 #9
0
ファイル: Patient.cs プロジェクト: MSH/PViMS-2
        public void ChangeMedicationDetails(int patientMedicationId, DateTime startDate, DateTime?endDate, string dose, string doseFrequency, string doseUnit)
        {
            var patientMedication = PatientMedications.SingleOrDefault(t => t.Id == patientMedicationId);

            if (patientMedication == null)
            {
                throw new KeyNotFoundException($"Unable to locate medication {patientMedicationId} on patient {Id}");
            }

            if (DateOfBirth.HasValue)
            {
                if (startDate.Date < DateOfBirth.Value.Date)
                {
                    throw new DomainException("Start Date should be after patient Date Of Birth");
                }
            }

            if (DateOfBirth.HasValue && endDate.HasValue)
            {
                if (endDate.Value.Date < DateOfBirth.Value.Date)
                {
                    throw new DomainException("End Date should be after Date Of Birth");
                }
            }

            if (CheckMedicationStartDateAgainstStartDateWithNoEndDate(patientMedication.Concept.Id, startDate, patientMedicationId))
            {
                throw new DomainException("Duplication of medication. Please check start and end dates");
            }
            else
            {
                if (CheckMedicationStartDateWithinRange(patientMedication.Concept.Id, startDate, patientMedicationId))
                {
                    throw new DomainException("Duplication of medication. Please check start and end dates");
                }
                else
                {
                    if (endDate.HasValue)
                    {
                        if (CheckMedicationStartDateWithNoEndDateBeforeStart(patientMedication.Concept.Id, startDate, patientMedicationId))
                        {
                            throw new DomainException("Duplication of medication. Please check start and end dates");
                        }
                    }
                }
            }

            if (endDate.HasValue)
            {
                if (CheckMedicationEndDateAgainstStartDateWithNoEndDate(patientMedication.Concept.Id, endDate.Value, patientMedicationId))
                {
                    throw new DomainException("Duplication of medication. Please check start and end dates");
                }
                else
                {
                    if (CheckMedicationEndDateWithinRange(patientMedication.Concept.Id, endDate.Value, patientMedicationId))
                    {
                        throw new DomainException("Duplication of medication. Please check start and end dates");
                    }
                }
            }

            patientMedication.ChangeDetails(startDate, endDate, dose, doseFrequency, doseUnit);
        }