/**
  * Mapping du patient
  *
  * @param array $data Datas
  *
  * @return array
  */
 function mappingPatient($data)
 {
     $node = $data['patient'];
     $xpath = new CHPrimXPath($node->ownerDocument);
     $personnePhysique = $xpath->queryUniqueNode("hprim:personnePhysique", $node);
     $prenoms = $xpath->getMultipleTextNodes("hprim:prenoms/*", $personnePhysique);
     $elementDateNaissance = $xpath->queryUniqueNode("hprim:dateNaissance", $personnePhysique);
     return array("idSourcePatient" => $data['idSourcePatient'], "idCiblePatient" => $data['idCiblePatient'], "nom" => $xpath->queryTextNode("hprim:nomUsuel", $personnePhysique), "prenom" => $prenoms[0], "naissance" => $xpath->queryTextNode("hprim:date", $elementDateNaissance));
 }
 /**
  * Récupération de l'assuré
  *
  * @param DOMNode  $node      Node
  * @param CPatient $mbPatient Patient
  *
  * @return CPatient
  */
 static function getAssure(DOMNode $node, CPatient $mbPatient)
 {
     $xpath = new CHPrimXPath($node->ownerDocument);
     $immatriculation = $xpath->queryTextNode("hprim:immatriculation", $node);
     $mbPatient->matricule = $immatriculation;
     $mbPatient->assure_matricule = $immatriculation;
     $personne = $xpath->queryUniqueNode("hprim:personne", $node);
     if (!$personne) {
         return $mbPatient;
     }
     $sexe = $xpath->queryAttributNode("hprim:personne", $node, "sexe");
     $sexeConversion = array("M" => "m", "F" => "f");
     $mbPatient->assure_sexe = $sexeConversion[$sexe];
     $mbPatient->assure_nom = $xpath->queryTextNode("hprim:nomUsuel", $personne);
     $prenoms = $xpath->getMultipleTextNodes("hprim:prenoms/*", $personne);
     $mbPatient->assure_prenom = CMbArray::get($prenoms, 0);
     $mbPatient->assure_prenom_2 = CMbArray::get($prenoms, 1);
     $mbPatient->assure_prenom_3 = CMbArray::get($prenoms, 2);
     $mbPatient->assure_naissance = $xpath->queryTextNode("hprim:naissance", $personne);
     $elementDateNaissance = $xpath->queryUniqueNode("hprim:dateNaissance", $personne);
     $mbPatient->assure_naissance = $xpath->queryTextNode("hprim:date", $elementDateNaissance);
     $mbPatient->rang_beneficiaire = $xpath->queryTextNode("hprim:lienAssure", $node);
     $mbPatient->qual_beneficiaire = CValue::read(CPatient::$rangToQualBenef, $mbPatient->rang_beneficiaire);
     return $mbPatient;
 }
 /**
  * Return person
  *
  * @param DOMNode   $node       Node
  * @param CMbObject $mbPersonne Person
  *
  * @return CMbObject|CMediusers|CPatient
  */
 static function getPersonne(DOMNode $node, CMbObject $mbPersonne)
 {
     $xpath = new CHPrimXPath($node->ownerDocument);
     $civilite = $xpath->queryAttributNode("hprim:civiliteHprim", $node, "valeur");
     $civiliteHprimConversion = array("mme" => "mme", "mlle" => "mlle", "mr" => "m", "dr" => "dr", "pr" => "pr", "bb" => "enf", "enf" => "enf");
     $nom = $xpath->queryTextNode("hprim:nomUsuel", $node);
     $prenoms = $xpath->getMultipleTextNodes("hprim:prenoms/*", $node);
     $adresses = $xpath->queryUniqueNode("hprim:adresses", $node);
     $adresse = $xpath->queryUniqueNode("hprim:adresse", $adresses);
     $ligne = $xpath->getMultipleTextNodes("hprim:ligne", $adresse, true);
     $ville = $xpath->queryTextNode("hprim:ville", $adresse);
     $cp = $xpath->queryTextNode("hprim:codePostal", $adresse);
     if ($cp) {
         $cp = preg_replace("/[^0-9]/", "", $cp);
     }
     $telephones = $xpath->getMultipleTextNodes("hprim:telephones/*", $node);
     $email = $xpath->getFirstTextNode("hprim:emails/*", $node);
     if ($mbPersonne instanceof CPatient) {
         if ($civilite) {
             $mbPersonne->civilite = $civiliteHprimConversion[$civilite];
         } else {
             if ($mbPersonne->civilite == null) {
                 $mbPersonne->civilite = "guess";
             }
         }
         $mbPersonne->nom = $nom;
         $mbPersonne->nom_jeune_fille = $xpath->queryTextNode("hprim:nomNaissance", $node);
         $mbPersonne->prenom = CMbArray::get($prenoms, 0);
         $mbPersonne->prenom_2 = CMbArray::get($prenoms, 1);
         $mbPersonne->prenom_3 = CMbArray::get($prenoms, 2);
         $mbPersonne->adresse = $ligne;
         $mbPersonne->ville = $ville;
         $mbPersonne->pays_insee = $xpath->queryTextNode("hprim:pays", $adresse);
         $pays = new CPaysInsee();
         $pays->numerique = $mbPersonne->pays_insee;
         $pays->loadMatchingObject();
         $mbPersonne->pays = $pays->nom_fr;
         $mbPersonne->cp = $cp;
         $tel1 = $tel2 = null;
         if (isset($telephones[0])) {
             $tel1 = $telephones[0];
         }
         if (isset($telephones[1])) {
             $tel2 = $telephones[1];
         }
         $mbPersonne->tel = $tel1 != $mbPersonne->tel2 && strlen($tel1) <= 10 ? $tel1 : null;
         $mbPersonne->tel2 = $tel2 != $mbPersonne->tel && strlen($tel2) <= 10 ? $tel2 : null;
         if (strlen($tel1) > 10) {
             $mbPersonne->tel_autre = $tel1;
         }
         if (strlen($tel2) > 10) {
             $mbPersonne->tel_autre = $tel2;
         }
         $mbPersonne->email = $email;
     } elseif ($mbPersonne instanceof CMediusers) {
         $mbPersonne->_user_last_name = $nom;
         $mbPersonne->_user_first_name = CMbArray::get($prenoms, 0);
         $mbPersonne->_user_email = $email;
         $mbPersonne->_user_phone = CMbArray::get($telephones, 0);
         $mbPersonne->_user_adresse = $ligne;
         $mbPersonne->_user_cp = $cp;
         $mbPersonne->_user_ville = $ville;
     }
     return $mbPersonne;
 }