public function getConstantsActivityData($item, $totalMen, $totalWomen) { if ($item->getType() == 5) { $options = Item5Enum::getConstants(); $defaultKey = 2; } else { $options = Item6Enum::getConstants(); $defaultKey = 2; } $optionsArray = array(); foreach ($options as $option) { $optionArray = array(); $optionArray["1"] = 0; $optionArray["2"] = 0; $optionsArray[$option] = $optionArray; } $sql = "select p.gender, pi.value, count(*) as 'counter'\n from tecnotek_patient_items pi\n left join tecnotek_patients p on pi.patient_id = p.id\n where p.is_graduate = false and pi.item_id = " . $item->getId() . "\n group by p.gender, value;\n "; $stmt = $this->getEntityManager()->getConnection()->prepare($sql); $stmt->execute(); $records = $stmt->fetchAll(); foreach ($records as $row) { $optionsArray[$row['value']][$row['gender']] = $row['counter']; } $totalPatients = $totalMen + $totalWomen; $totalNonDefaultMen = 0; $totalNonDefaultWomen = 0; $totalNonDefaultAll = 0; foreach (array_keys($optionsArray) as $key) { $optionsArray[$key]['percMen'] = 100 * $optionsArray[$key]['1'] / $totalMen; $optionsArray[$key]['percWomen'] = 100 * $optionsArray[$key]['2'] / $totalWomen; $totalAll = $optionsArray[$key]['1'] + $optionsArray[$key]['2']; $optionsArray[$key]['all'] = $totalAll; $optionsArray[$key]['percAll'] = 100 * $totalAll / $totalPatients; if ($key != $defaultKey) { $totalNonDefaultMen += $optionsArray[$key]['1']; $totalNonDefaultWomen += $optionsArray[$key]['2']; } } $totalNonDefaultAll = $totalNonDefaultMen + $totalNonDefaultWomen; $optionsArray[$defaultKey]['1'] = $totalMen - $totalNonDefaultMen; $optionsArray[$defaultKey]['2'] = $totalWomen - $totalNonDefaultWomen; $optionsArray[$defaultKey]['all'] = $totalPatients - $totalNonDefaultAll; $optionsArray[$defaultKey]['percMen'] = 100 * ($totalMen - $totalNonDefaultMen) / $totalMen; $optionsArray[$defaultKey]['percWomen'] = 100 * ($totalWomen - $totalNonDefaultWomen) / $totalWomen; $optionsArray[$defaultKey]['percAll'] = 100 * ($totalPatients - $totalNonDefaultAll) / $totalPatients; return $optionsArray; }
public function renderItem(\Tecnotek\Bundle\AsiloBundle\Entity\ActivityItem $item, $patientValues, $cataloges) { $html = ""; switch ($item->getType()) { case 1: //YesNo Select $value = "0"; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $html .= '<select class="item-element" item-id="' . $item->getId() . '">'; $html .= '<option value="1" ' . ($value == "1" ? 'selected="selected"' : '') . '>' . $this->translator->trans('yes') . '</option>'; $html .= '<option value="0" ' . ($value == "0" ? 'selected="selected"' : '') . '>' . $this->translator->trans('no') . '</option>'; $html .= '</select>'; break; case 2: //Entities Checkboxes $value = ""; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $entities = array(); if (sizeof($cataloges) > 0) { $entities = $cataloges[$item->getReferencedEntity()]; } foreach ($entities as $entity) { $html .= '<input type="checkbox" class="item-element" item-id="' . $item->getId() . '"' . (strpos($value, '[' . $entity->getId() . ']') !== false ? 'checked="checked"' : '') . ' value="' . $entity->getId() . '"> ' . $entity . ' <br> '; } break; case 3: // TextArea $value = ""; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $html .= '<textarea class="item-element" item-id="' . $item->getId() . '">' . $value . '</textarea>'; break; case 4: // Entities Select $value = ""; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $entities = array(); if (sizeof($cataloges) > 0) { $entities = $cataloges[$item->getReferencedEntity()]; } $html .= '<select class="item-element" item-id="' . $item->getId() . '">'; foreach ($entities as $entity) { $html .= '<option value="' . $entity->getId() . '"' . ($value == $entity->getId() ? ' selected="selected" ' : '') . '>' . $entity . '</option>'; } $html .= '</select>'; break; case 5: //Select from Enum $value = "2"; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $options = Item5Enum::getConstants(); $html = '<select class="item-element" item-id="' . $item->getId() . '">'; foreach ($options as $option) { $html .= '<option value="' . $option . '"' . ($value == $option ? 'selected="selected"' : '') . '>' . $this->translator->trans('item.5.enum.option.' . $option) . '</option>'; } $html .= '</select>'; break; case 6: //Select from Enum $value = "2"; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $options = Item6Enum::getConstants(); $html = '<select class="item-element" item-id="' . $item->getId() . '">'; foreach ($options as $option) { $html .= '<option value="' . $option . '"' . ($value == $option ? 'selected="selected"' : '') . '>' . $this->translator->trans('item.5.enum.option.' . $option) . '</option>'; } $html .= '</select>'; break; case 7: // Hour $value = "0"; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $html .= '<div class="input-group date timepicker">'; $html .= ' <input type="text" class="form-control timeinput" item-id="' . $item->getId() . '" value="' . $value . '"/>'; $html .= ' <span class="input-group-addon">'; $html .= ' <span class="glyphicon glyphicon-time"></span>'; $html .= ' </span>'; $html .= '</div>'; break; case 8: //Number Input $value = ""; if (array_key_exists($item->getId(), $patientValues)) { $value = $patientValues[$item->getId()]; } $html .= '<input class="timeinput" type="number" class="item-element" item-id="' . $item->getId() . '" value="' . $value . '">'; break; break; default: $html .= 'Tipo desconocido: ' . $item->getType(); break; } $html .= ""; return $html; }