<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>CheckID</name>
  <language/>
  <defaultLanguage/>
  <translation>0</translation>
  <creator>xwiki:XWiki.Admin</creator>
  <creationDate>1401822214000</creationDate>
  <parent>PhenoTips.WebHome</parent>
  <author>xwiki:XWiki.Admin</author>
  <contentAuthor>xwiki:XWiki.Admin</contentAuthor>
  <date>1401822214000</date>
  <contentUpdateDate>1401822214000</contentUpdateDate>
  <version>1.1</version>
  <title/>
  <comment/>
  <minorEdit>false</minorEdit>
  <syntaxId>xwiki/2.1</syntaxId>
  <hidden>true</hidden>
  <content>{{velocity}}
#if ("$!{request.outputSyntax}" != 'plain')
{{html clean="false"}}
#end
#if ($request.getParameter('eid') &amp;&amp; $request.getParameter('id'))
  #set ($externalIdentifier = "$!{request.eid}")
  #set ($identifier = "$!{request.id}")
  #set ($entity = "$!{request.entity}")
  #set ($className = 'PhenoTips.PatientClass')
  #set ($space = 'data')
  #if ($entity == 'families')
    #set ($className = 'PhenoTips.FamilyClass')
    #set ($space = 'Families')
  #end
  #if ($externalIdentifier == $xwiki.getDocument($services.model.resolveDocument($identifier, $services.model.resolveSpace($space))).getObject($className).getProperty('external_id').value)
    Self
    #break
  #end
  #set ($matchingDocuments = $xwiki.wrapDocs($services.query.xwql("where doc.object($className).external_id = :eid").bindValue('eid', $externalIdentifier).execute()))
  #if ($externalIdentifier == '')
    $response.setStatus(403)
    Empty
  #elseif ($matchingDocuments.size() == 0)
    $response.setStatus(404)
    Available
  #else
    $response.setStatus(409)
    Exists
  #end
#else
  $response.setStatus(400)
  Please specify an identifier to check
#end
#if ("$!{request.outputSyntax}" != 'plain')<commit_msg>PT-3696: Include inaccessible records when checking the uniqueness of the external id Done<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>CheckID</name>
  <language/>
  <defaultLanguage/>
  <translation>0</translation>
  <creator>xwiki:XWiki.Admin</creator>
  <creationDate>1401822214000</creationDate>
  <parent>PhenoTips.WebHome</parent>
  <author>xwiki:XWiki.Admin</author>
  <contentAuthor>xwiki:XWiki.Admin</contentAuthor>
  <date>1401822214000</date>
  <contentUpdateDate>1401822214000</contentUpdateDate>
  <version>1.1</version>
  <title/>
  <comment/>
  <minorEdit>false</minorEdit>
  <syntaxId>xwiki/2.1</syntaxId>
  <hidden>true</hidden>
  <content>{{velocity}}
#if ("$!{request.outputSyntax}" != 'plain')
{{html clean="false"}}
#end
#if ($request.getParameter('eid') &amp;&amp; $request.getParameter('id'))
  #set ($externalIdentifier = "$!{request.eid}")
  #set ($identifier = "$!{request.id}")
  #set ($entity = "$!{request.entity}")
  #set ($className = 'PhenoTips.PatientClass')
  #set ($space = 'data')
  #if ($entity == 'families')
    #set ($className = 'PhenoTips.FamilyClass')
    #set ($space = 'Families')
  #end
  #if ($externalIdentifier == $xwiki.getDocument($services.model.resolveDocument($identifier, $services.model.resolveSpace($space))).getObject($className).getProperty('external_id').value)
    Self
    #break
  #end
  #set ($matchingDocuments = $services.query.xwql("where doc.object($className).external_id = :eid").bindValue('eid', $externalIdentifier).execute())
  #if ($externalIdentifier == '')
    $response.setStatus(403)
    Empty
  #elseif ($matchingDocuments.size() == 0)
    $response.setStatus(404)
    Available
  #else
    $response.setStatus(409)
    Exists
  #end
#else
  $response.setStatus(400)
  Please specify an identifier to check
#end
#if ("$!{request.outputSyntax}" != 'plain')
{'fraction_non_alphanumeric': 0.14904027098231087, 'fraction_numerical': 0.024463680843056078, 'mean_word_length': 4.859977949283352, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 2, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1918673', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1655, 'n_words': 437}