<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE FreeMedForms>

<FreeMedForms>

  <formdescription>
    <!-- Non translatable values -->
    <authors>Eric Maeker, MD</authors>
    <version>0.9.0</version>
    <fmfv>0.8.4</fmfv>
    <cdate>2012-01-01</cdate>
    <lmdate>2013-04-18</lmdate>
    <icon>__theme__/identity.png</icon>
    <weblink></weblink>
    <bibliography/>

    <!-- Translatable values -->
    <license>GPLv3</license>
    <description lang="fr">Identité complète</description>
    <description lang="xx">Full identity</description>
    <category lang="xx">Generic tools</category>
    <category lang="fr">Outils généraux</category>
    <specialties lang="fr">Outils</specialties>
    <specialties lang="xx">Tools</specialties>

    <updateinfo>
      <updateversion from="0.8.2" to="0.8.4">
        <text lang="fr">
        Gestion de la représentation des données patient (nom du propriétaire du NSS)
        Par défaut, le patient est propriétaire du numéro de sécurité sociale.
        Ajout des masques HTML d'exportation et d'impression plus modernes.
        </text>
        Managing the patient data representation for the SocialNumber owner full name
        Adding modern HTML export and print masks.
        <text lang="xx">
        </text>
      </updateversion>
      <updateversion from="0.8.0" to="0.8.2">
        <text lang="fr">
        Ajout du formulaire de la personne de confiance&lt;br />
        Utilisation des DetailsWidget pour limiter la taille de la vue&lt;br />
        Ajout de l'auto-remplissage du formulaire de déclaration du médecin traitant.
        Cette fonctionnalité nécessite l'installation d'un paquet de données
        disponible auprès de l'association asso.freemedforms.com&lt;br />
        </text>
        <text lang="xx">
        Adding new trusted person subform&lt;br />
        Usign DetailsWidgets to minimize the view size&lt;br />
        </text>
      </updateversion>
      <updateversion from="0.7.0" to="0.8.0">
        <text lang="fr">
        Ajout du numéro de téléphone mobile&lt;br />
        Bouton 'envoyer un courriel' connecté&lt;br />
        N'affiche pas l'entête du formulaire&lt;br />
        Défini le formulaire comme formulaire d'identité dans l'application&lt;br />
        Ajout des données professionnelles&lt;br />
        </text>
        <text lang="xx">
        Adding the mobile phone number&lt;br />
        'Send mail' button is now connected&lt;br />
        Hide the form header&lt;br />
        Define this form as the application identity form&lt;br />
        Adding professional data&lt;br />
        </text>
      </updateversion>
    </updateinfo>

  </formdescription>

  <MedForm name="Subs::Tools::IdentitySynopsis" uifilename="./ui/xx/identity.ui">
    <label lang="xx">Identity</label>
    <label lang="fr">Identité</label>
    <options>NoEpisode</options>
    <icon>__theme__/identity.png</icon>

      <MedForm name="Subs::Tools::Identity" uifilename="./ui/xx/identity.ui" isidentity="true">
        <label lang="xx">Identity</label>
        <label lang="fr">Identité</label>
        <options>unique;UseFormNameAsNameSpace;HideHeaderOnUniqueEpisode</options>
        <icon>__theme__/identity.png</icon>
        <file type="htmlprintmask">./html/xx/padtools_mask.html</file>
        <file type="htmlexportmask">./html/xx/padtools_mask.html</file>

        <Item type="detailswidget" name="IdentityDetails" uifilename="./ui/xx/ident.ui">
            <uilink label="" widget="" layout="identityLayout"/>
            <label lang="xx">Identity and address</label>
            <label lang="fr">Identité et adresse</label>
            <label lang="de">Identität und Anschrift</label>
            <label lang="es">Identidad y dirección</label>
            <options>SummaryFontBold;expanded</options>

            <Item type="identity" name="IdentityWidget">
                <uilink label="" widget="" layout="identityIncludeLayout"/>
                <label lang="xx">Full Identity</label>
                <label lang="fr">Identité</label>
                <options>with-address;with-photo</options>
            </Item>
        </Item>

        <Item type="detailswidget" name="FrDetails" uifilename="./ui/xx/social.ui">
          <uilink label="" widget="" layout="identityLayout"/>
          <country>FR</country>
          <label lang="xx">Social insurance</label>
          <label lang="fr">Sécurité sociale</label>
          <extralabel>{Subs::Tools::Identity::FrGroup::NSS}</extralabel>
          <column>1</column>
          <options>DontPrintEmptyValues;SummaryFontBold</options>

          <Item type="frenchnss" name="FrGroup::NSS">
            <uilink label="socialNumberLabel" widget="" layout="socialNumberLayout"/>
            <label lang="xx">Social insurance number</label>
            <label lang="fr">Numéro de sécurité sociale</label>
            <options>DontPrintEmptyValues</options>
            <patientdata>SocialNumber</patientdata>
          </Item>

          <Item type="check" name="FrGroup::IsNSSOwner">
            <uilink widget="isSINOwnerCheck"/>
            <label lang="xx">Patient is the social insurance number owner</label>
            <label lang="fr">Est le propriétaire du numéro de sécurité sociale</label>
            <options>DontPrintEmptyValues</options>
            <value><default>checked</default></value>
          </Item>

          <Item type="shorttext" name="FrGroup::OwnerName">
            <uilink label="ownerLabel" widget="ownerEdit"/>
            <label lang="xx">Social number owner</label>
            <label lang="fr">Propriétaire</label>
            <options>DontPrintEmptyValues</options>
            <patientdata>SocialNumberOwnerFullName</patientdata>
          </Item>

          <Item type="button" name="FrGroup::CreateDeclaration">
            <uilink widget="declaration"/>
            <label lang="xx">Formulaire Médecin Traitant</label>
            <ToolTip lang="xx">Formulaire Médecin Traitant</ToolTip>
            <icon>__theme__/carte_vitale.png</icon>
            <script>
              <onload>
                // Enabled this button only is the FreeMedForms PDF object is available
                freemedforms.forms.namespaceInUse = "Subs::Tools::Identity";
                var item = freemedforms.forms.item("FrGroup::CreateDeclaration");
                if (!item.isValid) {
                    print("Error in identity form");
                    return;
                }
                item.enabled = freemedforms.pdf.isAvailable;
              </onload>
              <onclicked>
                  function _identity_france_declaration_med_traitant()
                  {
                      // get the fremedforms pdf worker
                      var pdf = freemedforms.pdf;
                      if (!pdf.isAvailable) {
                          print("pdftk not available");
                          return;
                      }

                      // process data
                      var patient = freemedforms.patient;
                      if (!patient.isActive) {
                          print("not active patient");
                          return;
                      }

                      pdf.beginFdfEncoding();

                      freemedforms.forms.namespaceInUse = "Subs::Tools::Identity";
                      var isNssOwner = freemedforms.forms.item("FrGroup::IsNSSOwner");
                      if (!isNssOwner.isValid) {
                          print("isNSSOwner not available");
                          return;
                      }
                      var nss = freemedforms.forms.item("FrGroup::NSS");
                      if (!nss.isValid) {
                          print("NSS not available");
                          return;
                      }

                      pdf.addFdfValue("nom", patient.usualName + " " + patient.otherNames);
                      pdf.addFdfValue("prénom", patient.firstName);
                      pdf.addFdfValue("date naissance", freemedforms.tools.dateToString(patient.dateOfBirth, "ddMMyyyy"));
                      // TODO: split street into 2 max lines if required

                      var street = patient.street;
                      if (street.search("\n")) {
                          var splitter = street.split("\n");
                          pdf.addFdfValue("adresse1", splitter.shift());
                          pdf.addFdfValue("adresse2", splitter.join(" ; "));
                      } else {
                          pdf.addFdfValue("adresse1", patient.street);
                      }
                      pdf.addFdfValue("adresse3", patient.city + " " + patient.zipcode + " " + patient.state);

                      if (!isNssOwner.checked) {
                          var owner = freemedforms.forms.item("FrGroup::OwnerName");
                          if (!owner.isValid) {
                              print("NSS owner not available");
                              return;
                          }
                          pdf.addFdfValue("nom ben", owner.currentText);
                          //pdf.addFdfValue("prénom ben", nss.currentText);
                      }

                      print(nss.currentText);

                      if (nss.currentText.length == 15) {
                          pdf.addFdfValue("n° immatriculation", nss.currentText.substring(0, 13));
                          pdf.addFdfValue("clé immatric", nss.currentText.substring(13,15));
                      }

                      var user = freemedforms.user;
                      if (user.isValid) {
                          print("No valid user");
                          //return;
                      }

                      pdf.addFdfValue("num ident med1", user.identifiants.join("; "));
                      pdf.addFdfValue("nom medecin", user.usualName + " " + user.otherNames);
                      pdf.addFdfValue("prénom médecin", user.firstName);
                      pdf.addFdfValue("identif  medecin", user.fullAddress);

                      pdf.addFdfValue("date déclaration", freemedforms.tools.dateToString(new Date(), "ddMMyyyy"));

                      var filename = freemedforms.forms.extractFormFile("__subForms__/generic/fullidentity", "./pdf/fr/declaration.pdf");
                      pdf.endFdfEncoding(filename);

                      var output = freemedforms.tools.userDocumentPath + "declaration_" + patient.usualName + " " + patient.otherNames + " " + patient.firstName + ".pdf";
                      output = output.replace("  ", " ");
                      output = output.replace(" ", "_");
                      pdf.fillPdfWithFdf(filename, pdf.getFdfContent(), output, "ISO-8859-1");
                  }
                  _identity_france_declaration_med_traitant();
              </onclicked>
            </script>
          </Item>
        </Item>

        <Item type="detailswidget" name="ContactDetails" uifilename="./ui/xx/contact.ui">
          <uilink label="" widget="" layout="identityLayout"/>
          <label lang="xx">Contact</label>
          <label lang="fr">Contact</label>
          <column>1</column>
          <options>DontPrintEmptyValues;SummaryFontBold</options>

          <Item type="shorttext" name="ContactGroup::Tels">
            <uilink label="telsLabel" widget="telsEdit"/>
            <label lang="xx">Telephone numbers</label>
            <label lang="fr">Numéros de téléphone</label>
            <tooltip lang="xx">Semicolon separated list</tooltip>
            <tooltip lang="fr">Liste séparée par un point-virgule</tooltip>
            <options>DontPrintEmptyValues</options>
            <patientdata>Tels</patientdata>
          </Item>

          <Item type="shorttext" name="ContactGroup::MobileTel">
            <uilink label="mobileLabel" widget="mobileEdit"/>
            <label lang="xx">Mobile phone</label>
            <label lang="fr">Numéros de mobile</label>
            <tooltip lang="xx">Inform the mobile phone number</tooltip>
            <tooltip lang="fr">Renseignez le numéro de téléphone mobile</tooltip>
            <options>DontPrintEmptyValues</options>
            <patientdata>MobilePhone</patientdata>
          </Item>

          <Item type="shorttext" name="ContactGroup::Fax">
            <uilink label="faxLabel" widget="faxEdit"/>
            <label lang="xx">Fax number</label>
            <label lang="fr">Numéro de fax</label>
            <options>DontPrintEmptyValues</options>
            <patientdata>Faxes</patientdata>
          </Item>

          <Item type="shorttext" name="ContactGroup::Mail">
            <uilink label="emailLabel" widget="emailEdit"/>
            <label lang="xx">E-Mail</label>
            <label lang="fr">Courriel</label>
            <tooltip lang="xx">Semicolon separated list</tooltip>
            <tooltip lang="fr">Liste séparée par un point-virgule</tooltip>
            <options>DontPrintEmptyValues</options>
            <patientdata>Mails</patientdata>
          </Item>

          <Item type="button" name="ContactGroup::SendMailButton">
            <uilink widget="sendMailButton"/>
            <label lang="xx">Send mail</label>
            <label lang="fr">Envoyer un courriel</label>
            <icon>__theme__/mail_new.png</icon>
            <script>
              <onclicked>
              freemedforms.forms.namespaceInUse = "Subs::Tools::Identity::ContactGroup::";
              var address = freemedforms.forms.item("Mail");
              if (address.isValid) {
                  if (address.currentText != "")
                      freemedforms.tools.openUrl("mailto:" + address.currentText);
              }
              </onclicked>
            </script>
          </Item>

          <Item type="button" name="ContactGroup::SendSmsButton">
            <uilink widget="sendSmsButton"/>
            <label lang="xx">Send SMS</label>
            <label lang="fr">Envoyer un SMS</label>
            <icon>__theme__/iphone.png</icon>
          </Item>

        </Item>

        <Item type="detailswidget" name="ProfDetails" uifilename="./ui/xx/prof.ui">
            <uilink label="" widget="" layout="identityLayout"/>
            <label lang="xx">Profession</label>
            <label lang="fr">Profession</label>
            <column>1</column>
            <options>DontPrintEmptyValues;SummaryFontBold</options>

            <Item type="shorttext" name="ProfGroup::Profession">
              <uilink label="profLabel" widget="profEdit"/>
              <label lang="xx">Current profession</label>
              <label lang="fr">Profession actuelle</label>
              <options>DontPrintEmptyValues</options>
              <patientdata>Profession</patientdata>
            </Item>

            <Item type="shorttext" name="ProfGroup::ProfessionSite">
              <uilink label="profSiteLabel" widget="profSiteEdit"/>
              <label lang="xx">Site</label>
              <label lang="fr">Site</label>
              <options>DontPrintEmptyValues</options>
              <patientdata>ProfessionalSite</patientdata>
            </Item>

            <Item type="shorttext" name="ProfGroup::ProfessionTels">
              <uilink label="profTelsLabel" widget="profTelsEdit"/>
              <label lang="xx">Professional tel</label>
              <label lang="fr">Téléphone professionel</label>
              <options>DontPrintEmptyValues</options>
              <patientdata>ProfessionalTels</patientdata>
            </Item>

        </Item>
      </MedForm>

      <MedForm name="Subs::Tools::TrustedPerson" uifilename="./ui/xx/identity.ui">
        <label lang="xx">Trusted person</label>
        <label lang="fr">Personne de confiance</label>
        <options>unique;UseFormNameAsNameSpace;HideHeaderOnUniqueEpisode</options>
        <icon>__theme__/identity.png</icon>
        <file type="htmlprintmask">./html/xx/trustedperson_padtools_mask.html</file>
        <file type="htmlexportmask">./html/xx/trustedperson_padtools_mask.html</file>

        <Item type="detailswidget" name="TrustedPersonDetails" uifilename="./ui/xx/trusted.ui">
            <uilink label="" widget="" layout="identityLayout"/>
            <label lang="xx">Trusted person</label>
            <label lang="fr">Personne de confiance</label>
            <options>DontPrintEmptyValues;SummaryFontBold;expanded</options>

            <Item type="identity" name="Identity">
                <uilink label="" widget="" layout="trustedLayout"/>
                <label lang="xx">Full Identity</label>
                <label lang="fr">Identité</label>
                <options>with-address;xml</options>
                <file type="htmlprintmask">./html/xx/identity_mask.html</file>
            </Item>

          <Item type="shorttext" name="Mail">
            <uilink label="mailLabel" widget="mail"/>
            <label lang="xx">E-Mail</label>
            <label lang="fr">Courriel</label>
            <tooltip lang="xx">Semicolon separated list</tooltip>
            <tooltip lang="fr">Liste séparée par un point-virgule</tooltip>
            <options>DontPrintEmptyValues</options>
            <patientdata>Mails</patientdata>
          </Item>

          <Item type="shorttext" name="Tels">
            <uilink label="telLabel" widget="tel"/>
            <label lang="xx">Telephone numbers</label>
            <label lang="fr">Numéros de téléphone</label>
            <tooltip lang="xx">Semicolon separated list</tooltip>
            <tooltip lang="fr">Liste séparée par un point-virgule</tooltip>
            <options>DontPrintEmptyValues</options>
            <patientdata>Tels</patientdata>
          </Item>

          <Item type="shorttext" name="MobileTel">
            <uilink label="mobileLabel" widget="mobile"/>
            <label lang="xx">Mobile phone</label>
            <label lang="fr">Numéros de mobile</label>
            <tooltip lang="xx">Inform the mobile phone number</tooltip>
            <tooltip lang="fr">Renseignez le numéro de téléphone mobile</tooltip>
            <options>DontPrintEmptyValues</options>
            <patientdata>MobilePhone</patientdata>
          </Item>

        </Item>
      </MedForm>

  </MedForm>

</FreeMedForms>
