Ejemplo n.º 1
0
        /// <summary>
        /// Update Patient's Study Id and/or warn if already exits.
        /// </summary>
        /// <param name="e"></param>
        protected void UpdateStudyId(CaisisAjaxEventArgs e)
        {
            string newStudyId = e.ClientParam;

            if (PatientPage != null && !string.IsNullOrEmpty(newStudyId) && !string.IsNullOrEmpty(PatientPage.PatientProtocolId))
            {
                // ok to update when study id doesn't exits
                if (!ProtocolMgmtDa.StudyIdExists(newStudyId, int.Parse(PatientPage.BaseProtocolId)))
                {
                    int             ptProtocolId = int.Parse(PatientPage.PatientProtocolId);
                    PatientProtocol biz          = new PatientProtocol();
                    biz.Get(ptProtocolId);
                    biz[PatientProtocol.PtProtocolStudyId] = newStudyId;
                    biz.Save();

                    // CREATE STUDY ID IDENTIFIER
                    PatientProtocolController.CreateStudyIdIdentifier(biz);

                    // echo back value to client
                    e.ReturnValue = newStudyId;
                }
                // otherwise exists, and warn
                else
                {
                    // echo back to client study id exits
                    e.ReturnValue = "The StudyId entered already exits in the system.";
                }
            }
            else
            {
                // echo to client there were issues
                e.ReturnValue = "Please Enter a valid StudyId.";
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates PtProtocol record with PtProtocol Notes Field
 /// </summary>
 private void UpdatePtProtocolNotes()
 {
     if (ptProtocol != null)
     {
         ptProtocol[PatientProtocol.PtProtocolNotes] = PtProtocolNotes.Text;
         ptProtocol.Save();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DoSave(object sender, EventArgs e)
        {
            try
            {
                if (ValidateForm())
                {
                    // REQUIRED
                    int protocolId = int.Parse(BaseProtocolId);

                    // STEP 1: Get PatientId
                    Patient patient = new Patient();
                    int     ptId    = -1;
                    if (CanViewPatientInfo)
                    {
                        if (AddNewPatient.Checked)
                        {
                            patient[Patient.PtFirstName] = NewFirstName.Value;
                            patient[Patient.PtLastName]  = NewLastName.Value;
                            patient[Patient.PtMRN]       = NewMRN.Value;
                            // If no name or mrn, enter notes to save record
                            patient[Patient.PtNotes] = "Protocol-Patient";
                            // insert records using controller
                            PatientController ct = new PatientController();
                            try
                            {
                                // insert new patient
                                InsertNewPatientRecord(patient);
                            }
                            catch (InvalidScreeningException ex)
                            {
                                throw ex;
                            }
                            // if cannot insert patient, already exits, warn user
                            catch (Exception ex)
                            {
                                throw new InvalidScreeningException("Select a new MRN, another patient with the same MRN already exists in the system.");
                            }
                            //if (patient.RecordCount > 0)
                            if (!patient.IsEmpty)
                            {
                                ptId = int.Parse(patient[Patient.PatientId].ToString());
                            }
                        }
                        // if using existing patient
                        else if (FindExistingPatient.Checked)
                        {
                            if (!string.IsNullOrEmpty(epid.Value))
                            {
                                ptId = int.Parse(DecrypyValue(epid.Value));
                            }
                        }
                    }
                    // if cannnot view PatientInfo, insert blinded info
                    else
                    {
                        patient[Patient.PtFirstName] = string.Empty;
                        patient[Patient.PtLastName]  = string.Empty;
                        patient[Patient.PtMRN]       = string.Empty;
                        patient[Patient.PtNotes]     = "Blinded-Protocol-Patient";

                        // insert new patient
                        InsertNewPatientRecord(patient);

                        //if (patient.RecordCount > 0)
                        if (!patient.IsEmpty)
                        {
                            ptId = int.Parse(patient[Patient.PatientId].ToString());
                        }
                    }

                    // STEP 2: Create ParticipantID (if needed)
                    if (ptId != -1)
                    {
                        if (!PatientProtocolController.HasParticipantId(protocolId, ptId))
                        {
                            PatientProtocolController.CreateParticipantIdIdentifier(protocolId, ptId);
                        }
                    }

                    // VALIDATION: ensure non-duplicate PatientProtocol, via insert new patient
                    int?ptProtocolId = null;
                    var pp           = BusinessObject.GetByFields <PatientProtocol>(
                        new Dictionary <string, object>
                    {
                        { PatientProtocol.ProtocolId, protocolId },
                        { PatientProtocol.PatientId, ptId }
                    }
                        );
                    if (pp.Count() > 0)
                    {
                        ptProtocolId = (int)pp.First()[PatientProtocol.PatientProtocolId];
                    }

                    // STEP 3: Determine Pass or Fail, and create relevent records

                    // If screening failed, create empty PatientProtocol record to track screening
                    if (ScreeningFailed.Checked)
                    {
                        PatientProtocol ptProtocol = new PatientProtocol();
                        if (ptProtocolId.HasValue)
                        {
                            ptProtocol.Get(ptProtocolId.Value);
                        }
                        else
                        {
                            ptProtocol[PatientProtocol.PatientId]             = ptId;
                            ptProtocol[PatientProtocol.ProtocolId]            = protocolId;
                            ptProtocol[PatientProtocol.PtProtocolScreeningId] = PatientProtocolController.GenerateScreeningId();
                            ptProtocol.Save();
                        }
                        PatientProtocolStatus status = new PatientProtocolStatus();
                        status[PatientProtocolStatus.PatientProtocolId] = ptProtocol[PatientProtocol.PatientProtocolId];
                        status[PatientProtocolStatus.PtProtocolStatus]  = PatientProtocolController.ScreeningFailed;

                        DateTime statusDate = DateTime.Today;
                        if (!string.IsNullOrEmpty(ScreeningDate.Value) && DateTime.TryParse(ScreeningDate.Value, out statusDate))
                        {
                            status[PatientProtocolStatus.PtProtocolStatusDate]     = statusDate;
                            status[PatientProtocolStatus.PtProtocolStatusDateText] = statusDate.ToShortDateString();
                        }
                        else
                        {
                            status[PatientProtocolStatus.PtProtocolStatusDate]     = DateTime.Today;
                            status[PatientProtocolStatus.PtProtocolStatusDateText] = DateTime.Today.ToShortDateString();
                        }
                        status[PatientProtocolStatus.PtProtocolStatusReason] = ReasonFailed.Value;
                        status[PatientProtocolStatus.PtProtocolStatusNotes]  = ReasonFailedNotes.Value;
                        status.Save();
                    }
                    // If screening passed, create necessary records
                    else if (ScreeningPassed.Checked)
                    {
                        // Create PatientProtocol for Patient
                        PatientProtocol ptProtocol = new PatientProtocol();
                        if (ptProtocolId.HasValue)
                        {
                            ptProtocol.Get(ptProtocolId.Value);
                            bool doUpdate = false;
                            // update/ insert fields
                            if (ptProtocol.IsNull(PatientProtocol.PtProtocolStudyId))
                            {
                                ptProtocol[PatientProtocol.PtProtocolStudyId] = StudyID.Value;
                                doUpdate = true;
                            }
                            if (ptProtocol.IsNull(PatientProtocol.PtProtocolScreeningId))
                            {
                                ptProtocol[PatientProtocol.PtProtocolScreeningId] = PatientProtocolController.GenerateScreeningId();
                                doUpdate = true;
                            }
                            if (doUpdate)
                            {
                                ptProtocol.Save();
                            }
                        }
                        else
                        {
                            ptProtocol[PatientProtocol.ProtocolId]            = protocolId;
                            ptProtocol[PatientProtocol.PatientId]             = ptId;
                            ptProtocol[PatientProtocol.PtProtocolScreeningId] = PatientProtocolController.GenerateScreeningId();
                            ptProtocol[PatientProtocol.PtProtocolStudyId]     = StudyID.Value;
                            ptProtocol.Save();
                        }

                        // CREATE STUDY ID IDENTIFIER
                        PatientProtocolController.CreateStudyIdIdentifier((int)ptProtocol[ptProtocol.PrimaryKeyName]);

                        // Create Registration Record
                        PatientProtocolRegistration registrationRecord = new PatientProtocolRegistration();
                        registrationRecord[PatientProtocolRegistration.PatientProtocolId] = ptProtocol[PatientProtocol.PatientProtocolId];
                        registrationRecord[PatientProtocolRegistration.ConsentedTo]       = " ";
                        registrationRecord.Save();

                        PatientProtocolStatus status = new PatientProtocolStatus();
                        status[PatientProtocolStatus.PatientProtocolId] = ptProtocol[PatientProtocol.PatientProtocolId];
                        status[PatientProtocolStatus.PtProtocolStatus]  = PatientProtocolController.ScreeningPassed;
                        DateTime statusDate = DateTime.Today;
                        if (!string.IsNullOrEmpty(ScreeningDate.Value) && DateTime.TryParse(ScreeningDate.Value, out statusDate))
                        {
                            status[PatientProtocolStatus.PtProtocolStatusDate]     = statusDate;
                            status[PatientProtocolStatus.PtProtocolStatusDateText] = statusDate.ToShortDateString();
                        }
                        else
                        {
                            status[PatientProtocolStatus.PtProtocolStatusDate]     = DateTime.Today;
                            status[PatientProtocolStatus.PtProtocolStatusDateText] = DateTime.Today.ToShortDateString();
                        }
                        status[PatientProtocolStatus.PtProtocolStatusNotes] = StudyNodes.Value;
                        status.Save();
                    }

                    // STEP 4: Register Client Script events

                    // Save and Close
                    if (sender == SaveBtn)
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "saveAndClose", "saveAndClose();", true);
                    }
                    // Save and Load Registration Interface
                    else if (sender == ContinueBtn)
                    {
                        string script = "if(parent.patientAssigned) { parent.patientAssigned('" + protocolId + "','','" + EncryptValue(ptId.ToString()) + "'); }";
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "OnPatientAssigned", script, true);
                    }
                    ErrorMessage.Text = "";
                }
            }
            catch (InvalidScreeningException invalidFormException)
            {
                ErrorMessage.Text = "Error:&nbsp;&nbsp;" + invalidFormException.Message;
            }
        }
Ejemplo n.º 4
0
        private void InsertDimension(object atts, int patientId, SqlTransaction trans)
        {
            DataRow dr;

            if (atts is XmlNode)
            {
                dr = this.AttributesToRow(((XmlNode)atts).Attributes);
            }
            else
            {
                dr = (DataRow)atts;
            }

            string dimType = (string)dr["type"];

            switch (dimType)
            {
            case "Institution":
                InstitutionDa ida           = new InstitutionDa();
                int           institutionId = ida.GetPrimKey((string)dr["value"]);
                this._CheckId(institutionId, dimType, dr);
                PatientInstitutionDa pida = new PatientInstitutionDa();

                if (VerifyUnique((pida.GetPatientInstitution(patientId, institutionId, trans)).Tables[0]))
                {
                    // NEW CODE, insert record though middle tier
                    PatientInstitution ptInstitution = new PatientInstitution();
                    ptInstitution[PatientInstitution.PatientId]     = patientId;
                    ptInstitution[PatientInstitution.InstitutionId] = institutionId;
                    ptInstitution.Save();

                    // OLD CODE, inserts now handled by middle tier
                    // pida.InsertPatientInstitution(patientId, institutionId, trans);  add trans logic after concurrency fully tested- spy 2/21
                    // pida.InsertPatientInstitution(patientId, institutionId, trans);
                }
                break;

            case "Physician":
                PhysicianDa pda = new PhysicianDa();
                //to get Physician primary key need to pass first and last name in from dataset defined in XML
                int physicianId = pda.GetPrimKey((string)dr["value"], (string)dr["value2"]);
                this._CheckId(physicianId, dimType, dr);

                PatientPhysicianDa ppda = new PatientPhysicianDa();
                if (VerifyUnique((ppda.ValidatePatientPhysician(patientId, physicianId)).Tables[0]))
                {
                    // NEW CODE, insert record though middle tier
                    PatientPhysician ptPhysician = new PatientPhysician();
                    ptPhysician[PatientPhysician.PatientId]   = patientId;
                    ptPhysician[PatientPhysician.PhysicianId] = physicianId;
                    ptPhysician.Save();

                    // OLD CODE, inserts now handled by middle tier
                    //should be creating Patient Physician biz object and passing object to PatientPhysicianDa
                    //ppda.InsertPatientPhysicianDimension(patientId, physicianId, _sc.GetUserName(), trans);
                }
                break;

            case "Protocol":
                ProtocolDa protDa     = new ProtocolDa();
                int        protocolId = protDa.GetPrimKey((string)dr["value"]);
                this._CheckId(protocolId, dimType, dr);

                PatientProtocolDa ptProtDa = new PatientProtocolDa();
                if (VerifyUnique((ptProtDa.ValidatePatientProtocol(patientId, protocolId)).Tables[0]))
                {
                    // NEW CODE, insert record though middle tier
                    PatientProtocol ptProtocol = new PatientProtocol();
                    ptProtocol[PatientProtocol.PatientId]  = patientId;
                    ptProtocol[PatientProtocol.ProtocolId] = protocolId;
                    ptProtocol.Save();

                    // OLD CODE, inserts now handled by middle tier
                    //ptProtDa.InsertPatientProtocolDimension(patientId, protocolId, _sc.GetUserName(), trans);
                }
                break;

            case "Disease":
                DiseaseDa disDa     = new DiseaseDa();
                int       diseaseId = disDa.GetPrimKey((string)dr["value"]);
                this._CheckId(diseaseId, dimType, dr);

                PatientDiseaseDa ptDiseaseDa = new PatientDiseaseDa();
                if (VerifyUnique((ptDiseaseDa.GetPatientDisease(patientId, diseaseId)).Tables[0]))
                {
                    // NEW CODE, insert record though middle tier
                    PatientDisease ptDisease = new PatientDisease();
                    ptDisease[PatientDisease.PatientId] = patientId;
                    ptDisease[PatientDisease.DiseaseId] = diseaseId;
                    ptDisease.Save();

                    // OLD CODE, inserts now handled by middle tier
                    //ptDiseaseDa.InsertPatientDisease(patientId, diseaseId, trans);
                }
                break;
            }
        }