Beispiel #1
0
        protected void InitPage(object sender, EventArgs e)
        {
            // set restrict configuration
            var config = ProtocolMgmtUtil.GetProtocolConfigurationNode();

            restrictByUserOrganization = config != null && config.SelectSingleNode("configuration/RestrictByUserOrganization[text() = 'true' or text() = 'True']") != null;

            InitPagingVariables();

            AdminPanel.Visible = base.UserType == ProtocolMgmtUsers.ProtocolAdmin;
            if (AdminPanel.Visible)
            {
                ShowAllProtocolCheck.Visible = restrictByUserOrganization;
            }

            DataView protocolsList = LoadProtocols();

            recordCount = protocolsList.Count;

            // Bind projects to user's view
            BindProtocolList(protocolsList);

            // build paging
            BuildPaging();

            // Add scripts for dynamic postsback
            //RegisterProtocolSearchScript();
        }
        private float?GetDoublingTime(IEnumerable <KeyValuePair <float, DateTime> > labsByDate)
        {
            float?dbl = ProtocolMgmtUtil.GetPSADoublingTime(labsByDate);

            // smooth output
            if (dbl.HasValue)
            {
                dbl = (float)Math.Round(dbl.Value, 2);
            }
            return(dbl);
        }
        private void BuildGleasonInterface()
        {
            int patientProtocolId = int.Parse(PatientProtocolId);
            KeyValuePair <Pathology, BusinessObject>?gleasonPair = ProtocolMgmtUtil.GetGleasonPathologyRecord(patientProtocolId);

            if (gleasonPair.HasValue)
            {
                // get pair, determin type of pathology
                Pathology      path          = gleasonPair.Value.Key;
                BusinessObject pathProcedure = gleasonPair.Value.Value;
                // validation
                if (path.IsEmpty)
                {
                    return;
                }

                int    pathologyId = (int)path[Pathology.PathologyId];
                string pathType    = path[Pathology.PathSpecimenType].ToString();
                // manually set Path Fields
                PathDateText.Value     = path[Pathology.PathDateText].ToString();
                PathDate.Value         = path[Pathology.PathDate].ToString();
                PathSpecimenType.Value = pathType;
                // manuall set child records
                if (pathProcedure is ProstatectomyPathology)
                {
                    ProstatectomyPathology prostatectomy = pathProcedure as ProstatectomyPathology;
                    GleasonField1.Text   = prostatectomy[ProstatectomyPathology.PathGG1].ToString();
                    GleasonField2.Text   = prostatectomy[ProstatectomyPathology.PathGG2].ToString();
                    GleasonFieldSum.Text = prostatectomy[ProstatectomyPathology.PathGGS].ToString();
                }
                else if (pathProcedure is BiopsyProstatePathology)
                {
                    BiopsyProstatePathology biopsy = pathProcedure as BiopsyProstatePathology;
                    GleasonField1.Text   = biopsy[BiopsyProstatePathology.PathGG1].ToString();
                    GleasonField2.Text   = biopsy[BiopsyProstatePathology.PathGG2].ToString();
                    GleasonFieldSum.Text = biopsy[BiopsyProstatePathology.PathGGS].ToString();
                }
                else
                {
                    CICHelper.ClearCaisisInputControlValues(GleasonFields);
                }
            }
            else
            {
                CICHelper.ClearCaisisInputControlValues(GleasonFields);
            }
        }
Beispiel #4
0
        protected override void Page_Load(object sender, EventArgs e)
        {
            // set dataset message
            if (!hasInstitutionDataset)
            {
                NewPatientInstitution.Visible = true;
            }

            if (!Page.IsPostBack)
            {
                int protocolId = int.Parse(BaseProtocolId);
                // Get an auto-generate screening id
                ScreeningID.Value = PatientProtocolController.GenerateScreeningId().ToString();
                // study id
                string autoStudyId = PatientProtocolController.GenerateStudyId(protocolId);
                StudyID.Value = autoStudyId;
                bool calculateStudyIdBySite = ProtocolMgmtUtil.GenerateStudyIdByOrganization();
                // custom auto-generation
                if (calculateStudyIdBySite)
                {
                    OrganizationStudyIds.Visible = true;

                    StudyIdTooltip.Attributes["title"] = "An Id created to identify a patient on a study in the form: Site Id (2 digits) + Protocol Id (3 digits) + Incremental Patient Id (3 digits)";

                    // get associated Project (to select organizations)
                    Protocol protocol = new Protocol();
                    protocol.Get(protocolId);
                    string protocolNum = protocol[Protocol.ProtocolNum].ToString();

                    // get a list of associated organizations
                    if (!protocol.IsNull(Protocol.ProjectId) && !string.IsNullOrEmpty(protocolNum))
                    {
                        ProjectManagementDa da = new ProjectManagementDa();
                        int projectId          = (int)protocol[Protocol.ProjectId];

                        // get a list of organizations associated with project
                        var projectOrganizations = BusinessObject.GetByFields <Project_ProjectOrganization>(new Dictionary <string, object> {
                            { Project_ProjectOrganization.ProjectId, projectId }
                        });

                        // get a list of user's organizations
                        int       userId              = new UserController().GetUserId();
                        DataTable userOrganizations   = new UserDa().GetUserOrganizations(userId);
                        var       userOrganizationIds = userOrganizations.AsEnumerable().Select(r => (int)r["OrganizationId"]);

                        // get the intersect of user's sites and lead sites
                        var userLeadSites = from po in projectOrganizations
                                            let organizationType = po["OrganizationType"].ToString()
                                                                   let organizationId = (int)po[Project_ProjectOrganization.OrganizationId]
                                                                                        where organizationType.Contains("Lead Site")
                                                                                        join userOrgId in userOrganizationIds on organizationId equals userOrgId
                                                                                        select userOrgId;
                        // if user is part of a lead site, allow to select organization
                        if (userLeadSites.Count() > 0)
                        {
                            // TODO: centralize call to get project organizations
                            var organizations = da.GetAllOrganizationsByProjectId(projectId);
                            // get a list of organizations and calculate study id per organization
                            var organizationToStudyId = from row in organizations.AsEnumerable()
                                                        let orgName                         = row["Name"].ToString()
                                                                                  let orgId = (int)row["OrganizationId"]
                                                                                              let isAssociated = userOrganizationIds.Contains(orgId) ? 0 : 1
                                                                                                                 orderby
                                                                                                                 //isAssociated ascending,
                                                                                                                 orgName ascending
                                                                                                                 select new
                            {
                                OrganizationName    = orgName,
                                OrganizationId      = orgId,
                                OrganizationStudyId = GenerateStudyIdByOrganization(protocolId, protocolNum, orgId)
                            };

                            OrganizationStudyIds.DataSource = organizationToStudyId;
                            OrganizationStudyIds.DataBind();

                            // a list of insitutions where institution = organization in project
                            var allInstitutions = from inst in BOL.BusinessObject.GetAll <Institution>()
                                                  let institutionId = (int)inst[BOL.Institution.InstitutionId]
                                                                      let institutionName = inst[BOL.Institution.Institution_Field].ToString()
                                                                                            select new
                            {
                                InstitutionId = institutionId,
                                Institution   = institutionName
                            };
                            var orgs = from org in userOrganizations.AsEnumerable()
                                       select new
                            {
                                Name      = org["Name"].ToString(),
                                ShortName = org["ShortName"].ToString()
                            };
                            // get institution where name matches an organization's name or short name
                            var institutions = from inst in allInstitutions
                                               let institutionName = inst.Institution
                                                                     let organization = orgs.Where(org => org.Name == institutionName || org.ShortName == institutionName).FirstOrDefault()
                                                                                        where organization != null
                                                                                        select new
                            {
                                Text  = organization.Name,
                                Value = inst.InstitutionId
                            };

                            // build institutions
                            NewPatientInstitutionSelect.DataSource = institutions;
                            NewPatientInstitutionSelect.DataBind();

                            // set default study id: user's organization
                            // get user's site
                            int userLeadSiteId = userLeadSites.First();
                            // get study id for user's site
                            var userSites = organizationToStudyId.Where(o => o.OrganizationId == userLeadSiteId);
                            autoStudyId = userSites.Count() == 1 ? userSites.First().OrganizationStudyId : "";

                            // update field and select
                            OrganizationStudyIds.Value = autoStudyId;
                            StudyID.Value = autoStudyId;
                        }
                        // show a list of all user's organizations
                        else
                        {
                            if (userOrganizations.Rows.Count > 0)
                            {
                                string organizationName = userOrganizations.Rows[0]["Name"].ToString();
                                int    organizationId   = (int)userOrganizations.Rows[0]["OrganizationId"];

                                // a list of orgaizations associated with the project
                                var organizations = from o in userOrganizations.AsEnumerable()
                                                    let orgId = (int)o["OrganizationId"]
                                                                select
                                                                new
                                {
                                    OrganizationName    = o["Name"].ToString(),
                                    OrganizationId      = orgId,
                                    OrganizationStudyId = GenerateStudyIdByOrganization(protocolId, protocolNum, orgId)
                                };

                                // a list of insitutions where institution = organization in project
                                var allInstitutions = from inst in BOL.BusinessObject.GetAll <Institution>()
                                                      let institutionId = (int)inst[BOL.Institution.InstitutionId]
                                                                          let institutionName = inst[BOL.Institution.Institution_Field].ToString()
                                                                                                select new
                                {
                                    InstitutionId = institutionId,
                                    Institution   = institutionName
                                };
                                var orgs = from org in userOrganizations.AsEnumerable()
                                           select new
                                {
                                    Name      = org["Name"].ToString(),
                                    ShortName = org["ShortName"].ToString()
                                };
                                // get institution where name matches an organization's name or short name
                                var institutions = from inst in allInstitutions
                                                   let institutionName = inst.Institution
                                                                         let organization = orgs.Where(org => org.Name == institutionName || org.ShortName == institutionName).FirstOrDefault()
                                                                                            where organization != null
                                                                                            select new
                                {
                                    Text  = organization.Name,
                                    Value = inst.InstitutionId
                                };

                                // build organizations
                                OrganizationStudyIds.DataSource = organizations;
                                OrganizationStudyIds.DataBind();


                                // build institutions
                                NewPatientInstitutionSelect.DataSource = institutions;
                                NewPatientInstitutionSelect.DataBind();


                                autoStudyId = organizations.Count() == 1? organizations.First().OrganizationStudyId : "";

                                OrganizationStudyIds.Value = autoStudyId;

                                //OrganizationStudyIds.Enabled = false;
                                StudyID.Value = autoStudyId;
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(autoStudyId))
                    {
                        StudyIdError.Visible = true;
                    }
                }

                // default screeing date
                //ScreeningDate.Value = DateTime.Today.ToShortDateString();

                PopulatePhysicians();

                // set search by particpant id type
                SeachTypeParticipantID.Text = PROTOCOL_PARTICIPANT_ID_CODE;

                // default participant id field
                ParticipantIdField.Text = GetNextParticipantId();

                // default radios and panel which can be seen by user
                DetermineUserSearchAccess();
            }
        }
        private bool CanExportPatients()
        {
            int  protocolId = int.Parse(QueryProtocolId);
            bool canExport  = Caisis.Security.PermissionManager.HasPermission(Caisis.Security.PermissionManager.ExportData) && ProtocolMgmtUtil.EnablePatientExport(protocolId);

            return(canExport);
        }
        /// <summary>
        /// Inserts/Updates the relevent labs and gleason calculations
        /// </summary>
        private void SaveDetails()
        {
            // validation
            int             patientId         = int.Parse(BaseDecryptedPatientId);
            int             patientProtocolId = int.Parse(PatientProtocolId);
            PatientProtocol patientProtocol   = new PatientProtocol();

            patientProtocol.Get(patientProtocolId);

            var relatedLabTestIds = GetRelatedLabTestIds(patientProtocolId);

            // LABS (PSA)
            List <KeyValuePair <float, DateTime> > labResults = new List <KeyValuePair <float, DateTime> >();

            foreach (GridViewRow row in LabTestsGrid.Rows)
            {
                LabTest lab = new LabTest();
                // load???
                string currentRowId = LabTestsGrid.DataKeys[row.RowIndex][LabTest.LabTestId].ToString();
                if (!string.IsNullOrEmpty(currentRowId))
                {
                    lab.Get(int.Parse(currentRowId));
                }
                CICHelper.SetBOValues(row.Controls, lab, patientId);
                if (!lab.IsEmpty)
                {
                    lab[LabTest.LabTest_Field] = "PSA";
                    lab.Save();
                    int labTestId = (int)lab[LabTest.LabTestId];

                    string labTest        = lab[LabTest.LabTest_Field].ToString();
                    string labResult      = lab[LabTest.LabResult].ToString();
                    float  labResultValue = 0;
                    if (labTest.Equals("PSA") && float.TryParse(labResult, out labResultValue) && !lab.IsNull(LabTest.LabDate))
                    {
                        DateTime labDate = (DateTime)lab[LabTest.LabDate];
                        labResults.Add(new KeyValuePair <float, DateTime>(labResultValue, labDate));
                    }

                    // RELATED RECORD
                    if (!relatedLabTestIds.Contains(labTestId))
                    {
                        BOL.RelatedRecord relatedRecord = RelatedRecordController.CreateRelatedRecord(lab, patientProtocol);
                    }
                }
            }

            // calculate doubling time
            float?dbl = ProtocolMgmtUtil.GetPatientPSADoublingTime(patientProtocolId);

            if (dbl.HasValue)
            {
                PSADoublingTime.Text = dbl + " Months";
            }
            else
            {
                PSADoublingTime.Text = "N/A";
            }

            // GLEASON SCORE
            Pathology pathology = PatientProtocolController.GetPatientRelatedRecords <Pathology>(patientProtocolId).FirstOrDefault();

            // create new patholgy if needed
            if (!string.IsNullOrEmpty(PathSpecimenType.Value))
            {
                bool   isNewPathology = pathology == null;
                string pathType       = PathSpecimenType.Value;
                if (isNewPathology)
                {
                    pathology = new Pathology();
                    pathology[Pathology.PatientId] = patientId;
                }
                pathology[Pathology.PathSpecimenType] = pathType;
                pathology[Pathology.PathDateText]     = PathDateText.Value;
                pathology[Pathology.PathDate]         = PathDate.Value;
                pathology.Save();
                if (!pathology.IsEmpty)
                {
                    int pathologyId = (int)pathology[Pathology.PathologyId];
                    // create child record
                    if (pathType.Equals("Prostatectomy"))
                    {
                        var prostatectomy = BusinessObject.GetByParent <ProstatectomyPathology>(pathologyId).FirstOrDefault();
                        if (prostatectomy == null)
                        {
                            prostatectomy = new ProstatectomyPathology();
                            prostatectomy[ProstatectomyPathology.PathologyId] = pathologyId;
                        }
                        prostatectomy[ProstatectomyPathology.PathGG1] = GleasonField1.Text;
                        prostatectomy[ProstatectomyPathology.PathGG2] = GleasonField2.Text;
                        prostatectomy[ProstatectomyPathology.PathGGS] = GleasonFieldSum.Text;
                        prostatectomy.Save();
                    }
                    else if (pathType == "Biopsy")
                    {
                        var biopsy = BusinessObject.GetByParent <BiopsyProstatePathology>(pathologyId).FirstOrDefault();
                        if (biopsy == null)
                        {
                            biopsy = new BiopsyProstatePathology();
                            biopsy[BiopsyProstatePathology.PathologyId] = pathologyId;
                        }
                        biopsy[BiopsyProstatePathology.PathGG1] = GleasonField1.Text;
                        biopsy[BiopsyProstatePathology.PathGG2] = GleasonField2.Text;
                        biopsy[BiopsyProstatePathology.PathGGS] = GleasonFieldSum.Text;
                        biopsy.Save();
                    }
                    // create related record if needed
                    if (isNewPathology)
                    {
                        BOL.RelatedRecord relatedPathology = RelatedRecordController.CreateRelatedRecord(pathology, patientProtocol);
                    }
                }
            }

            // rebuild UI
            BuildInterfaces();
        }