<commit_before><?xml version="1.0" encoding="UTF-8"?>

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/
-->

<xwikidoc version="1.1">
  <web>PhenoTips</web>
  <name>DatabaseFilters</name>
  <language/>
  <defaultLanguage/>
  <translation>0</translation>
  <creator>xwiki:XWiki.Admin</creator>
  <creationDate>1401822219000</creationDate>
  <parent>PhenoTips.Export</parent>
  <author>xwiki:XWiki.Admin</author>
  <contentAuthor>xwiki:XWiki.Admin</contentAuthor>
  <date>1401822219000</date>
  <contentUpdateDate>1401822219000</contentUpdateDate>
  <version>1.1</version>
  <title/>
  <comment/>
  <minorEdit>false</minorEdit>
  <syntaxId>xwiki/2.1</syntaxId>
  <hidden>true</hidden>
  <content>{{velocity output=false}}
#set ($activeFields = $services.recordConfiguration.getConfiguration("patient").enabledFieldNames)
#set ($dateFormat = "MM/dd/yyyy")
##
##
#macro (__filters_dateRange $field_name $dateStart $dateEnd)
(% class="date-range" %)(((
#__filters_dateField ("$services.localization.render('phenotips.databaseFilters.after.label') " "${field_name}/after" $dateStart)

#__filters_dateField ("$services.localization.render('phenotips.databaseFilters.before.label') " "${field_name}/before" $dateEnd)
)))
#end
##
#macro (__filters_dateField $label $field_name $value)
{{html clean="false"}}&lt;label&gt;$label &lt;input class="xwiki-date" type="text" alt="#if($value)#formatdateISO($value)#end" value="$!xwiki.formatDate($value, $definedFormat)" name="${field_name}" title="${dateFormat}" /&gt;&lt;/label&gt;{{/html}}
#end
##
#macro (__filters_labeledIdentifiers)
#set ($eidClass = "PhenoTips.LabeledIdentifierClass")
#set ($labelParam = 'label')
#set ($valueParam = 'value')
(% class="labeled-eids" %)(((
#__filters_LabeledEidLabel ("$services.localization.render('phenotips.databaseFilters.label.label') " $labelParam $eidClass)
#__filters_LabeledEidValue ("$services.localization.render('phenotips.databaseFilters.value.label') " $valueParam $eidClass)
)))
#end
##
#macro (__filters_LabeledEidLabel $label $field_name $eidClass)
{{html clean="false"}}&lt;label&gt;$label &lt;select name="${field_name}"&gt;&lt;option&gt;&lt;/option&gt;{{/html}}##
    #__filters_LabeledEidOptions()
{{html clean="false"}}&lt;/select&gt;&lt;/label&gt;&lt;input type="hidden" value="$eidClass" name="${field_name}/class" /&gt;&lt;input type="hidden" value="ci" name="${field_name}/match" /&gt;{{/html}}##
#end
##
#macro (__filters_LabeledEidValue $label $field_name $eidClass)
{{html clean="false"}}&lt;label&gt;$label &lt;input type="text" value="" name="${field_name}" /&gt;&lt;/label&gt;&lt;input type="hidden" value="$eidClass" name="${field_name}/class" /&gt;{{/html}}
#end
##
#macro (__filters_LabeledEidOptions)
#set ($labelParam = 'label')
#set ($existingLabels = $services.query.xwql("select distinct labeled_eid.${labelParam} from Document doc, doc.object(PhenoTips.LabeledIdentifierClass) as labeled_eid").execute())
#foreach ($label in $existingLabels)
{{html clean="false"}}
&lt;option&gt;$label&lt;/option&gt;
{{/html}}##
#end
#end

#macro(__filters_display $cssClass $showHideButton)
#if ($showHideButton)
{{html clean='false' wiki='true'}}&lt;span class='buttonwrapper'&gt;&lt;a class='button toggle-filters' href='#'&gt;{{icon name='filter' /}}&lt;span class='label'&gt;$services.localization.render('phenotips.allData.filterButton')&lt;/span&gt;&lt;input type="hidden" name="user-hash" value="$!{xcontext.userReference.hashCode()}"/&gt;{{icon name='angle-double-left' cssClass='collapse-marker' /}}{{icon name='angle-double-down' cssClass='expand-marker' /}}&lt;/a&gt;&lt;/span&gt;{{/html}}
#end
(% class="filters $!cssClass" %)
#if ($activeFields.contains('external_id'))
* $services.localization.render('phenotips.databaseFilters.externalID') {{html clean=false}}&lt;input type="text" name="external_id" value=""/&gt;{{/html}}
#end
#if (!$doc.getObject('PhenoTips.StudyClass'))
#set ($studies = $services.query.xwql("from doc.object(PhenoTips.StudyClass) as s where doc.fullName &lt;&gt; 'PhenoTips.StudyTemplate'").execute())
#if ($studies.size() &gt; 0)
* $services.localization.render('phenotips.databaseFilters.study') {{html clean=false}}#foreach($sName in $studies)#set ($s = $xwiki.getDocument($sName))&lt;br/&gt;&lt;label&gt;&lt;input type="checkbox" name="studyReference" value="$escapetool.xml($services.model.serialize($s.documentReference, 'default'))"/&gt;#if ("$!{s.plainTitle}" != '')${s.plainTitle}#else${s.name}#end&lt;/label&gt;#end&lt;input type="hidden" name="studyReference/class" value="PhenoTips.StudyBindingClass"/&gt;&lt;input type="hidden" name="studyReference/match" value="fullReference"/&gt;&lt;input type='hidden' name='studyReference/join_mode' value='OR'/&gt;{{/html}}
#end
#end
#if ($activeFields.contains('labeled_eids'))
* $services.localization.render('phenotips.databaseFilters.labeledExternalID') #__filters_labeledIdentifiers()
#end
#if (!$xwiki.getDocument('PhenoTips.VisibilityClass').isNew())
  * $services.localization.render('phenotips.databaseFilters.visibility') {{html clean=false}}#foreach ($visibility in $services.permissions.listVisibilityOptions())&lt;br /&gt;&lt;label&gt;&lt;input type="checkbox" class="multipleSelection privacyExport" name="visibility" value="$visibility.name"#if ($visibility.name != 'hidden') checked="checked"#end /&gt; $visibility.label&lt;/label&gt;#end&lt;input type="hidden" name="visibility/class" value="PhenoTips.VisibilityClass"/&gt;{{/html}}
#end
* $services.localization.render('phenotips.databaseFilters.referrer') {{html clean=false}}&lt;input type="text" class="suggestUsers multipleSelection" name="doc.creator" value=""/&gt;{{/html}}
#if (!$xwiki.getDocument('PhenoTips.OwnerClass').isNew())<commit_msg>PT-3591: Labeled external identifier fields should be shown in Advanced filter panel only if they are allowed and defined<commit_after><?xml version="1.0" encoding="UTF-8"?>

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/
-->

<xwikidoc version="1.1">
  <web>PhenoTips</web>
  <name>DatabaseFilters</name>
  <language/>
  <defaultLanguage/>
  <translation>0</translation>
  <creator>xwiki:XWiki.Admin</creator>
  <creationDate>1401822219000</creationDate>
  <parent>PhenoTips.Export</parent>
  <author>xwiki:XWiki.Admin</author>
  <contentAuthor>xwiki:XWiki.Admin</contentAuthor>
  <date>1401822219000</date>
  <contentUpdateDate>1401822219000</contentUpdateDate>
  <version>1.1</version>
  <title/>
  <comment/>
  <minorEdit>false</minorEdit>
  <syntaxId>xwiki/2.1</syntaxId>
  <hidden>true</hidden>
  <content>{{velocity output=false}}
#set ($activeFields = $services.recordConfiguration.getConfiguration("patient").enabledFieldNames)
#set ($dateFormat = "MM/dd/yyyy")
##
##
#macro (__filters_dateRange $field_name $dateStart $dateEnd)
(% class="date-range" %)(((
#__filters_dateField ("$services.localization.render('phenotips.databaseFilters.after.label') " "${field_name}/after" $dateStart)

#__filters_dateField ("$services.localization.render('phenotips.databaseFilters.before.label') " "${field_name}/before" $dateEnd)
)))
#end
##
#macro (__filters_dateField $label $field_name $value)
{{html clean="false"}}&lt;label&gt;$label &lt;input class="xwiki-date" type="text" alt="#if($value)#formatdateISO($value)#end" value="$!xwiki.formatDate($value, $definedFormat)" name="${field_name}" title="${dateFormat}" /&gt;&lt;/label&gt;{{/html}}
#end
##
#macro (__filters_labeledIdentifiers)
#set ($eidClass = "PhenoTips.LabeledIdentifierClass")
#set ($labelParam = 'label')
#set ($valueParam = 'value')
#set ($existingLabels = $services.query.xwql("select distinct labeled_eid.${labelParam} from Document doc, doc.object(PhenoTips.LabeledIdentifierClass) as labeled_eid").execute())
#if ($!{existingLabels} &amp;&amp; $existingLabels.size() > 0)
* $services.localization.render('phenotips.databaseFilters.labeledExternalID')
(% class="labeled-eids" %)(((
#__filters_LabeledEidLabel ("$services.localization.render('phenotips.databaseFilters.label.label') " $labelParam $eidClass $existingLabels)
#__filters_LabeledEidValue ("$services.localization.render('phenotips.databaseFilters.value.label') " $valueParam $eidClass)
)))
#end
#end
##
#macro (__filters_LabeledEidLabel $label $field_name $eidClass $existingLabels)
{{html clean="false"}}&lt;label&gt;$label &lt;select name="${field_name}"&gt;&lt;option&gt;&lt;/option&gt;{{/html}}##
    #__filters_LabeledEidOptions($existingLabels)
{{html clean="false"}}&lt;/select&gt;&lt;/label&gt;&lt;input type="hidden" value="$eidClass" name="${field_name}/class" /&gt;&lt;input type="hidden" value="ci" name="${field_name}/match" /&gt;{{/html}}##
#end
##
#macro (__filters_LabeledEidValue $label $field_name $eidClass)
{{html clean="false"}}&lt;label&gt;$label &lt;input type="text" value="" name="${field_name}" /&gt;&lt;/label&gt;&lt;input type="hidden" value="$eidClass" name="${field_name}/class" /&gt;{{/html}}
#end
##
#macro (__filters_LabeledEidOptions $existingLabels)
#foreach ($label in $existingLabels)
{{html clean="false"}}
&lt;option&gt;$label&lt;/option&gt;
{{/html}}##
#end
#end

#macro(__filters_display $cssClass $showHideButton)
#if ($showHideButton)
{{html clean='false' wiki='true'}}&lt;span class='buttonwrapper'&gt;&lt;a class='button toggle-filters' href='#'&gt;{{icon name='filter' /}}&lt;span class='label'&gt;$services.localization.render('phenotips.allData.filterButton')&lt;/span&gt;&lt;input type="hidden" name="user-hash" value="$!{xcontext.userReference.hashCode()}"/&gt;{{icon name='angle-double-left' cssClass='collapse-marker' /}}{{icon name='angle-double-down' cssClass='expand-marker' /}}&lt;/a&gt;&lt;/span&gt;{{/html}}
#end
(% class="filters $!cssClass" %)
#if ($activeFields.contains('external_id'))
* $services.localization.render('phenotips.databaseFilters.externalID') {{html clean=false}}&lt;input type="text" name="external_id" value=""/&gt;{{/html}}
#end
#if (!$doc.getObject('PhenoTips.StudyClass'))
#set ($studies = $services.query.xwql("from doc.object(PhenoTips.StudyClass) as s where doc.fullName &lt;&gt; 'PhenoTips.StudyTemplate'").execute())
#if ($studies.size() &gt; 0)
* $services.localization.render('phenotips.databaseFilters.study') {{html clean=false}}#foreach($sName in $studies)#set ($s = $xwiki.getDocument($sName))&lt;br/&gt;&lt;label&gt;&lt;input type="checkbox" name="studyReference" value="$escapetool.xml($services.model.serialize($s.documentReference, 'default'))"/&gt;#if ("$!{s.plainTitle}" != '')${s.plainTitle}#else${s.name}#end&lt;/label&gt;#end&lt;input type="hidden" name="studyReference/class" value="PhenoTips.StudyBindingClass"/&gt;&lt;input type="hidden" name="studyReference/match" value="fullReference"/&gt;&lt;input type='hidden' name='studyReference/join_mode' value='OR'/&gt;{{/html}}
#end
#end
#if ($activeFields.contains('labeled_eids'))
#__filters_labeledIdentifiers()
#end
#if (!$xwiki.getDocument('PhenoTips.VisibilityClass').isNew())
  * $services.localization.render('phenotips.databaseFilters.visibility') {{html clean=false}}#foreach ($visibility in $services.permissions.listVisibilityOptions())&lt;br /&gt;&lt;label&gt;&lt;input type="checkbox" class="multipleSelection privacyExport" name="visibility" value="$visibility.name"#if ($visibility.name != 'hidden') checked="checked"#end /&gt; $visibility.label&lt;/label&gt;#end&lt;input type="hidden" name="visibility/class" value="PhenoTips.VisibilityClass"/&gt;{{/html}}
#end
* $services.localization.render('phenotips.databaseFilters.referrer') {{html clean=false}}&lt;input type="text" class="suggestUsers multipleSelection" name="doc.creator" value=""/&gt;{{/html}}
#if (!$xwiki.getDocument('PhenoTips.OwnerClass').isNew())
{'fraction_non_alphanumeric': 0.18777692895339954, 'fraction_numerical': 0.008174178762414056, 'mean_word_length': 8.29098651525905, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 2, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465536', 'n_tokens_mistral': 4446, 'n_tokens_neox': 4306, 'n_words': 779}