- Timestamp:
- Jan 26, 2012, 5:12:54 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy
r1969 r2153 208 208 } 209 209 210 public static String generateSampleName(flow, subject, eventGroup, samplingEvent) { 211 def samplingEventName = ucwords(samplingEvent.template.name) 212 def eventGroupName = ucwords(eventGroup.name).replaceAll("([ ]{1,})", "") 213 def sampleTemplateName = (samplingEvent.sampleTemplate) ? ucwords(samplingEvent.sampleTemplate.name) : '' 214 def sampleName = (ucwords(subject.name) + '_' + samplingEventName + '_' + eventGroupName + '_' + new RelTime(samplingEvent.startTime).toString() + '_' + sampleTemplateName).replaceAll("([ ]{1,})", "") 215 def tempSampleIterator = 0 216 def tempSampleName = sampleName 217 218 // make sure sampleName is unique 219 if (flow.study.samples) { 220 while (flow.study.samples.find { it.name == tempSampleName }) { 221 tempSampleIterator++ 222 tempSampleName = sampleName + "_" + tempSampleIterator 223 } 224 sampleName = tempSampleName 225 } 226 return sampleName 227 } 228 229 /** 230 * groovy / java equivalent of php's ucwords function 231 * 232 * Capitalize all first letters of separate words 233 * 234 * @param String 235 * @return String 236 */ 237 public static ucwords(String text) { 238 def newText = '' 239 240 // change case to lowercase 241 text = text.toLowerCase() 242 243 // iterate through words 244 text.split(" ").each() { 245 newText += it[0].toUpperCase() + it.substring(1) + " " 246 } 247 248 return newText.substring(0, newText.size()-1) 249 } 210 250 }
Note: See TracChangeset
for help on using the changeset viewer.