Skip to content

Instantly share code, notes, and snippets.

@sdumitriu
sdumitriu / extract-module.sh
Created March 7, 2012 14:13
How to extract a submodule from a git repository, taking into consideration subdirectory moves (an advanced filter-branch --subdirectory-filter)
#!/bin/bash
echo Cloning repository...
git clone git@github.com:organization/project.git
cd project
echo
echo Removing origin
git remote rm origin
@sdumitriu
sdumitriu / gist:3886217
Created October 13, 2012 21:38
tomcat6 logrotate config
/var/log/tomcat6/catalina.out {
copytruncate
weekly
rotate 52
compress
missingok
create 0644 tomcat tomcat
}
{{velocity}}
#foreach ($p in $services.query.xwql("from doc.object(PhenoTips.PatientClass) as patient where :matEtn member of patient.maternal_ethnicity").bindValue('matEtn', 'irish').execute())
* [[$p]]
#end
{{/velocity}}
@sdumitriu
sdumitriu / gist:f55c7225091fb5dee3d4
Last active August 29, 2015 14:18
Patient records created each months
{{velocity}}
##set ($format = $services.jodatime.getISODateFormatter())
#set ($format = $services.jodatime.getDateTimeFormatterForPattern('yyyy-MM'))
#set($q = $services.query.hql("select doc.creationDate from XWikiDocument doc, BaseObject as obj, DBStringListProperty phenotype, LongProperty iid where obj.name=doc.fullName and obj.className = ? and doc.fullName not in (?, ?) and obj.id=phenotype.id.id and phenotype.id.name = ? and (? in elements(phenotype.list)) and iid.id.id = obj.id and iid.id.name = 'identifier' and iid.value >= 0 order by doc.creationDate asc").bindValues(["PhenoTips.PatientClass", "PhenoTips.PatientClassTemplate", "PhenoTips.PatientTemplate", "extended_phenotype", "HP:0000118"]))
|=Month|=Patient records created
#foreach ($i in $q.execute())
#set ($date = $format.print($i))
#if ($prevDate != $date)
#if($prevDate)
|$prevDate|$count
@sdumitriu
sdumitriu / README.md
Last active December 5, 2016 16:24
PhenoTips - Update visibility for all patient records

To set or update the visibility for all patient records, including the template used for future patients, open /bin/edit/Sandbox/UpdateVisibility 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 visibility, at line 2 replace private with the desired value (hidden, private, matchable, public, open)
  • skip the patient template by replacing the query at line 3 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 3 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 3 with `'from doc.object(PhenoTips.PatientClass) as p, doc.object(Phen
@sdumitriu
sdumitriu / README.md
Last active December 5, 2016 16:25
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'''
@sdumitriu
sdumitriu / README.md
Created November 3, 2015 14:34
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.

@sdumitriu
sdumitriu / sample.sh
Last active December 22, 2015 01:58
PhenoTips - Using curl with REST to manage users and workgroups
# Creating a user:
curl -u Admin:admin -X PUT -d "parent=XWiki.XWikiUsers" -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/jdoe
curl -u Admin:admin -X POST -d 'className=XWiki.XWikiUsers&property#first_name=John&property#last_name=Doe&property#email=jdoe@company.com&property#password=pass1234' -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/jdoe/objects
# Deleting a user:
curl -u Admin:admin -X DELETE http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/jdoe
# Creating a workgroup:
@sdumitriu
sdumitriu / gist:688b43b2faa72838d5fb
Created December 19, 2015 11:34
Running the distribution wizard when switching databases
find -name *.xed -exec sed -e 's/<installed.installed type="boolean">true<\/installed.installed>/<installed.installed type="boolean">false<\/installed.installed>/' -i \{\} \;
@sdumitriu
sdumitriu / set_mapping.sh
Created January 12, 2016 13:17
PhenoTips - Set a specific phenotype mapping for a user via REST
# Change the following three variables to what you need:
XAUTH='Admin:admin'
USER='Admin'
MAPPING='PhenoTips.Detailed physical phenotype configuration'
XOBJNR=`curl -s -u ${XAUTH} http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/${USER}/objects | sed -r -e ': start' -e 's/(<\/[^>]+?>)([^\n])/\1\n\2/g' -e 't start' | grep -E '<headline>phenotips_mapping</headline>' -B 5 | grep -E '<number>' | sed -r -e 's/.*>(.*)<.*/\1/'`
if [[ -n $XOBJNR ]]
then curl -s -o /dev/null -u ${XAUTH} -X PUT -H 'Content-Type: text/plain' -d "${MAPPING}" http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/${USER}/objects/XWiki.ConfigurationClass/${XOBJNR}/properties/value
else curl -s -o /dev/null -u ${XAUTH} -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d "className=XWiki.ConfigurationClass&property#property=phenotips_mapping&property#value=${MAPPING}" http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/${USER}/objects