Skip to content

Instantly share code, notes, and snippets.

@sdumitriu
Last active December 5, 2016 16:25
Show Gist options
  • Save sdumitriu/5bac1c325098d7dfe985 to your computer and use it in GitHub Desktop.
Save sdumitriu/5bac1c325098d7dfe985 to your computer and use it in GitHub Desktop.
PhenoTips - Add a new collaborator to every patient record

To add a new collaborator for all patient records, including the template used for future patients, open /bin/edit/Sandbox/AddCollaborator in a browser while logged in with an administrative account, paste the following snippet, and press Preview.

WARNING: Pressing Preview doesn't preview the changes, it will actually modify the permissions!

Things you can adjust:

  • the target access level, at line 2 replace edit with the desired value (view, edit, manage)
  • the target collaborator, at line 3 replace groupname with the desired group name, or uncomment line 5 and replace username with the desired username
  • skip the patient template by replacing the query at line 6 with 'from doc.object(PhenoTips.PatientClass) as p where doc.name <> ''PatientTemplate'''
  • only include records of a certain user by replacing the query at line 6 with 'from doc.object(PhenoTips.PatientClass) as p, doc.object(PhenoTips.OwnerClass) as o where o.owner = ''xwiki:XWiki.username'''
  • only include records of a certain workgroup by replacing the query at line 6 with 'from doc.object(PhenoTips.PatientClass) as p, doc.object(PhenoTips.OwnerClass) as o where o.owner = ''xwiki:Groups.groupname'''
  • only include records with an external ID matching a specific substring by replacing the query at line 6 with 'from doc.object(PhenoTips.PatientClass) as p where p.external_id like ''GC%'''
  • modify a specific set of patient records by specifying it manually: #foreach ($i in ['P0000001', 'P0000005', 'P0000042'])
{{velocity}}
#set ($accessLevel = $services.permissions.resolveAccessLevel('edit'))
#set ($collaborator = $services.model.createDocumentReference('', 'Groups', 'groupname'))
## Or for a specific user:
## #set ($collaborator = $services.model.createDocumentReference('', 'XWiki', 'username'))
#foreach ($i in $services.query.xwql('from doc.object(PhenoTips.PatientClass) as p').execute())
$!services.permissions.getPatientAccess($services.patients.getPatientById($i)).addCollaborator($collaborator, $accessLevel)
#end
{{/velocity}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment