public static List <DoctorViewModel> GetDoctorViewModelsFromPractice(CerebelloEntitiesAccessFilterWrapper db, Practice practice, DateTime localNow)
        {
            var usersThatAreDoctors = db.Users
                                      .Where(u => u.PracticeId == practice.Id)
                                      .Where(u => u.Doctor != null);

            var dataCollection = usersThatAreDoctors
                                 .Select(u => new
            {
                ViewModel = new DoctorViewModel()
                {
                    Id               = u.Id,
                    Name             = u.Person.FullName,
                    UrlIdentifier    = u.Doctor.UrlIdentifier,
                    CRM              = u.Doctor.CRM,
                    MedicalSpecialty = u.Doctor.MedicalSpecialtyName,
                },
                u.Doctor.MedicalEntityCode,
                u.Doctor.MedicalEntityJurisdiction,
                u.Doctor,
                u.Person.EmailGravatarHash,
            })
                                 .ToList();

            // Getting more doctor's informations:
            // Todo: this is going to become a problem in the future, because this info has no cache.
            // - next free time slot of each doctor;
            // - gravatar image.
            foreach (var eachItem in dataCollection)
            {
                if (!string.IsNullOrEmpty(eachItem.EmailGravatarHash))
                {
                    eachItem.ViewModel.ImageUrl = GravatarHelper.GetGravatarUrl(eachItem.EmailGravatarHash, GravatarHelper.Size.s16);
                }

                eachItem.ViewModel.MedicalEntity = string.Format(
                    string.IsNullOrEmpty(eachItem.MedicalEntityJurisdiction) ? "{0}" : "{0}-{1}",
                    eachItem.MedicalEntityCode,
                    eachItem.MedicalEntityJurisdiction);

                // It is only possible to determine the next available time if the schedule of the doctor is already configured.
                if (eachItem.Doctor.CFG_Schedule != null)
                {
                    var nextSlotInLocalTime = ScheduleController.FindNextFreeTimeInPracticeLocalTime(db, eachItem.Doctor, localNow);
                    eachItem.ViewModel.NextAvailableTime = nextSlotInLocalTime.Item1;
                }
            }

            var doctors = dataCollection.Select(item => item.ViewModel).ToList();

            return(doctors);
        }
Esempio n. 2
0
        public static void DeleteFileByMetadata(FileMetadata metadata, CerebelloEntitiesAccessFilterWrapper db, IBlobStorageManager storage)
        {
            // deleting dependent files
            var relatedFiles = db.FileMetadatas.Where(f => f.RelatedFileMetadataId == metadata.Id).ToList();

            foreach (var relatedFile in relatedFiles)
            {
                DeleteFileByMetadata(relatedFile, db, storage);
            }

            // deleting file metadata and storage entries
            storage.DeleteFileFromStorage(metadata.ContainerName, metadata.BlobName);
            db.FileMetadatas.DeleteObject(metadata);
        }
Esempio n. 3
0
        internal static string ExportDoctorXml(CerebelloEntitiesAccessFilterWrapper db, Practice practice, Doctor doctor)
        {
            var rg = new ReportData(db, practice);

            var doctorData = rg.GetReportDataSourceForXml(doctor, null);

            var stringBuilder = new StringBuilder();

            using (var writer = new StringWriter(stringBuilder))
            {
                var xs = new XmlSerializer(typeof(ReportData.XmlDoctorData));
                xs.Serialize(writer, doctorData);
            }

            return(stringBuilder.ToString());
        }
Esempio n. 4
0
        internal static byte[] ExportPatientsPdf(int?patientId, CerebelloEntitiesAccessFilterWrapper db, Practice practice, Doctor doctor)
        {
            var reportDataSource = new ReportData(db, practice).GetReportDataSourceForPdf(doctor, patientId);

            // the frame determines what is displayed in the header and in the
            // footer of your report pages
            var frame = new ReportFrame(
                new ReportFrameData()
            {
                Header1      = doctor.CFG_Documents.Header1,
                Header2      = doctor.CFG_Documents.Header2,
                FooterLeft1  = doctor.CFG_Documents.FooterLeft1,
                FooterLeft2  = doctor.CFG_Documents.FooterLeft2,
                FooterRight1 = doctor.CFG_Documents.FooterRight1,
                FooterRight2 = doctor.CFG_Documents.FooterRight2
            });

            // creates a new report
            var report = new Report(frame);

            foreach (var patient in reportDataSource.Patients)
            {
                // creates a data-context for each contact inside the report.
                // a data context is a section of your report that is bound to
                // a particular data object.
                using (var patientContext = report.AddDataContext(patient))
                {
                    // creates a title for the contact
                    patientContext.AddTitle(ReportTitleSize.H1, m => "Paciente: " + m.FullName);

                    // creates a Card to display the contacts details
                    var card = patientContext.AddCard();
                    card.AddField(m => m.FullName, true);
                    card.AddField(m => m.Gender);
                    card.AddField(m => m.DateOfBirth);
                    card.AddField(m => m.Profissao);
                    card.AddField(m => m.MaritalStatus);
                    card.AddField(m => m.PhoneLand);
                    card.AddField(m => m.PhoneCell);
                    card.AddField(m => m.Email, true);
                    card.AddField(m => m.Observations, true);

                    // creates another Card for displaying the contact's address details
                    patientContext.AddTitle(ReportTitleSize.H2, m => "Endereço");
                    var addressCard = patientContext.AddCard(m => m.Address);
                    addressCard.AddField(m => m.Street, true);
                    addressCard.AddField(m => m.Neighborhood, true);
                    addressCard.AddField(m => m.Complement);
                    addressCard.AddField(m => m.City);
                    addressCard.AddField(m => m.StateProvince);
                    addressCard.AddField(m => m.CEP);

                    for (var i = 0; i < patient.Sessions.Count; i++)
                    {
                        var closureI = i;
                        var session  = patient.Sessions[i];

                        patientContext.AddTitle(ReportTitleSize.H2, m => "Consulta do dia " + session.Date.ToShortDateString() + " às " + session.Date.ToShortTimeString());

                        for (var j = 0; j < session.Anamneses.Count; j++)
                        {
                            var closureJ = j;
                            patientContext.AddTitle(ReportTitleSize.H2, m => "Anamnese");
                            var anamneseCard = patientContext.AddCard(c => c.Sessions[closureI].Anamneses[closureJ]);
                            anamneseCard.AddField(m => m.ChiefComplaint, true);
                            anamneseCard.AddField(m => m.HistoryOfThePresentIllness, true);
                            anamneseCard.AddField(m => m.PastMedicalHistory, true);
                            anamneseCard.AddField(m => m.ReviewOfSystems, true);
                            anamneseCard.AddField(m => m.FamilyDeseases, true);
                            anamneseCard.AddField(m => m.SocialHistory, true);
                            anamneseCard.AddField(m => m.RegularAndAcuteMedications, true);
                            anamneseCard.AddField(m => m.Allergies, true);
                            anamneseCard.AddField(m => m.SexualHistory, true);
                            anamneseCard.AddField(m => m.Conclusion, true);
                        }

                        for (var j = 0; j < session.PhysicalExaminations.Count; j++)
                        {
                            var closureJ = j;
                            patientContext.AddTitle(ReportTitleSize.H2, m => "Exame físico");
                            var physicalExaminationCard = patientContext.AddCard(c => c.Sessions[closureI].PhysicalExaminations[closureJ]);
                            physicalExaminationCard.AddField(m => m.Notes);
                        }

                        for (var j = 0; j < session.DiagnosticHipotheses.Count; j++)
                        {
                            var closureJ = j;
                            patientContext.AddTitle(ReportTitleSize.H2, m => "Hipótese diagnóstica");
                            var physicalExaminationCard = patientContext.AddCard(c => c.Sessions[closureI].DiagnosticHipotheses[closureJ]);
                            physicalExaminationCard.AddField(m => m.Cid10Code);
                            physicalExaminationCard.AddField(m => m.Cid10Name);
                            physicalExaminationCard.AddField(m => m.Text);
                        }

                        for (var j = 0; j < session.Prescriptions.Count; j++)
                        {
                            var closureJ = j;
                            patientContext.AddTitle(ReportTitleSize.H2, m => "Receita");
                            var prescriptionGrid = patientContext.AddGrid(c => c.Sessions[closureI].Prescriptions[closureJ].PrescriptionMedicines);
                            prescriptionGrid.AddColumn(m => m.MedicineText);
                            prescriptionGrid.AddColumn(m => m.Quantity);
                            prescriptionGrid.AddColumn(m => m.Prescription);
                            prescriptionGrid.AddColumn(m => m.Observations);
                        }

                        if (session.ExaminationRequests.Any())
                        {
                            patientContext.AddTitle(ReportTitleSize.H2, m => "Pedidos de exame ou procedimento");
                            var examinationRequestsGrid = patientContext.AddGrid(c => c.Sessions[closureI].ExaminationRequests);
                            examinationRequestsGrid.AddColumn(m => m.MedicalProcedureName);
                            examinationRequestsGrid.AddColumn(m => m.MedicalProcedureCode);
                            examinationRequestsGrid.AddColumn(m => m.Notes);
                        }

                        if (session.ExaminationResults.Any())
                        {
                            patientContext.AddTitle(ReportTitleSize.H2, m => "Resultados de exame ou procedimento");
                            var examinationResultGrid = patientContext.AddGrid(c => c.Sessions[closureI].ExaminationResults);
                            examinationResultGrid.AddColumn(m => m.MedicalProcedureName);
                            examinationResultGrid.AddColumn(m => m.MedicalProcedureCode);
                            examinationResultGrid.AddColumn(m => m.Text);
                        }
                    }
                }
            }

            return(report.SaveToByteArray());
        }
Esempio n. 5
0
 public ReportData(CerebelloEntitiesAccessFilterWrapper db, Practice practice)
 {
     this.db       = db;
     this.practice = practice;
 }