public override CreatePatientEventRes Execute(CreatePatientEventReq pServiceRequest)
        {
            CreatePatientEventRes wRes = new CreatePatientEventRes();

            int id = MedicalEventDAC.CreateMedicalEvent(pServiceRequest.BusinessData, Guid.Parse(pServiceRequest.ContextInformation.UserId));

            if (pServiceRequest.BusinessData.PatientMedicaments != null)
            {
                foreach (PatientMedicament_ViewBE patientMedicament in pServiceRequest.BusinessData.PatientMedicaments)
                {
                    if (patientMedicament.EntityState != Fwk.Bases.EntityState.Unchanged)
                    {
                        if (patientMedicament.PatientMedicamentId_Parent.HasValue)
                        {
                            PatientsDAC.DisablePatientMedicaments(patientMedicament.PatientMedicamentId_Parent.Value, Guid.Parse(pServiceRequest.ContextInformation.UserId), BE.Enums.MedicamentStatus.Finalizado);
                        }

                        patientMedicament.MedicalEventId = id;
                        PatientsDAC.AddPatientMedicaments(patientMedicament, Guid.Parse(pServiceRequest.ContextInformation.UserId));
                    }
                }
            }
            wRes.BusinessData.EventId = id;
            return(wRes);
        }
예제 #2
0
        public override RetrivePatientMedicamentsRes Execute(RetrivePatientMedicamentsReq pServiceRequest)
        {
            RetrivePatientMedicamentsRes wRes = new RetrivePatientMedicamentsRes();
            PatientMedicament_ViewList   wPatientMedicament_ViewBE = new PatientMedicament_ViewList();

            if (pServiceRequest.BusinessData.RetriveHistory)
            {
                wRes.BusinessData = PatientsDAC.RetrivePatientMedicamentsAlls(pServiceRequest.BusinessData.PatientId);
                return(wRes);
            }
            else
            {
                if (pServiceRequest.BusinessData.MedicalEventId.HasValue)
                {
                    wPatientMedicament_ViewBE = PatientsDAC.RetrivePatientMedicaments(pServiceRequest.BusinessData.PatientId, pServiceRequest.BusinessData.MedicalEventId.Value, true);
                }
                else
                {
                    wPatientMedicament_ViewBE = PatientsDAC.RetrivePatientMedicaments(pServiceRequest.BusinessData.PatientId);
                }
            }

            DateTime currentDate = Fwk.HelperFunctions.DateFunctions.GetStartDateTime(DateTime.Now);

            if (wPatientMedicament_ViewBE.Count != 0)
            {
                wRes.BusinessData = new PatientMedicament_ViewList();
            }

            //Realizar aqui actualizacion de medicacion NO permanente que sobrepaso dias resetados por el medico. Enabled = FALSE
            foreach (PatientMedicament_ViewBE item in wPatientMedicament_ViewBE)
            {
                ///Ignorar si la consulta es por id . Por que si viene el id del requetst es por que se esta creando en este momento
                if (!(pServiceRequest.BusinessData.MedicalEventId.HasValue && item.MedicalEventId.Equals(pServiceRequest.BusinessData.MedicalEventId)))
                {
                    if (currentDate > Fwk.HelperFunctions.DateFunctions.GetStartDateTime(item.CreatedDate).AddDays(item.DaysCount) && !item.Status.Equals((int)MedicamentStatus.Permanente))
                    {
                        PatientsDAC.DisablePatientMedicaments(item.PatientMedicamentId, Guid.Parse(pServiceRequest.ContextInformation.UserId), MedicamentStatus.Finalizado);
                        //wRes.BusinessData.Remove(item);
                    }
                    else
                    {
                        wRes.BusinessData.Add(item);
                    }
                }
                else
                {
                    wRes.BusinessData.Add(item);
                }
            }

            return(wRes);
        }
        public override UpdatePatientEventRes Execute(UpdatePatientEventReq pServiceRequest)
        {
            UpdatePatientEventRes wRes = new UpdatePatientEventRes();

            MedicalEventDAC.UpdateMedicalEvent(pServiceRequest.BusinessData, Guid.Parse(pServiceRequest.ContextInformation.UserId));

            int currentMedicalEventId = pServiceRequest.BusinessData.MedicalEventId;



            if (pServiceRequest.BusinessData.MedicalEventDetailList != null)
            {
                foreach (MedicalEventDetailBE medicalEventDetail in pServiceRequest.BusinessData.MedicalEventDetailList)
                {
                    medicalEventDetail.MedicalEventId = currentMedicalEventId;


                    if (medicalEventDetail.EntityState == EntityState.Added)
                    {
                        MedicalEventDAC.Insert_MedicalEventDetail(medicalEventDetail, Guid.Parse(pServiceRequest.ContextInformation.UserId));

                        if (medicalEventDetail.DetailType.Equals(AlertTypeEnum.Diagnosis))
                        {
                            if (medicalEventDetail.RelevanceType.HasValue)
                            {
                                MedicalEventDAC.Create_MedicalEventAlert(currentMedicalEventId, medicalEventDetail.Description, (AlertTypeEnum)medicalEventDetail.DetailType, medicalEventDetail.Id);
                            }
                        }
                    }

                    //Si en medio de la atencion gravo y luego el profesional se arrepiente y decide quitar el medicamento este debe se eliminado fisicamente
                    if (medicalEventDetail.EntityState == EntityState.Deleted)
                    {
                        MedicalEventDAC.Remove_MedicalEventDetail(medicalEventDetail.Id);
                    }
                }
            }

            if (pServiceRequest.BusinessData.PatientMedicaments != null)
            {
                //Selecciono medicamentos generados en otros eventos medicos
                var otherMedicaments = pServiceRequest.BusinessData.PatientMedicaments.Where(p =>
                                                                                             !p.MedicalEventId.Equals(currentMedicalEventId) &&
                                                                                             p.EntityState == EntityState.Changed);

                ///Si cambio algun medicamento de unevento anterior este es deshbilitado y se genera uno nuevo en el actual evento medico
                ///Logrando asi un hstorial
                foreach (PatientMedicament_ViewBE patientMedicament in otherMedicaments)
                {
                    PatientsDAC.DisablePatientMedicaments(patientMedicament.PatientMedicamentId,
                                                          Guid.Parse(pServiceRequest.ContextInformation.UserId),
                                                          BE.Enums.MedicamentStatus.Deshabilitado);
                }

                //|| p.PatientMedicamentId.Equals(-1)
                var currentMedicaments = pServiceRequest.BusinessData.PatientMedicaments.Where(p =>
                                                                                               p.MedicalEventId.Equals(currentMedicalEventId));

                foreach (PatientMedicament_ViewBE patientMedicament in currentMedicaments)
                {
                    patientMedicament.MedicalEventId = currentMedicalEventId;


                    if (patientMedicament.EntityState == EntityState.Added)
                    {
                        PatientsDAC.AddPatientMedicaments(patientMedicament, Guid.Parse(pServiceRequest.ContextInformation.UserId));
                    }

                    //Si modifique del mismo event Id (Esto se da por que el medico desidio guardar y luego modifico el evento si cerrar pantall
                    // y nuevamente preciona gurdar )
                    if (patientMedicament.EntityState == EntityState.Changed)
                    {
                        PatientsDAC.UpdatePatientMedicaments(patientMedicament, Guid.Parse(pServiceRequest.ContextInformation.UserId));
                    }

                    //Si en medio de la atencion gravo y luego el profesional se arrepiente y decide quitar el medicamento este debe se eliminado fisicamente
                    if (patientMedicament.EntityState == EntityState.Deleted)
                    {
                        PatientsDAC.RemovePatientMedicaments(patientMedicament.PatientMedicamentId);
                    }
                }
            }

            return(wRes);
        }