0

I'm trying to return an object in a model's view that goes an element and I can't figure out how to get my conditions out properly. Here's my controller:

    function view($id = null) {
    if (!$id) {
        $this->Session->setFlash(__('Invalid admission', true));
        $this->redirect(array('action' => 'index'));
    }
            $admission = $this->Admission->read(null, $id);

            **$_patient_id = 2;**
            $patientAdmissions = $this->Admission->getCurrentPatientAdmissions($_patient_id);

    $this->set(compact('admission', 'patientAdmissions'));
}

This view function is in the admissions_controller and shows a specific admission with $id. I want to display a div with all of this patient's admissions in it. My getCurrentPatientAdmissions looks like this:

    function getCurrentPatientAdmissions($_patient_id) {
      $params = array(
          'conditions' => array(
              'Admission.patient_id' => $_patient_id,
          ),
      );
      return $this->find('all', $params);
    }

Any ideas are much appreciated.

1 Answer 1

1

Where are you placing the 'getCurrentPatientAdmissions' function? what file?

Why are you using the function 'getCurrentPatientAddmissions' instead of just running 'find'?

$patientAdmissions = $this->Admissions->find('all', array(
  'conditions' => array(
    'Admission.patient_id' => $admission['Patient']['id']
   )
  )
);

It seems like creating a function for something as simple as this is a bit over kill...

Doesn't the read function:

$admission = $this->Admission->read(null, $id);

already get a list of all the patients addmissions for you?

Sign up to request clarification or add additional context in comments.

11 Comments

@YonoRan Bother are in admissions model
@YonoRan No it doesn't. This is the admissions view which shows specific admissions. I want to show the other admissions for the patient in that view so they can select other admissions. I want to keep it in this view because it will show admission specific data (events, comments, etc) related to the admission.
You have 2 models with the same name? cause in both cases your running a query on the admissions model. What exactly is the structure and relationships?
Patients, Floors top level, then Admissions, Then Events, Comments, Followups; A patient can have multiple admissions, each admission can have multiple events comments and followups
At the moment, we're talking about the Admissions->View Controller which calls a couple Model Classes. There probably is a better way to do it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.