config.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import os
  2. def getPatientId(row,xconfig):
  3. return row[getPatientField(xconfig)]
  4. def getPatientField(xconfig):
  5. return xconfig['ParticipantField']
  6. def getVisitField(xconfig):
  7. return 'visitName'
  8. def getVisitId(row,xconfig):
  9. return row[getVisitField(xconfig)]
  10. def getIdFilter(row,xconfig):
  11. return {'variable':getPatientField(xconfig),\
  12. 'value':getPatientId(row,xconfig),
  13. 'oper':'eq'}
  14. def getVisitFilter(row,xconfig):
  15. return {'variable':getVisitField(xconfig),\
  16. 'value':getVisitId(row,xconfig),
  17. 'oper':'eq'}
  18. def getCode(row,xconfig):
  19. return '{}_{}'.format(getPatientId(row,xconfig),getVisitId(row,xconfig))
  20. def getTargetSeqNum(row,xconfig):
  21. if getVisitId(row,xconfig)=='OBR':
  22. return 2
  23. return 1
  24. def getPathList(row,xconfig):
  25. return [xconfig['baseDir'],getPatientId(row,xconfig),getVisitId(row,xconfig)]
  26. def getOutputDir(row,xconfig):
  27. return '/'.join(getPathList(row,xconfig))
  28. def getLocalDir(row,xconfig):
  29. return os.path.join(xconfig['tempDir'],getCode(row,xconfig))
  30. def getNodeName(row,xconfig,mode,i=0):
  31. if mode=='CT':
  32. return getCode(row,xconfig)+'_CT'
  33. if mode=='NM':
  34. return '{}_Volume{}'.format(getCode(row,xconfig),i)
  35. return getCode(row,xconfig)+'_Dummy'
  36. def decode(code,xconfig):
  37. #invert code and return object equivalent to row with relevant
  38. #fields set that can be used in
  39. #getPatientId, getVisitId,getIdFilter,getVisitFilter
  40. #as an equivalent replacement for r
  41. values=code.split('_')
  42. fid=values[0]
  43. vid=values[1]
  44. return {getPatientField(xconfig):fid,getVisitField(xconfig):vid}