Example #1
0
<?php

/**
 * $Id: ajax_clean_facture.php 19223 2013-05-21 14:44:04Z aurelie17 $
 *
 * @package    Mediboard
 * @subpackage dPfacturation
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 19223 $
 */
CCanDo::checkAdmin();
$where = array();
$where["object_class"] = " = 'CConsultation'";
$where["facture_class"] = " = 'CFactureCabinet'";
$group = "object_id HAVING COUNT(object_id) >= 2";
$liaison = new CFactureLiaison();
$liaisons = $liaison->loadList($where, null, null, $group);
foreach ($liaisons as $lien) {
    $fact = $lien->loadRefFacture();
    $fact->loadRefPatient();
    $fact->loadRefPraticien();
    $fact->loadRefsObjects();
    $fact->loadRefsReglements();
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("liaisons", $liaisons);
$smarty->display("inc_configure_resolutions.tpl");
Example #2
0
 /**
  * Suppression d'une consult dans la facture
  *
  * @return void
  **/
 function cancelConsult()
 {
     if ($this->_consult_id) {
         $this->loadRefsObjects();
         $nb_objets = count($this->_ref_consults) + count($this->_ref_sejours);
         if ($nb_objets == 1) {
             if ($msg = $this->delete()) {
                 return $msg;
             }
         } else {
             $liaison = new CFactureLiaison();
             $liaison->facture_id = $this->_id;
             $liaison->facture_class = $this->_class;
             $liaison->object_class = "CConsultation";
             $liaison->object_id = $this->_consult_id;
             $liaison->loadMatchingObject();
             if ($msg = $liaison->delete()) {
                 return $msg;
             }
         }
     }
 }
Example #3
0
 /**
  * @see parent::store()
  */
 function store()
 {
     $this->completeField("entree_reelle", "entree", "patient_id", "type_pec", "grossesse_id", "mode_sortie");
     /** @var CSejour $old */
     $old = $this->loadOldObject();
     // Vérification de la validité des codes CIM
     if ($this->DP != null) {
         $dp = CCodeCIM10::get($this->DP);
         if (!$dp->exist) {
             CAppUI::setMsg("Le code CIM saisi n'est pas valide", UI_MSG_WARNING);
             $this->DP = "";
         }
     }
     if ($this->DR != null) {
         $dr = CCodeCIM10::get($this->DR);
         if (!$dr->exist) {
             CAppUI::setMsg("Le code CIM saisi n'est pas valide", UI_MSG_WARNING);
             $this->DR = "";
         }
     }
     // Mode de sortie normal par défaut si l'autorisation de sortie est réalisée
     if ($this->conf("specified_output_mode") && !$this->mode_sortie && $this->fieldModified("confirme")) {
         $this->mode_sortie = "normal";
     }
     // Annulation de l'établissement de transfert si le mode de sortie n'est pas transfert
     if (null !== $this->mode_sortie) {
         if ("transfert" != $this->mode_sortie) {
             $this->etablissement_sortie_id = "";
         }
         if ("mutation" != $this->mode_sortie) {
             $this->service_sortie_id = "";
         }
     }
     // Mise à jour du type PEC si vide
     if (!$this->_id && !$this->type_pec) {
         $this->type_pec = $this->grossesse_id ? "O" : "M";
     }
     // Annulation de la sortie réelle si on annule le mode de sortie
     if ($this->mode_sortie === "") {
         $this->sortie_reelle = "";
     }
     // Annulation de l'établissement de provenance si le mode d'entrée n'est pas transfert
     if ($this->fieldModified("mode_entree")) {
         if ("7" != $this->mode_entree) {
             $this->etablissement_entree_id = "";
         }
         if ("6" != $this->mode_entree) {
             $this->service_entree_id = "";
         }
     }
     // Passage au mode transfert si on value un établissement de provenance
     if ($this->fieldModified("etablissement_entree_id")) {
         if ($this->etablissement_entree_id != null) {
             $this->mode_entree = 7;
         }
     }
     // Passage au mode mutation si on value un service de provenance
     if ($this->fieldModified("service_entree_id")) {
         if ($this->service_entree_id != null) {
             $this->mode_entree = 6;
         }
     }
     $patient_modified = $this->fieldModified("patient_id");
     // Si le patient est modifié et qu'il y a des consultations, on cascade les consultations
     if (!$this->_forwardRefMerging && $this->sejour_id && $patient_modified) {
         /** @var CConsultation[] $consultations */
         $consultations = $this->loadBackRefs("consultations");
         foreach ($consultations as $_consult) {
             $_consult->_sync_consults_from_sejour = true;
             $_consult->patient_id = $this->patient_id;
             if ($msg = $_consult->store()) {
                 return $msg;
             }
         }
     }
     // Pour un séjour non annulé, mise à jour de la date de décès du patient
     // suivant le mode de sortie
     if (!$this->annule) {
         $patient = new CPatient();
         $patient->load($this->patient_id);
         if ($this->fieldModified("mode_sortie")) {
             if ("deces" == $this->mode_sortie) {
                 $patient->deces = $this->_date_deces;
             } else {
                 if ($this->_old->mode_sortie == "deces") {
                     $patient->deces = "";
                 }
             }
         }
         // On verifie que le champ a été modifié pour faire le store (sinon probleme lors de la fusion de patients)
         if ($patient->fieldModified("deces")) {
             // Ne pas faire de return $msg ici, car ce n'est pas "bloquant"
             $patient->store();
         }
     }
     // Si annulation possible que par le chef de bloc
     if (CAppUI::conf("dPplanningOp COperation cancel_only_for_resp_bloc") && $this->fieldModified("annule", 1) && $this->entree_reelle && !CModule::getCanDo("dPbloc")->edit) {
         foreach ($this->loadRefsOperations() as $_operation) {
             if ($_operation->rank) {
                 CAppUI::setMsg("Impossible de sauvegarder : une des interventions du séjour est validée.\nContactez le responsable de bloc", UI_MSG_ERROR);
                 return null;
             }
         }
     }
     // On fixe la récusation si pas définie pour un nouveau séjour
     if (!$this->_id && ($this->recuse === "" || $this->recuse === null)) {
         $this->recuse = CAppUI::conf("dPplanningOp CSejour use_recuse") ? -1 : 0;
     }
     // no matter of config, if sejour is "urgence" type: recusation 0
     if ($this->type == "urg") {
         $this->recuse = 0;
     }
     // Si gestion en mode expert de l'isolement
     if (CAppUI::conf("dPplanningOp CSejour systeme_isolement") == "expert") {
         $this->isolement_date = $this->_isolement_date !== $this->entree && $this->isolement ? $this->_isolement_date : "";
         if (!$this->isolement) {
             $this->isolement_fin = "";
         }
     }
     $facture = null;
     if (CModule::getActive("dPfacturation") && CAppUI::conf("dPplanningOp CFactureEtablissement use_facture_etab")) {
         // Création de la facture de sejour
         $this->loadRefsFactureEtablissement();
         $facture = $this->_ref_last_facture;
         if (!$facture->_id) {
             $facture->ouverture = CMbDT::date();
         }
         if (CAppUI::conf("dPfacturation CFactureEtablissement use_temporary_bill")) {
             $facture->temporaire = 1;
         }
         $facture->group_id = $this->group_id;
         $facture->patient_id = $this->patient_id;
         $facture->praticien_id = $this->praticien_id;
         $facture->type_facture = $this->_type_sejour;
         $facture->dialyse = $this->_dialyse;
         $facture->cession_creance = $this->_cession_creance;
         $facture->statut_pro = $this->_statut_pro;
         $facture->assurance_maladie = $this->_assurance_maladie;
         $facture->assurance_accident = $this->_assurance_accident;
         $facture->rques_assurance_accident = $this->_rques_assurance_accident;
         $facture->rques_assurance_maladie = $this->_rques_assurance_maladie;
         //Store de la facture
         if ($msg = $facture->store()) {
             return $msg;
         }
     }
     $this->completeField("mode_entree_id");
     if ($this->mode_entree_id) {
         /** @var CModeEntreeSejour $mode */
         $mode = $this->loadFwdRef("mode_entree_id");
         $this->mode_entree = $mode->mode;
     }
     $this->completeField("mode_sortie_id");
     if ($this->mode_sortie_id) {
         /** @var CModeSortieSejour $mode */
         $mode = $this->loadFwdRef("mode_sortie_id");
         $this->mode_sortie = $mode->mode;
     }
     // Gestion du tarif et precodage des actes
     if ($this->_bind_tarif && $this->_id) {
         $this->getActeExecution();
         if ($msg = $this->bindTarif()) {
             return $msg;
         }
     }
     // Si on change la grossesse d'un séjour, il faut remapper les naissances éventuelles
     $change_grossesse = $this->fieldModified("grossesse_id");
     /** @var CNaissance[] $naissances */
     $naissances = array();
     if ($change_grossesse) {
         $naissances = $old->loadRefGrossesse()->loadRefsNaissances();
     }
     // Sectorisation Rules
     $this->getServiceFromSectorisationRules();
     if ($this->fieldModified("completion_sortie") && $this->completion_sortie && !$this->reception_sortie) {
         $this->reception_sortie = $this->completion_sortie;
     }
     if ($this->fieldModified("reception_sortie", "") && !$this->completion_sortie) {
         $this->completion_sortie = "";
     }
     $this->getUFs();
     $eai_sender_guid = $this->_eai_sender_guid;
     // On fait le store du séjour
     if ($msg = parent::store()) {
         return $msg;
     }
     $this->_eai_sender_guid = $eai_sender_guid;
     if ($change_grossesse) {
         foreach ($naissances as $_naissance) {
             $_naissance->grossesse_id = $this->grossesse_id;
             if ($msg = $_naissance->store()) {
                 return $msg;
             }
         }
     }
     // Changement des liaisons de prestations si besoin
     // Seulement par rapport à l'entrée
     if (CAppUI::conf("dPhospi prestations systeme_prestations", CGroups::loadCurrent()) == "expert") {
         $decalage = CMbDT::daysRelative($old->entree, $this->entree);
         if ($decalage != 0) {
             $liaisons = $this->loadBackRefs("items_liaisons");
             foreach ($liaisons as $_liaison) {
                 $_liaison->date = CMbDT::date("{$decalage} days", $_liaison->date);
                 if ($msg = $_liaison->store()) {
                     return $msg;
                 }
             }
         }
     }
     if (CModule::getActive("dPfacturation") && CAppUI::conf("dPplanningOp CFactureEtablissement use_facture_etab")) {
         if (count($this->_ref_factures) == 0) {
             $liaison = new CFactureLiaison();
             $liaison->object_id = $this->_id;
             $liaison->object_class = $this->_class;
             $liaison->facture_id = $facture->_id;
             $liaison->facture_class = "CFactureEtablissement";
             //Store de la table de liaison entre facture et séjour
             if ($msg = $liaison->store()) {
                 return $msg;
             }
         }
     }
     if ($patient_modified) {
         $list_backrefs = array("contextes_constante", "deliveries", "consultations");
         foreach ($list_backrefs as $_backname) {
             /** @var CConstantesMedicales[]|CProductDelivery[]|CConsultation[] $backobjects */
             $backobjects = $this->loadBackRefs($_backname);
             if (!$backobjects) {
                 continue;
             }
             foreach ($backobjects as $_object) {
                 if ($_object->patient_id == $this->patient_id) {
                     continue;
                 }
                 $_object->patient_id = $this->patient_id;
                 if ($_object instanceof CConsultation) {
                     $_object->_skip_count = true;
                 }
                 if ($msg = $_object->store()) {
                     CAppUI::setMsg($msg, UI_MSG_WARNING);
                 }
             }
         }
     }
     // Cas d'une annulation de séjour
     if ($this->annule) {
         // Suppression des affectations
         if ($msg = $this->delAffectations()) {
             return $msg;
         }
         // Suppression des opérations
         if ($msg = $this->cancelOperations()) {
             return $msg;
         }
         // Annulation des mouvements
         if ($msg = $this->cancelMovements()) {
             return $msg;
         }
     }
     // Synchronisation des affectations
     if (!$this->_no_synchro && !($this->type == "seances")) {
         $this->loadRefsAffectations();
         $firstAff =& $this->_ref_first_affectation;
         $lastAff =& $this->_ref_last_affectation;
         // Cas où on a une premiere affectation différente de l'heure d'admission
         if ($firstAff->_id && $firstAff->entree != $this->_entree) {
             $firstAff->entree = $this->_entree;
             $firstAff->_no_synchro = 1;
             $firstAff->store();
         }
         // Cas où on a une dernière affectation différente de l'heure de sortie
         if ($lastAff->_id && $lastAff->sortie != $this->_sortie) {
             $lastAff->sortie = $this->_sortie;
             $lastAff->_no_synchro = 1;
             $lastAff->store();
         }
         //si le sejour a une sortie ==> compléter le champ effectue de la derniere affectation
         if ($lastAff->_id) {
             $this->_ref_last_affectation->effectue = $this->sortie_reelle ? 1 : 0;
             $this->_ref_last_affectation->store();
         }
     }
     // try to assign an affectation
     $this->createAffectationLitUnique();
     $this->createAffectationService();
     // Génération du NDA ?
     if ($this->_generate_NDA) {
         // On ne synchronise pas un séjour d'urgences qui est un reliquat
         $rpu = $this->loadRefRPU();
         if ($rpu && $rpu->mutation_sejour_id && $rpu->sejour_id != $rpu->mutation_sejour_id) {
             return null;
         }
         if ($msg = $this->generateNDA()) {
             return $msg;
         }
     }
     return null;
 }