Skip to content

Instantly share code, notes, and snippets.

@sdumitriu
Created November 3, 2015 14:34
Show Gist options
  • Save sdumitriu/0d48ad7fda85d6252138 to your computer and use it in GitHub Desktop.
Save sdumitriu/0d48ad7fda85d6252138 to your computer and use it in GitHub Desktop.
PhenoTips - Renumber all patient records

This script renumbers all patient records in a PhenoTips instance, adding a specified offset, for example for merging two PhenoTips instances.

Open /bin/edit/Sandbox/Renumber in a browser while logged in with an administrative account, paste the following snippet, and press Preview. Don't forget to adjust the $offset variable with the correct value.

{{velocity}}
#set ($offset = 100)## Set a proper value, 1 + the ID of the last record in the other instance
#foreach ($pid in $services.query.xwql('from doc.object(PhenoTips.PatientClass) as p where doc.space = ''data''').execute())
#set ($pdoc = $xwiki.getDocument($pid))
#set ($pobj = $pdoc.getObject('PhenoTips.PatientClass'))
#set ($newId = $mathtool.add($pobj.getProperty('identifier').value, $offset))
#set ($discard = $pobj.set('identifier', "$newId"))
$pdoc.save('Updated ID', true)
$pdoc.rename("data.P${doc.name.format('%07d', $newId)}")
#end
{{/velocity}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment