Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66333370
studies.coffee
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jun 9, 21:27
Size
1 KB
Mime Type
text/x-c++
Expires
Tue, Jun 11, 21:27 (2 d)
Engine
blob
Format
Raw Data
Handle
18206129
Attached To
R7177 epiph
studies.coffee
View Options
class @Study
constructor: (doc) ->
_.extend this, doc
creator: ->
Meteor.users.findOne _id: @creatorId
editingNotAllowed: ->
false
@Studies = new Meteor.Collection("studies",
transform: (doc) ->
new Study(doc)
)
Studies.before.insert BeforeInsertTimestampHook
Studies.before.update BeforeUpdateTimestampHook
Meteor.methods
"createStudy": ->
checkIfAdmin()
Studies.insert
title: "new Study"
creatorId: Meteor.userId()
return
"updateStudyTitle": (studyId, title) ->
checkIfAdmin()
check(title, String)
study = Studies.findOne studyId
throw new Meteor.Error(403, "study not found.") unless study?
Studies.update studyId,
$set: title: title
return
if Meteor.isServer
Meteor.methods
"removeStudy": (studyId, forceReason) ->
checkIfAdmin()
study = Studies.findOne studyId
throw new Meteor.Error(403, "study not found.") unless study?
#check if a visit with answer exists
visitTemplateIds = []
StudyDesigns.find(
studyId: studyId
).forEach (sd) ->
sd.visits.forEach (vt) ->
visitTemplateIds.push vt._id
visitIds = Visits.find(
designVisitId: $in: visitTemplateIds
).map (v) -> v._id
hasData = Answers.find(visitId: $in: visitIds).count() > 0
if hasData and !forceReason?
throw new Meteor.Error(400, "answersExistForStudy")
if hasData
Meteor.call "logActivity", "remove study (#{study.title}) which has data", "critical", forceReason, study
else
Meteor.call "logActivity", "remove empty study (#{study.title})", "notice", null, study
Answers.remove
visitId: $in: visitIds
Visits.remove
designVisitId: $in: visitTemplateIds
Patients.remove
studyId: studyId
StudyDesigns.remove
studyId: studyId
Studies.remove
_id: studyId
return
Event Timeline
Log In to Comment