예제 #1
0
        public IActionResult Post([FromBody] Dictionary <string, object> param)
        {
            EntityConnection con = new EntityConnection("tbl_patient");

            if (param != null)
            {
                param.Remove("hospitalNumber");

                // Generate hospital number
                EntityConnection forHospNum = new EntityConnection("tbl_patient");
                var hospitalNumber          = forHospNum.GenerateUniqueHospitalNumber();

                int patientTypeId = Convert.ToInt32(param["patientType"]);

                Dictionary <string, object> genericPatient = new Dictionary <string, object>();

                string[] patientRecord = { "surname", "otherNames", "phoneNumber", "altPhoneNum", "email", "ethnicGroup", "gender", "nhisNumber", "hmoId", "dateOfBirth", "maritalStatus", "address", "stateId", "nationalityId", "patientType", "nokName", "nokAddress", "nokPhoneNum", "nokRelationship", "pictureId", "status", "recordStaffId" };

                if (patientTypeId == 1 || patientTypeId == 2)
                {
                    patientRecord.Append("faculty");
                    patientRecord.Append("department");
                }

                genericPatient = Utility.Pick(param, patientRecord);

                genericPatient.Add("hospitalNumber", hospitalNumber);

                genericPatient.Add("createDate", DateTime.Now.ToString());

                long patientId = con.InsertScalar(genericPatient);

                genericPatient.Add("itbId", patientId);



                // check if patient type is a staff
                if (patientTypeId == 1)
                {
                    Dictionary <string, object> staff = new Dictionary <string, object>();

                    string[] staffPatientRecord = { "staffCode", "dateOfEmployment", "designation", "partnerTitle", "partnerName", "partnerHospNum", "partnerRelation", "partnerIsStaff", "dateOfArrival", "status" };

                    staff = Utility.Pick(param, staffPatientRecord);

                    staff.Add("patientId", patientId);
                    staff.Add("createDate", DateTime.Now.ToString());

                    EntityConnection connection = new EntityConnection("tbl_staff_patient");

                    long staffId = connection.InsertScalar(staff);

                    param.Add("staffId", staffId);

                    //connection.InsertStaffPatient(staff);
                }
                else if (patientTypeId == 2) //if patient type is a student
                {
                    Dictionary <string, object> student = new Dictionary <string, object>();

                    string[] studentPatientRecord = { "matricNumber", "yearOfAdmission", "parentName", "parentAddress1", "parentAddress2", "parentPhone1", "parentPhone2", "localGuardian", "localGuardAddress1", "localGuardAddress2", "localGuardPhone1", "localGuardPhone2", "localGuardianRelationship", "status" };

                    student = Utility.Pick(param, studentPatientRecord);

                    student.Add("patientId", patientId);
                    student.Add("createDate", DateTime.Now.ToString());

                    EntityConnection connect = new EntityConnection("tbl_student_patient");

                    connect.InsertStudentPatient(student);
                }
                else if (patientTypeId == 4)
                {
                    Dictionary <string, object> nonStaff = new Dictionary <string, object>();

                    string[] nonStaffRecord = { "companyName", "dateOfEmployment", "companyAddress", "designation", "recordStaffId", "partnerTitle", "partnerRelation", "partnerName", "dateOfArrival" };

                    nonStaff = Utility.Pick(param, nonStaffRecord); // pick the perculiar data related to a specific table and save it in a dictionary

                    nonStaff.Add("patientId", patientId);

                    EntityConnection cons = new EntityConnection("tbl_nonstaff");

                    param.Remove("faculty");

                    param.Remove("department");

                    cons.InsertNonStaff(nonStaff);
                }

                param.Add("hospitalNumber", hospitalNumber);
                param.Add("itbId", patientId);
                obj = new { data = param };
                return(Created("", obj));
            }
            else
            {
                return(BadRequest());
            }
        }