public IHttpActionResult Post([FromBody] PatientRegistrationInfo value)
        {
            if (ModelState.IsValid)
            {
                PatientRegistrationInfoEntity patientReg = new PatientRegistrationInfoEntity();
                patientReg.FirstName        = value.FirstName;
                patientReg.LastName         = value.LastName;
                patientReg.DoctorId         = value.DoctorId;
                patientReg.TreatmentRoomId  = value.TreatmentRoomId;
                patientReg.ConditionTypeId  = value.ConditionTypeId;
                patientReg.TopographyId     = value.TopographyId;
                patientReg.ConsultationDate = value.ConsultationDate;

                try
                {
                    var newId = _businessLayer.RegisterPatient(patientReg);

                    //Generate a link to the new consultation and set the location header in the response
                    var location = new Uri(Url.Link("GetConsultationById", new { id = newId }));

                    return(Created(location, "Patient is regiested"));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        /// <summary>
        /// Schedule a consultation for a patient
        /// </summary>
        /// <param name="patientRegistrationInfo"></param>
        /// <returns>New consultation Id</returns>
        public int RegisterPatient(PatientRegistrationInfoEntity patientRegistrationInfo)
        {
            //This method is only for new patient
            //To do: need to handle transation

            /*Patient registration workflow
             *  check if the input is valid
             *  check if the consultation date is greater than today
             *  check if the patient has registed already
             *  check if the doctor is available that date
             *  check if the doctor has a role to treat the patient's condition
             *  check if the trementroom is availabel that date
             *  check if the machine (if there is) in the treatmentroom has the capability to treat the patient based on the patient's opography.
             *      Note that flu condition is configured to a topography "Not Applicable". All conditions should have at least one topography
             *  insert the patient and set the registration date as today
             *  Insert a consulatation for the new patient
             */

            if (patientRegistrationInfo == null)
            {
                throw new ArgumentNullException("patientRegistrationInfo");
            }

            try
            {
                //check if input is valid
                var doctor = _dataAccessService.DoctorRepository.GetItemById(patientRegistrationInfo.DoctorId);
                if (doctor == null)
                {
                    throw new Exception("Invalid doctor id");
                }

                var condition = _dataAccessService.ConditionTypeRepository.GetItemById(patientRegistrationInfo.ConditionTypeId);
                if (condition == null)
                {
                    throw new Exception("Invalid ConditionType id");
                }

                var topography = _dataAccessService.TopographyRepository.GetItemById(patientRegistrationInfo.TopographyId);
                if (topography == null)
                {
                    throw new Exception("Invalid Topography id");
                }

                var treatmentRoom = _dataAccessService.TreatmentRoomRepository.GetItemById(patientRegistrationInfo.TreatmentRoomId);
                if (treatmentRoom == null)
                {
                    throw new Exception("Invalid TreatmentRoom id");
                }

                //check if teh consultation date is greater than today
                if ((DateTime.Now.Date - patientRegistrationInfo.ConsultationDate.Date).Days >= 0)
                {
                    throw new Exception("The consultation date should be a future date");
                }

                //check if the patient has registed already (assume a patient's identity is the combination of first name and last name)
                if (DoesPatientExist(patientRegistrationInfo.FirstName, patientRegistrationInfo.LastName))
                {
                    throw new Exception("The patient has been registered.");
                }

                //check if the doctor is available that date
                if (IsDoctorAvailableByDate(patientRegistrationInfo.DoctorId, patientRegistrationInfo.ConsultationDate) == false)
                {
                    throw new Exception(string.Format("The doctor has booked on {0}", patientRegistrationInfo.ConsultationDate.Date.ToString()));
                }

                //check if the doctor has a role to treat the patient's condition
                if (IsDoctorQualifedForConsultation(patientRegistrationInfo.DoctorId, patientRegistrationInfo.ConditionTypeId) == false)
                {
                    throw new Exception(string.Format("The doctor is not qulified to treat {0}", condition.ConditionTypeName));
                }

                //check if the trementroom is availabel that date
                if (IsTreatmentRoomAvailableByDate(patientRegistrationInfo.TreatmentRoomId, patientRegistrationInfo.ConsultationDate) == false)
                {
                    throw new Exception(string.Format("The treatment room has booked on {0}", patientRegistrationInfo.ConsultationDate.Date.ToString()));
                }

                //check if the machine(if there is) in the treatmentroom has the capability to treat the patient based on the patient's opography.
                if (IsTreatmentRoomQualifedForConsultation(patientRegistrationInfo.TreatmentRoomId, patientRegistrationInfo.TopographyId) == false)
                {
                    throw new Exception("The treatment room is not qualified for consultation");
                }

                //insert new patient
                Patient newPatient = new Patient();
                newPatient.FirstName            = patientRegistrationInfo.FirstName;
                newPatient.LastName             = patientRegistrationInfo.LastName;
                newPatient.ConditionTypeID      = condition.Id;
                newPatient.ConditionTypeName    = condition.ConditionTypeName;
                newPatient.TopographyID         = topography.Id;
                newPatient.TopographyName       = topography.TopographyName;
                newPatient.RegistrationDatetime = DateTime.Now;

                var insertedPatient = _dataAccessService.AddPatient(newPatient);

                if (insertedPatient == null)
                {
                    throw new Exception("Insert patient failed");
                }

                Consultation newConsultation = new Consultation();
                newConsultation.PatiendID       = insertedPatient.Id;
                newConsultation.DoctorID        = patientRegistrationInfo.DoctorId;
                newConsultation.StartDateTime   = patientRegistrationInfo.ConsultationDate.Date;
                newConsultation.EndDateTime     = patientRegistrationInfo.ConsultationDate.Date;
                newConsultation.TreatmentRoomID = patientRegistrationInfo.TreatmentRoomId;
                newConsultation.Patient         = insertedPatient;
                newConsultation.Doctor          = doctor;
                newConsultation.TreatmentRoom   = treatmentRoom;

                var insertedConsultation = _dataAccessService.AddConsultation(newConsultation);
                if (newConsultation == null)
                {
                    throw new Exception("Failed to schedule a consultation");
                }

                return(newConsultation.Id);
            }
            catch
            {
                throw;
            }
        }