*
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 22475 $
 */
CCanDo::checkAdmin();
CApp::setTimeLimit(600);
$count_min = CValue::post("count_min", 1);
$merge_dates = CValue::post("merge_dates", 0);
$dry_run = CValue::post("dry_run");
// Ignore handlers
global $dPconfig;
$dPconfig["object_handlers"] = array();
CMbObject::$useObjectCache = false;
$correspondant = new CCorrespondantPatient();
$fields = array_keys($correspondant->getPlainFields());
$spec = $correspondant->_spec;
// Don't group by key... of course
CMbArray::removeValue($spec->key, $fields);
// Don't group by date
if ($merge_dates) {
    CMbArray::removeValue("date_debut", $fields);
}
$select = $fields;
$select["TOTAL"] = "COUNT(*)";
$select["IDS"] = "GROUP_CONCAT(CAST({$spec->key} AS CHAR))";
$orderby = "TOTAL DESC";
$count_min = max(1, $count_min);
$having = array("TOTAL" => $spec->ds->prepare("> ?", $count_min));
Esempio n. 2
0
$count = CValue::post("count");
$callback = CValue::post("callback");
$date = CMbDT::date();
CApp::setTimeLimit(600);
CApp::setMemoryLimit("512M");
CMbObject::$useObjectCache = false;
$file_import = fopen(CAppUI::conf("root_dir") . "/tmp/rapport_import_patient_{$date}.txt", "a");
importFile(CAppUI::conf("dPpatients imports pat_csv_path"), $start, $count, $file_import);
fclose($file_import);
$start += $count;
file_put_contents(CAppUI::conf("root_dir") . "/tmp/import_patient.txt", "{$start};{$count}");
if ($callback) {
    CAppUI::js("{$callback}({$start},{$count})");
}
echo "<tr><td colspan=\"2\">MEMORY: " . memory_get_peak_usage(true) / (1024 * 1024) . " MB" . "</td>";
CMbObject::$useObjectCache = true;
CApp::rip();
/**
 * import the patient file
 *
 * @param string   $file        path to the file
 * @param int      $start       start int
 * @param int      $count       number of iterations
 * @param resource $file_import file for report
 *
 * @return null
 */
function importFile($file, $start, $count, $file_import)
{
    $fp = fopen($file, 'r');
    $csv_file = new CCSVFile($fp);
 function handle($ack, CMbObject $object, $data)
 {
     // Traitement du message des erreurs
     $comment = "";
     $exchange_hpr = $this->_ref_exchange_hpr;
     $exchange_hpr->_ref_sender->loadConfigValues();
     $sender = $exchange_hpr->_ref_sender;
     $this->_ref_sender = $sender;
     CMbObject::$useObjectCache = false;
     // Rejets partiels du message
     $errors = array();
     if (isset($data["REG"])) {
         $regs = $data["REG"];
     } else {
         $regs = $data["//REG"];
     }
     // Récupération des règlements
     foreach ($regs as $_REG) {
         $sejour = new CSejour();
         $NDA = $this->getNDA($_REG);
         $user_reg = $this->getUser($_REG);
         $segment_row = $this->getREGSegmentRow($_REG);
         // Recherche si on retrouve le séjour
         if (!$this->admitFound($NDA, $sejour)) {
             $errors[] = $this->addError("P", null, array("REG", $segment_row, array($NDA, $user_reg)), null, $NDA, "I", CAppUI::tr("CHL7EventADT-P-01", $NDA));
             continue;
         }
         $consults = array();
         $consultations = $sejour->loadRefsConsultations();
         // Sélection des consultations éligibles
         foreach ($consultations as $_consult) {
             $user = $_consult->loadRefPraticien();
             if ($user_reg) {
                 if ($user->adeli == $user_reg) {
                     $consults[$_consult->_id] = $_consult;
                 }
                 continue;
             }
         }
         // Si une seule consultation donnée
         if (!count($consults) && count($consultations) == 1) {
             $consults = $consultations;
         }
         $consultation = new CConsultation();
         // On essaie d'en trouver une qui ne soit pas acquittée
         foreach ($consults as $_consult) {
             $facture = $_consult->loadRefFacture();
             if (!$facture->patient_date_reglement) {
                 $consultation = $_consult;
                 break;
             }
         }
         // Aucune consultation trouvée
         if (!$consultation->_id && count($consults) > 0) {
             $consultation = end($consults);
         }
         if (!$consultation || !$consultation->_id) {
             $errors[] = $this->addError("P", null, array("REG", $segment_row, array($NDA, $user_reg)), null, $NDA, "I", CAppUI::tr("CHL7EventADT-P-02"));
             continue;
         }
         $facture = $consultation->loadRefFacture();
         if (!$facture->_id) {
             /* @TODO avant de transposer la création de la facture dans le store */
             $facture = $consultation->createFactureConsult();
             if (!$facture->_id) {
                 $errors[] = $this->addError("P", null, array("REG", $segment_row, array($NDA, $user_reg)), null, $NDA, "I", CAppUI::tr("CHL7EventADT-P-03"));
                 continue;
             }
         }
         // Recherche d'un reglèment par tag + idex (nom fichier - id reg)
         $idex_value = $NDA . "_" . $segment_row;
         $tag = CHprim21::getTag($sender->group_id);
         $idex = CIdSante400::getMatch("CReglement", $tag, $idex_value);
         // Mapping des règlements
         $return_payment = $this->mapAndStorePayment($_REG, $facture, $idex);
         if (is_string($return_payment)) {
             $errors[] = $this->addError("P", null, array("REG", $segment_row, array($NDA, $user_reg)), null, $NDA, "I", CAppUI::tr("CHL7EventADT-P-04", $return_payment));
             continue;
         }
     }
     if (count($errors) > 0) {
         return $exchange_hpr->setAckP($ack, $errors, $object);
     }
     return $exchange_hpr->setAckI($ack, null, $object);
 }