Avatar of Bruce Gust
Bruce Gust
Flag for United States of America asked on

What is $unrolled_data?

Here's the function I'm attempting to deconstruct:

protected function pipeToArray($pipe_delim){

        $lines = explode("\n", str_replace("\r\n","\n",$pipe_delim));

        //Subsets of each statement
        $statement = array(
                'statement' => array(),
                'client' => array(),
                'guarantor' => array(),
                'patient' => array(),
                'unrolled_data' => array(),
                'rolled_data' => array(),
                'paymentplan_options' => array(),
                'paymentplan' =>array()
            );

        //Loop through the lines
        foreach ($lines as $raw_line) {

            //Split into cells
            $line = explode("|",$raw_line);

            switch ($line[0]) {
                  case 'N6' :
                    //Unrolled Account Information
                    $index = count($statement['unrolled_data']);
                    foreach($statement['unrolled_data'] as $i => $enc){
                        if($enc['encounterid'] === $line[1]) {
                            $index = $i;
                            continue;
                        }
                    }

                    $statement['unrolled_data'][$index]['txns'][] = array(

                        //'encounterid'   => $line[1],
                        //'provider_name' => $line[2],
                        'date'          => $line[3],
                        'type'          => $line[4],
                        'description'   => $line[5],
                        'amount'        => $line[6]
                        //'left_to_pay'   => $line[7]

                    );


                    break;
                case 'A6' :
                    //Rolled Account Information
                    $statement['rolled_data'][] = array(

                        'encounterid'   => $line[1],
                        'provider'      => $line[2],
                        'description'   => $line[3],
                        'date'          => $line[4],
                        'charged'       => $line[5],
                        'adjustments'   => $line[6],
                        'payments'      => $line[7],
                        'left_to_pay'   => $line[8]

                    );
                    break;
                }
        }
        return $statement;
    }

    /**
     * Return the pdf buffer string
     * @return String pdf buffer
     * @todo THESE ARE BEING HARDCODED TO TEMPLATEIDS... THIS SHOULD BE DONE ELSEWHERE, IN A BUILDER/FACTORY PERHAPS.
     */
    protected function toPDF(){
        if($this->statement_data['statement']['templateid'] == 4) {
            $image = new StandardStatementPDFGenerator($this);
        } else if ($this->statement_data['statement']['templateid'] == 9) {
            $image = new LetterStatementPDFGenerator($this);
        } else {
            //This is a "Fail Gracefully" measure. We haven't generated a statement
            //without a templateid since July 2013, so we shouldn't hit this moving
            //forward.
            $image = new StandardStatementPDFGenerator($this);
        }

        return $image->getStream();

    }

Open in new window


First part of my question: "unrolled_data" is not a column heading in a table. It is simply the name that's being given to a subset I'm about to create, correct?

Second part of my question: Beginning at line 26, I've got this:

//Unrolled Account Information
                    $index = count($statement['unrolled_data']);
                    foreach($statement['unrolled_data'] as $i => $enc){
                        if($enc['encounterid'] === $line[1]) {
                            $index = $i;
                            continue;
                        }
                    }

Open in new window


What's going on here?

$index=count($statement['unrolled_data']) // how can you count an array that has yet to be processed?

foreach($statement['unrolled_data'] as $I->$enc){ //where did $enc come from and what's happening here?

For the sake of clarity and brevity, I've attempted to streamline the function that I'm working on. What you see above is a portion of the actual code. I've got that below, just in case there's something missing from the puzzle that you need.

Bottom line: I'm trying to understand how "unrolled_data" is being defined and calculated.

What do you think?
PHP

Avatar of undefined
Last Comment
Bruce Gust

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Guy Hengel [angelIII / a3]

$index=count($statement['unrolled_data']) // how can you count an array that has yet to be processed?

remember that you are inside a loop, so it is being filled by prdvious iterations. on the first one, it will be 0 indeed.
Guy Hengel [angelIII / a3]

so, how is it populated?
by lines where the first cell is 'N6':

switch ($line[0]) { case 'N6' :
...
Bruce Gust

ASKER
Guy, my head hurts, trying to understand all of this, but let me try to explain this back to you:

I'm looping through a dataset. Every time the system registers the N6 cell, it's doing a couple of things:

In a regular array, you've got something like $line[1]. The "key" is "1" and the value is...? What?

I'm looking at $enc['encounter['id'] and it looks as though there's an if statement happening there, but what's happening?

Thanks for spelling this out for me...
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ray Paseur

Man pages:
http://php.net/manual/en/control-structures.foreach.php
http://php.net/manual/en/function.count.php

This code is nearly incomprehensible, cannot be tested, and should be refactored.  Nobody writes this kind of spaghetti any more, at least not since the last century.  One of the problems I see here is that the behavior of the code is tightly coupled to the content of the data.  But because of the way this code is written you cannot provide mock-data.  So a logical step in trying to discern behavior would be to look at the data.  You can do that with var_dump().
http://php.net/manual/en/function.var-dump.php
SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Olaf Doschke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Guy Hengel [angelIII / a3]

lol, I love Lasagne :-)
Bruce Gust

ASKER
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.