| 113 | | |
| 114 | | |
| 115 | | def getPanelDataArray(self, chat_conv, *pargs, **kwargs): |
| 116 | | panelDataArray = [] |
| 117 | | |
| 118 | | listOf_CodeClassId = {} |
| 119 | | for cw in chat_conv.conv_care_workers: |
| 120 | | care_worker_registration_questions = self.selectConversationQuestionsByQuestionairName(cw.conv_participant_questions, ['CW_REG']) |
| 121 | | listOf_CodeClassId = self.getListOf_CodeClassId(conv_questions=care_worker_registration_questions, listOf_CodeClassId=listOf_CodeClassId) |
| 122 | | |
| 123 | | codeIdList = {} |
| 124 | | for code_class_id in listOf_CodeClassId.keys(): |
| 125 | | codeDataElements = ['answerClass', 'codeList', 'code_class_id', 'code_class_description', 'allow_sub_codes', |
| 126 | | 'code_id', 'code_description', 'main_code_id'] |
| 127 | | codeList = self.site.getCodeList(self.site, code_class_id) |
| 128 | | codeData = self.site.getTableData("CodeClass_%s" % code_class_id, "Code", codeList, codeDataElements, fieldsAsAttributes) |
| 129 | | #panelDataArray.append(codeData) |
| 130 | | |
| 131 | | answerCode = AnswerCode(codeList) |
| 132 | | answerCodeData = self.site.pythonObjectAsTuple(answerCode, codeDataElements) |
| 133 | | panelDataArray.append(answerCodeData) |
| 134 | | |
| 135 | | for code in codeList: |
| 136 | | codeIdList[code.code_id] = "" |
| 137 | | |
| 138 | | for main_code_id in codeIdList.keys(): |
| 139 | | codeList = self.site.getCodeListbyMainCodeId(self.site, main_code_id) |
| 140 | | if len(codeList) > 0: |
| 141 | | answerSubCode = AnswerSubCode(codeList, codeList[0].code_class_id) |
| 142 | | answerSubCodeData = self.site.pythonObjectAsTuple(answerSubCode, codeDataElements) |
| 143 | | panelDataArray.append(answerSubCodeData) |
| 144 | | |
| 145 | | return panelDataArray |
| 146 | | |
| 147 | | def getListOf_CodeClassId(self, conv_questions=[], listOf_CodeClassId={}): |
| 148 | | for conv_question in conv_questions: |
| 149 | | if conv_question.conv_Question_answer_type == 'CLASS': |
| 150 | | listOf_CodeClassId[conv_question.conv_Question_answer_class_id] = conv_question.conv_Question_answer_class_id |
| 151 | | return listOf_CodeClassId |
| 152 | | |
| 153 | | def performAction(self, *pargs, **kwargs): |
| 154 | | self.log.debug('.performAction') |
| 155 | | if self.parameters.has_key('conv_id'): |
| 156 | | chat = self.getChatConversation(self.parameters['conv_id'], *pargs, **kwargs) |
| 157 | | if self.checkParam('action', 'addComment'): |
| 158 | | |
| 159 | | if self.checkNotEmpty('comment_msg_id'): |
| 160 | | """ append this comment to a message """ |
| 161 | | self.site.addComment(self.site, |
| 162 | | self.him_request.session.session_user.user_id, |
| 163 | | self.parameters['comment_text'], |
| 164 | | self.parameters['comment_msg_id']) |
| 165 | | elif self.checkNotEmpty('comment_parent_id'): |
| 166 | | """ append this comment to a comment """ |
| 167 | | self.site.addComment(self.site, |
| 168 | | self.him_request.session.session_user.user_id, |
| 169 | | self.parameters['comment_text'], |
| 170 | | 0, |
| 171 | | self.parameters['comment_parent_id']) |
| 172 | | |
| 173 | | if self.checkParam('action', 'inviteCW'): |
| 174 | | from HelpIM.utils import sendMail |
| 175 | | invitee = self.site.getUserByEmail(self.site, self.getParam('invite_cw_email')) |
| 176 | | if invitee: |
| 177 | | """ add user as reviewer """ |
| 178 | | self.site.addConversationReviewer(self.site, chat, invitee) |
| 179 | | """ send email notification """ |
| 180 | | me = self.him_request.session.session_user |
| 181 | | subject = 'Uitnodiging voor feedback op chat' |
| 182 | | body = '%s heeft je uitgenodigd om feedback te geven op een chatgesprek op\n\nhttp://%s%s/%s?conv_id=%s\n\n%s' % \ |
| 183 | | (me.user_name, |
| 184 | | kwargs['him_request'].environment['HTTP_HOST'], |
| 185 | | self.him_request.SCRIPT_NAME, |
| 186 | | self.function, |
| 187 | | self.getParam('conv_id'), |
| 188 | | self.getParam('invite_cw_text')) |
| 189 | | sendMail(self.site, |
| 190 | | invitee.user_email, |
| 191 | | invitee.user_name, |
| 192 | | subject, |
| 193 | | body) |
| 194 | | self.panelMessage = 'Uitnodiging is verstuurd' |
| 195 | | else: |
| 196 | | self.addError('invite_cw_email', 'Sorry, er is geen gebruiker met dit e-mailadres bekend') |
| 197 | | |
| 198 | | self.site.flush(self.site) |
| 199 | | |
| 200 | | |
| 201 | | def panelDataToObject(self, *pargs, **kwargs): |
| 202 | | registration_questions = kwargs['registration_questions'] |
| 203 | | __conv_Question_answerText = 'conv_Question_answer_' |
| 204 | | visibility = True |
| 205 | | for registration_question in registration_questions: |
| 206 | | parm_name = '%s%s' % (__conv_Question_answerText, registration_question.conv_Question_id) |
| 207 | | if self.parameters.has_key(parm_name) : |
| 208 | | answeredValue = self.parameters[parm_name] |
| 209 | | self.log.debug('.panelDataToObject() parm(%s) value(%s)' % (parm_name, answeredValue)) |
| 210 | | registration_question.setAnswer(answeredValue) |
| 211 | | registration_question.conv_Question_isVisible = visibility |
| 212 | | fc_answerText = "" |
| 213 | | for fixedChoiceAnswer in registration_question.conv_Question_FixedChoiceAnswers: |
| 214 | | fixedChoiceAnswer.conv_FCAnswer_selected = False |
| 215 | | if not isinstance(answeredValue, type([])): |
| 216 | | answeredValue = [answeredValue] |
| 217 | | for answer in answeredValue: |
| 218 | | if fixedChoiceAnswer.conv_FCAnswer_answerCode == answer: |
| 219 | | fixedChoiceAnswer.conv_FCAnswer_selected = True |
| 220 | | if len(fc_answerText) > 0: |
| 221 | | fc_answerText += ", " |
| 222 | | fc_answerText += fixedChoiceAnswer.conv_FCAnswer_answerText |
| 223 | | if fixedChoiceAnswer.conv_FCAnswer_action == 'HIDE': |
| 224 | | visibility = False |
| 225 | | if registration_question.conv_Question_type == 'MK': |
| 226 | | registration_question.conv_Question_answerText = fc_answerText |
| 227 | | if registration_question.conv_Question_answer_type == 'CLASS': |
| 228 | | if self.parameters.has_key(parm_name): |
| 229 | | code_id = self.parameters[parm_name] |
| 230 | | code = self.site.getCodeById(self.site, code_id) |
| 231 | | if code.main_code_id == 0: |
| 232 | | registration_question.conv_Question_answer_main_code_id = code_id |
| 233 | | registration_question.conv_Question_answer_sub_code_id = None |
| 234 | | else: |
| 235 | | registration_question.conv_Question_answer_main_code_id = code.main_code_id |
| 236 | | registration_question.conv_Question_answer_sub_code_id = code_id |
| 237 | | registration_question.conv_Question_answerText = code.code_description |
| 238 | | if registration_question.conv_Question_answer_type == 'CITY': |
| 239 | | if self.parameters.has_key(parm_name): |
| 240 | | registration_question.conv_Question_answer_main_code_id = self.parameters[parm_name] |
| 241 | | registration_question.conv_Question_answer_sub_code_id = None |
| 242 | | registration_question.conv_Question_answerText = self.site.getProvincie(self.parameters[parm_name]) |
| 243 | | |
| 244 | | return registration_questions |
| 245 | | |
| 246 | | |
| 247 | | def getChatConversation(self, conv_id, *pargs, **kwargs): |
| 248 | | if self.chat_conv is None or self.chat_conv.conv_id != conv_id: |
| 249 | | self.chat_conv = self.site.getChatConversationById(self.site, conv_id) |
| 250 | | |
| 251 | | " touch the conv_messages to get them loaded by SqlAlchemy " |
| 252 | | self.chat_conv.conv_messages |
| 253 | | |
| 254 | | for cs in self.chat_conv.conv_care_seekers: |
| 255 | | self.log.debug('Processing CareSeeker id(%s)' % cs.conv_participant_id) |
| 256 | | cs.care_seeker_chat_questions = self.selectConversationQuestionsByQuestionairName(cs.conv_participant_questions, ['CS_PRE_CHAT', 'CS_POST_CHAT']) |
| 257 | | self.log.debug('Processing CareSeeker offered %s questions, got %s questions returned' % (len(cs.conv_participant_questions), len(cs.care_seeker_chat_questions))) |
| 258 | | for cw in self.chat_conv.conv_care_workers: |
| 259 | | self.log.debug('Processing CareWorker id(%s)' % cs.conv_participant_id) |
| 260 | | cw.care_worker_chat_questions = self.selectConversationQuestionsByQuestionairName(cw.conv_participant_questions, ['CW_PRE_CHAT', 'CW_POST_CHAT']) |
| 261 | | self.log.debug('Select CareWorker.["CW_PRE_CHAT", "CW_POST_CHAT"].Questions offered %s questions, got %s questions returned' % (len(cw.conv_participant_questions), len(cw.care_worker_chat_questions))) |
| 262 | | cw.care_worker_registration_questions = self.selectConversationQuestionsByQuestionairName(cw.conv_participant_questions, ['CW_REG']) |
| 263 | | self.log.debug('Select CareWorker.CW_REG.Questions offered %s questions, got %s questions returned' % (len(cw.conv_participant_questions), len(cw.care_worker_registration_questions))) |
| 264 | | |
| 265 | | return self.chat_conv |
| 266 | | |
| 267 | | |
| 268 | | def selectConversationQuestionsByQuestionairName(self, listOfQuestions, questionairNames): |
| 269 | | questionairNames = dict(zip(questionairNames, questionairNames)) |
| 270 | | result = [] |
| 271 | | for question in listOfQuestions: |
| 272 | | if questionairNames.has_key(question.conv_Question_questionairName): |
| 273 | | result.append(question) |
| 274 | | return result |
| 275 | | |
| 276 | | |
| 277 | | class AnswerCode(object): |
| 278 | | def __init__(self, codeList): |
| 279 | | self.codeList = codeList |
| 280 | | self.answerClass = codeList[0].code_class |
| 281 | | |
| 282 | | |
| 283 | | class AnswerSubCode(object): |
| 284 | | def __init__(self, codeList, code_class_id): |
| 285 | | self.codeList = codeList |
| 286 | | self.answerClass = code_class_id |
| 287 | | self.main_code_id = codeList[0].main_code_id |
| 288 | | |