Example #1
0
        /// <summary>
        /// Inserts a new patient with relevant required dataset paramaters
        /// </summary>
        /// <param name="patient"></param>
        /// <returns></returns>
        private DataSet InsertNewPatientRecord(Patient patient)
        {
            PatientController ct = new PatientController();
            int sessionId        = (int)Session[SessionKey.DatasetId];
            int?institutionId    = null;

            // if current dataset isn't mapped to institution, add institution based on user selection
            if (!hasInstitutionDataset)
            {
                string institutionIdValue = NewPatientInstitutionSelect.Value;
                if (string.IsNullOrEmpty(institutionIdValue))
                {
                    throw new InvalidScreeningException("An Institution is required for adding a patient to this dataset.");
                }
                else
                {
                    institutionId = int.Parse(institutionIdValue);
                }
            }
            // insert patient
            DataSet dimensionDs = ct.InsertNewPatientRecord(patient, sessionId);

            // if an insitution is required, create dimension
            if (patient.PrimaryKeyHasValue && !hasInstitutionDataset && institutionId.HasValue)
            {
                int patientId         = (int)patient[Patient.PatientId];
                PatientInstitution pi = new PatientInstitution();
                pi[PatientInstitution.PatientId]     = patientId;
                pi[PatientInstitution.InstitutionId] = institutionId.Value;
                pi.Save();
            }
            // return new dimension
            return(dimensionDs);
        }
    protected void AddButtonClick(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        if (!Request.Form["Institutions"].Equals("") && !Request.Form["SelectPatientName"].Equals(""))
        {
            UserGroupDa userGroupDa   = new UserGroupDa();
            int         patientId     = int.Parse(Request.Form["SelectPatientName"]);
            int         institutionId = int.Parse(Request.Form["Institutions"]);

            SecurityController sc = new SecurityController();

            PatientInstitution ptInstitution = new PatientInstitution();
            ptInstitution[PatientInstitution.InstitutionId] = institutionId;
            ptInstitution[PatientInstitution.PatientId]     = patientId;
            //ptInstitution[PatientInstitution.EnteredBy] = sc.GetUserName();
            //ptInstitution[PatientInstitution.EnteredTime] = DateTime.Now;

            ptInstitution.Save();

            this.ShowInstitutionSelect(patientId);
            //this.Page_Load(sender, (System.EventArgs)e);
        }
        else
        {
            valMsg.Text = "You must select a patient and institution.";
        }
    }
    protected void DeleteButtonClick(object sender, CommandEventArgs e)
    {
        int patientInstitutionId = int.Parse(e.CommandArgument.ToString());
        PatientInstitution biz   = new PatientInstitution();

        biz.Delete(patientInstitutionId);

        this.Page_Load(sender, (System.EventArgs)e);
    }
Example #4
0
        public IActionResult Pets(Pets pets)
        {
            if (ModelState.IsValid)
            {
                var petInInstExist = _context.PatientInstitution.Where(pe => pe.IdInst == pets.SelectedInst && pe.IdPatient == pets.SelectedPet).SingleOrDefault();
                if (petInInstExist == null)
                {
                    PatientInstitution petInInst = new PatientInstitution
                    {
                        IdPatient = pets.SelectedPet,
                        IdInst    = pets.SelectedInst
                    };

                    _context.Add(petInInst);
                    _context.SaveChanges();
                }
            }

            return(RedirectToAction("Pets"));
        }
Example #5
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;
            }
        }
Example #6
0
        public async Task <IActionResult> CreatePatientVisit(CreatePatientVisit cpv)
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                var checkEmail = _context.ApplicationUser.Where(e => e.Email == cpv.Email).SingleOrDefault();

                ApplicationUser owner      = new ApplicationUser();
                Patient         newPatient = new Patient();


                if (checkEmail == null)
                {
                    owner.Email    = cpv.Email;
                    owner.UserName = cpv.Email;
                    owner.Surname  = cpv.Surname;

                    owner.Address     = cpv.Address;
                    owner.Name        = cpv.NameOwner;
                    owner.PhoneNumber = cpv.PhoneNumber;


                    await _userManager.CreateAsync(owner, cpv.Password);

                    await _userManager.AddToRoleAsync(owner, "Owner");
                }
                else if (checkEmail != null)
                {
                    owner = _context.ApplicationUser.Where(e => e.Email == cpv.Email).SingleOrDefault();
                }
                else
                {
                    return(View());
                }

                if (owner != null)
                {
                    newPatient.Id      = owner.Id;
                    newPatient.Sex     = cpv.Sex;
                    newPatient.Breed   = cpv.Breed;
                    newPatient.Weight  = cpv.Weight;
                    newPatient.Age     = cpv.Age;
                    newPatient.Name    = cpv.NamePet;
                    newPatient.IdGenus = cpv.SelectedType;
                    newPatient.SterilizedCastration = cpv.SterilizedCastration;
                    _context.Add(newPatient);
                    _context.SaveChanges();
                }

                if (owner != null && newPatient != null)
                {
                    PatientInstitution patientInstitution = new PatientInstitution
                    {
                        IdInst    = applicationUser.IdInst,
                        IdPatient = newPatient.IdPatient
                    };

                    Visit firstVisit = new Visit
                    {
                        Purpose        = cpv.Purpose,
                        DecrDisActions = cpv.DecrDisActions,
                        IdPatient      = newPatient.IdPatient,
                        Id             = applicationUser.Id,
                        DateVisit      = DateTime.Now
                    };


                    await _context.AddAsync(patientInstitution);

                    _context.Add(firstVisit);
                    await _context.SaveChangesAsync();
                }



                return(RedirectToAction("PatientList"));
            }



            else
            {
                CreatePatientVisit();
                return(View());
            }
        }