Displaying selected list content based on other selected list content

13 posts by 2 authors in: Forums > CMS Builder
Last Post: April 19, 2011   (RSS)

Re: [Duches77] Displaying selected list content based on other selected list content

By Jason - April 13, 2011

Hi Jessica,

The issue here is this line
$find_a_doctorRecord[$carrier]

This code is trying to access a field in your section that has the same name as $carrier. But what we're looking for is a value in the 'insurance_carriers' field. This is why you're getting an unidentified index error.

If the insurance_carriers field is a multivalue field, you can get a list of all the selected values by using the :labels pseudo field like this:



<ul><li>
<?php join("</li><li>", $find_a_doctorRecord['insurance_carriers:labels']); ?>
</li></ul>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Displaying selected list content based on other selected list content

By JLynne77 - April 13, 2011

Oh, nice trick with that pseudo field. It's gotten me much closer.

My next step is to take each carrier and make a list under it of the plans that each carrier has. For example:

Carriers: Aetna, Aflac, Blue Cross, Vytra
Aetna Plans: HMO, PPO, POS
Aflac Plans: Network
Blue Cross Plans: Family Care, PPO
Vytra Plans: HMO, POS

The doctor accepts Vytra's POS plan, Aetna's PPO and POS plans, and nothing else.

So, on the page, I would do the following if I was using HTML:
Aetna:
<ul>
<li>PPO</li>
<li>POS</li>
</ul>
Vytra:
<ul>
<li>POS</li>
</ul>


In the CMS, I have given the user the ability to select Aetna and Vytra from one checkbox list. Then, they scroll down to the Aetna list and select PPO and POS. Then they scroll down to the Vytra list and select POS.

I'm getting closer to my goal, but not quite there. The demo link has been updated. This is what I have now:
<?php foreach ($find_a_doctorRecord['insurance_carriers:labels'] as $carrier):?>
<?php echo $carrier; ?><ul><li>
<?php foreach ($find_a_doctorRecord['insurance_carriers:values'] as $plan):?>
<?php echo join('</li><li>', $find_a_doctorRecord[$plan]); ?></li></ul>
<?php endforeach ?>
<?php endforeach ?>

I know there is an issue with the inner foreach loop. I'm looking at it now, and I know it's wrong, and I know why it's wrong (I'm cycling through the same list twice), but I'm not quite sure where to go next.

Thank you again!
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Displaying selected list content based on other selected list content

By Jason - April 14, 2011

Hi Jessica,

The issue is that $find_a_doctorRecord['insurance_carriers:labels'] only hold the values that have been selected for that record, not the entire list.

Also, you can't access the list like this:
$find_a_doctorRecord[$plan]

If, for example, $plan = PPO, for the code above to work, you'd need to have a field in your doctor table called "PPO" which you wouldn't. PPO would be an option in a list.

So in your 'carriers' field, you're storing things like 'Aetna, Aflac, etc". Where are you storing values like "HMO, PPO, Network", things like that?

Let me know and we'll see what we can figure out.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Displaying selected list content based on other selected list content

By JLynne77 - April 14, 2011 - edited: April 14, 2011

The plans are being stored in a list for each carrier.

So, I made a list 'carrier' with 'aetna', 'aflac', etc... and a list 'aetna' with 'hmo', 'ppo', etc. Aetna and Aflac aren't going to have the exact same plan options. A full name for a plan under Aetna might be "HMO Select Plus" and "HMO Plus", but Aflac would have different HMO options... maybe "HMO Gold" or "HMO Network".

On top of that, the doctor's profile page can't display anything that the doctor doesn't accept. So I can't display Aetna at all if the doctor doesn't accept any of Aetna's plans.

edit updated list information
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Displaying selected list content based on other selected list content

By Jason - April 15, 2011

Hi Jessica,

If the values of your "insurance_carriers" fields match up to the names of your different plan fields, you could try changing your join to this:

<?php echo join('</li><li>', $find_a_doctorRecord[$plan.":labels"]); ?></li></ul>

The join function needs an array. Just the field itself is just a string, but the labels pseudo field is already set up as an array.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Displaying selected list content based on other selected list content

By JLynne77 - April 15, 2011

Okay. This is what I have:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/usr/www/users/mathermd/mather/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($find_a_doctorRecords, $find_a_doctorMetaData) = getRecords(array(
'tableName' => 'find_a_doctor',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$find_a_doctorRecord = @$find_a_doctorRecords[0]; // get first record

// show error message if no matching record is found
if (!$find_a_doctorRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>
-----
<?php foreach ($find_a_doctorRecord['insurance_carriers'] as $carrier):?>
<?php echo $carrier; ?><ul><li>
<?php echo join('</li><li>', $find_a_doctorRecord[$carrier.":values"]); ?></li></ul>
<?php endforeach ?>

In 'insurance_carriers', I have:
aetna|Aetna
affinity|Affinity
cigna|Cigna
emblemhealth|EmblemHealth
empire_blue_cross|Empire Blue Cross

In 'aetna', I have:
Aetna Choice, Choice POS, Managed Choice
Aetna HMO, Elect Choice, Select, Healthy NY
Aetna Indemnity, Traditional Choice
Aetna Medicare Choice PPO
Aetna Medicare HMO
Aetna PPO, Open Choice PPO

The other carrier lists are similar, but with their own set of unique plans.

This is the message that's being produced:
Warning: Invalid argument supplied for foreach() in /usr/www/users/mathermd/mather/doctor-profile.php on line 120

I'm still stumped on how to produce this:
Aetna
<ul>
<li>Aetna Choice, Choice POS, Managed Choice</li>
<li>Aetna Indemnity, Traditional Choice</li>
<li>Aetna Medicare Choice PPO</li>
</ul>
Cigna
<ul>
<li>Cigna PPO</li>
</ul>

-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Displaying selected list content based on other selected list content

By Jason - April 15, 2011

Hi,

What if we tried this:
We can combine our labels and our values into 1 array, so that we only need 1 loop to go through everything we need like this:

<?php $selectedCarriers = array_combine($find_a_doctorRecord['insurance_carriers:values'], $find_a_doctorRecord['insurance_carriers:labels']); ?>

<?php foreach ($selectedCarriers as $plan => $carrier): ?>
<?php echo $carrier; ?>

<?php if ($find_a_doctorRecord[$plan]): ?>

<ul>
<li>
<?php join("</li><li>", $find_a_doctorRecord[$plan.":labels"]);?>
</li>
</ul>

<?php endif ?>

<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Displaying selected list content based on other selected list content

By JLynne77 - April 15, 2011 - edited: April 15, 2011

It's giving back:

Notice: Undefined index: Aetna in /usr/www/users/mathermd/mather/doctor-profile.php on line 123

and repeating that for all the selected carriers.

It looks like the label is being used as the index when it should be the value in order to match the list name for each corresponding carrier. Is something perhaps backwards that we've missed somewhere?

It's value|Label when I add them in the list options in the CMS, right?


EDIT Aha! Thinking there might be an issue with the data itself (because some profiles were displaying properly and some where giving errors), I started going through the different doctors I have in the database for testing.

It goes back to the comment I made in the other thread you were working with me on... how you have to manually adjust every single profile when you make a change to a list. There was a group of doctors that I missed making those changes after I had entered in the value|Label idea for the list.

This is solved. I appreciate your help on this!
-----
~Jessica Sullivan, Crystal Realm Designs.

Re: [Duches77] Displaying selected list content based on other selected list content

By Jason - April 18, 2011

Hi Jessica,

Glad that got fixed for you. As far as always having to update each profile when you change the list, if you're using the value|label format for your list, always try to keep the value part of it the same, that way you can change a label without having to update all of your records. Another good solutions would be to put everything in your list into it's own section. That way you can use the "num" field as a value since this will never change.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/