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)

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

Hello, all,

I have a conundrum, and I've gotten to this.

The client has insurance carriers, and each insurance carrier has insurance plans. The profiles must be searchable by both carrier and plan. What I want to do is display the selected carrier with a bulleted list underneath with the selected plans.

This is what I have so far:
<?php foreach (getListOptions('find_a_doctor', 'insurance_carriers') as $carrier):?>
<?php $carrier = strtolower($carrier); ?>
<?php if ( $find_a_doctorRecord[$carrier] ) { ?><?php echo $find_a_doctorRecord[$carrier] ?><ul><li>
<?php echo join('</li><li>', getListLabels('find_a_doctor', $carrier, $find_a_doctorRecord[$carrier])); ?></li></ul>
<?php } ?>
<?php endforeach ?>

As you can see on the demo page I linked above, I'm getting the selected options to return, but I'm also getting a bunch of undefined errors for the ones that aren't selected.

I have a list of carriers as checkboxes. Then, each carrier has it's own separate list of checkboxes for the plans.

The eventual plan is to enable the search engine to have a drop down of the carriers to search with, and then, if the website user wants to search plans, there will be an optional drop down that will show up with only the plans associated with that carrier for them to select from. The search is step two, however, and I want to make sure I can get everything to display on the individual detail pages first before I worry about making a fancy search engine. However, I want to make sure the ability to make the fancy search engine is there before I get too far into the detail page.

I'm wondering if I'm going about this in the right direction... or if maybe (before I go and enter the hundreds of doctors) there might be a better way.


edit fixed broken link to demo page
-----
~Jessica Sullivan, Crystal Realm Designs.

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: [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/