예제 #1
0
def dicom_view_jpg(request, message_id, attachment_id, index):
	"""
	Handles download dicom jpg request.
	
	:param request: The HTTP request
	:type request: django.core.handlers.wsgi.WSGIRequest  
	:param message_id: Message uuid
	:type message_id: uuid  
	:param attachment_id: Attachment uuid
	:type attachment_id: uuid
	:returns: django.http.HttpResponse -- the result in an HttpResonse object
	:raises: Exception 
	"""

	form = None
	if (request.method != 'POST'):
		form = MsgGetForm(request.GET)
	else:
		form = MsgGetForm(request.POST)

	if (not form or not form.is_valid()):
		return err_GE031(form)

	try:
		# Get/set up data for KMS.
		request.session['key'] = request.device_assn.secret
		secret = form.cleaned_data['secret']
		return getDicomJPG(request, message_id, attachment_id, index, secret=secret)
	except KeyInvalidException:
		return err_GE021()
예제 #2
0
def check_dicom(request, message_id, attachment_id):
	"""
	Check dicom jpg exsit or not.
	
	:param request: The HTTP request
	:type request: django.core.handlers.wsgi.WSGIRequest  
	:param message_id: Message uuid
	:type message_id: uuid
	:param attachment_id: Attachment uuid
	:type attachment_id: uuid
	:returns: JSON Data
	:raises: Exception 
	"""

	if (request.method != 'POST'):
		return err_GE002()

	form = MsgGetForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	try:
		# Get/set up data for KMS.
		request.session['key'] = request.device_assn.secret
		ret_data = checkDicom(request, message_id, attachment_id, secret=form.cleaned_data['secret'])
		response = {
			'data': ret_data,
			'warnings': {},
		}
		return HttpResponse(content=json.dumps(response), mimetype='application/json')

	except KeyInvalidException:
		return err_GE021()
예제 #3
0
def dicom_view(request, message_id, attachment_id):
	"""
	Handles dicom viewer.
	
	:param request: The HTTP request
	:type request: django.core.handlers.wsgi.WSGIRequest  
	:param message_id: Message uuid
	:type message_id: uuid
	:param attachment_id: Attachment uuid
	:type attachment_id: uuid
	:returns: DicomView.html
	:raises: Exception 
	"""
	if (request.method != 'POST'):
		return err_GE002()

	form = MsgGetForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	try:
		# Get/set up data for KMS.
		device_assn = request.device_assn
		request.session['key'] = device_assn.secret
		secret = form.cleaned_data['secret']
		context = getDicomInfo(request, message_id, attachment_id, 
							dicom_jpg_func_name='MHLogin.apps.smartphone.v1.views_messaging_dicom.dicom_view_jpg',
							secret=secret)

		context["secret"] = secret
		context["device_id"] = device_assn.device_id
		return render_to_response('DoctorCom/Messaging/DicomView_APP.html', context)

	except KeyInvalidException:
		return err_GE021()
예제 #4
0
def get_refer_pdf(request, refer_id):
	"""
	get_refer_pdf

	:param request: Request info
	:type request: django.core.handlers.wsgi.WSGIRequest
	:param refer_id: referall id
	:type refer_id: uuid
	:returns: django.http.HttpResponse -- the result in an HttpResonse object
	"""
	if (request.method != 'POST'):
		return err_GE002()
	form = MsgGetForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	refer = get_object_or_404(MessageRefer, uuid=refer_id)

	message = refer.message
	if ((message.sender and request.user.pk != message.sender.pk) and
		not ((request.user.pk,) in message.recipients.values_list('id') or
			(request.user.pk,) in message.ccs.values_list('id'))):
		return err403(request, err_msg=_("You don't seem to be a valid recipient for this file."))

	# Get/set up data for KMS.
	request.session['key'] = request.device_assn.secret
	try:
		clearkey = decrypt_cipherkey(request, refer, ss=form.cleaned_data['secret'])
	except KeyInvalidException:
		return err_GE021()

	try:
		response = refer.get_file(request, clearkey)
		return response
	except Exception as e:
		err_email_body = '\n'.join([
				('PDF file not exist!'),
				''.join(['Server: ', settings.SERVER_ADDRESS]),
				''.join(['Session: ', str(request.session.session_key)]),
				''.join(['Message: ', (u'PDF file not exist in media/refer/pdf')]),
				''.join(['Exception: ', str(e)]),
				''.join(['Exception data: ', str(e.args)]),
			])
		mail_admins(_('PDF folder not exist'), err_email_body)
		raise Exception(_('A seemingly invalid URL has been stored for Refer Pdf.'))
예제 #5
0
def get_attachment(request, message_id, attachment_id):
	if (request.method != 'POST'):
		return err_GE002()
	form = MsgGetForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	attachment = get_object_or_404(MessageAttachment, message__uuid=message_id, uuid=attachment_id)
	message = attachment.message

	if ((message.sender and request.user.pk != message.sender.pk) and
		not ((request.user.pk,) in message.recipients.values_list('id') or
			(request.user.pk,) in message.ccs.values_list('id'))):
		return err403(request, err_msg="You don't seem to be a valid recipient for this file.")

	# Get/set up data for KMS.
	request.session['key'] = request.device_assn.secret
	try:
		clearkey = decrypt_cipherkey(request, attachment, ss=form.cleaned_data['secret'])
	except KeyInvalidException:
		return err_GE021()

	url = attachment.decrypt_url(request, key=clearkey)
	if (url[0:4] == 'file'):
		response = HttpResponse(content_type=attachment.content_type)
		attachment.get_file(request, response)
		return response

	elif (url[0:4] == 'http'):
		# This is likely a fully qualified URL
		if (not attachment.encrypted):
			return HttpResponseRedirect(url)
		else:
			# Download and decrypt this attachment.
			pass
	else:
		raise Exception('A seemingly invalid URL has been stored: %s, '
			'for MessageAttachment %s.' % (url, attachment_id,))
예제 #6
0
def dicom_info(request, message_id, attachment_id):
	"""
	Handles dicom viewer.
	
	:param request: The HTTP request
	:type request: django.core.handlers.wsgi.WSGIRequest  
	:param message_id: Message uuid
	:type message_id: uuid
	:param attachment_id: Attachment uuid
	:type attachment_id: uuid
	:returns: json
	:raises: Exception 
	"""
	if (request.method != 'POST'):
		return err_GE002()

	form = MsgGetForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	try:
		# Get/set up data for KMS.
		device_assn = request.device_assn
		request.session['key'] = device_assn.secret
		secret = form.cleaned_data['secret']
		context = getDicomInfo(request, message_id, attachment_id, 
							dicom_jpg_func_name='MHLogin.apps.smartphone.v1.views_messaging_dicom.dicom_view_jpg',
							secret=secret)

		response = {
			'data': context,
			'warnings': {},
		}
		return HttpResponse(content=json.dumps(response), mimetype='application/json')

	except KeyInvalidException:
		return err_GE021()
예제 #7
0
def get_message_details(request):
	if (request.method != 'POST'):
		return err_GE002()
	form = GetMsgDetailsForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	message_uuids = form.cleaned_data['message_uuids']

	msgss = list(MessageBodyUserStatus.objects.filter(user=request.user,
					delete_flag=False, msg_body__message__uuid__in=message_uuids)
			.extra(select={'sender_title':"SELECT MHLUsers_mhluser.title \
				FROM MHLUsers_mhluser INNER JOIN Messaging_message ON \
				MHLUsers_mhluser.user_ptr_id = Messaging_message.sender_id \
				INNER JOIN  Messaging_messagebody ON \
				Messaging_message.id = Messaging_messagebody.message_id \
				WHERE Messaging_messagebody.id = Messaging_messagebodyuserstatus.msg_body_id"})
			.order_by('-msg_body__message__send_timestamp')
			.select_related('msg_body', 'msg_body__message', 'msg_body__message__sender'))

	if (len(msgss) == 0):
		raise Http404

	# Get/set up data for KMS.
	request.session['key'] = request.device_assn.secret
	ss = form.cleaned_data['secret']

	recipients = MessageRecipient.objects.filter(message__uuid__in=message_uuids) \
						.select_related('user', 'message')\
						.only('user__first_name', 'user__last_name',
								'message__uuid')
	recp_dict = convert_query_set_to_dict_with_uuid(recipients)

	ccs = MessageCC.objects.filter(message__uuid__in=message_uuids)\
						.select_related('user', 'message')\
						.only('user__first_name', 'user__last_name', 'message__uuid')
	cc_dict = convert_query_set_to_dict_with_uuid(ccs)

	attachments = MessageAttachment.objects.filter(message__uuid__in=message_uuids)\
						.select_related('message')
	attach_dict = convert_query_set_to_dict_with_uuid(attachments)

	mahs = MessageActionHistory.objects.filter(message__uuid__in=message_uuids)\
				.select_related('user', 'message')\
				.extra(select={'title':'SELECT title FROM MHLUsers_mhluser \
					WHERE MHLUsers_mhluser.user_ptr_id = Messaging_messageactionhistory.user_id'})
	mah_dict = convert_query_set_to_dict_with_uuid(mahs)

	refers = MessageRefer.objects.filter(message__uuid__in=message_uuids)\
				.select_related('message')
	refer_dict = convert_query_set_to_dict_with_uuid(refers)

	user = request.user
	local_tz = getCurrentTimeZoneForUser(user)
	current_user = request.role_user
	current_user_mobile = current_user.user.mobile_phone

	ret_msgs = []
	for status_obj in msgss:
		try:
			read_message(request, status_obj.msg_body, ss=ss)
		except KeyInvalidException:
			return err_GE021()
		msg = status_obj.msg_body.message
		msg_uuid = msg.uuid
		recipients = []
		if msg_uuid in recp_dict:
			recipients = [{
						'name': get_fullname_bystr(msg.sender.last_name,
							msg.sender.first_name,status_obj.sender_title),
						'id': u.user.id,
						} for u in recp_dict[msg_uuid]]

		ccs = []
		if msg_uuid in cc_dict:
			ccs = [{
						'name': get_fullname_bystr(u.user.last_name,
									u.user.first_name, u.title),
						'id': u.user.id,
						} for u in cc_dict[msg_uuid]]
		attachments = []
		if msg_uuid in attach_dict:
			attachments = [
					{
						'id': att.uuid,
						'filename': get_attachment_filename(request, att, ss),
						'filesize': att.size,
						'suffix':att.suffix,
					} for att in attach_dict[msg_uuid]]
		refer = None
		if msg_uuid in refer_dict:
			refer = _get_refer_from_mbus(status_obj, logo_size="Large", 
										refers=refer_dict[msg_uuid])
		action_history = []
		if msg_uuid in mah_dict:
			action_history = render_action_histories(mah_dict[msg_uuid], 
								user=user, time_zone=local_tz)

		ret_msgs.append({
			'body': status_obj.msg_body.clear_data,
			'timestamp': formatTimeSetting(user, msg.send_timestamp, 
									local_tz, True),
			'send_timestamp': msg.send_timestamp,
			'sender': {
						'name': get_fullname_bystr(msg.sender.last_name,
									msg.sender.first_name,status_obj.sender_title)\
										if msg.sender else "System Message",
						'id': msg.sender.id if msg.sender else 0,
					},
			'recipients': recipients,
			'ccs': ccs,
			'attachments': attachments,
			'message_type': msg.message_type if msg.message_type else 'NM',
			'callback_number': msg.callback_number,
			'callback_available': settings.CALL_ENABLE and bool(msg.callback_number)
				and bool(current_user_mobile),
			'urgent': bool(msg.urgent),
			'resolution_flag': bool(msg._resolved_by_id),
			'refer': refer,
			'thread_uuid': msg.thread_uuid,
			'action_history': action_history,
			'action_history_count': len(action_history)
		})

	response = {
		'data': ret_msgs,
		'warnings': {},
	}

	return HttpResponse(content=json.dumps(response), mimetype='application/json')
예제 #8
0
def get_message(request, message_id):
	if (request.method != 'POST'):
		return err_GE002()
	form = MsgGetForm(request.POST)
	if (not form.is_valid()):
		return err_GE031(form)

	msgs = list(MessageBodyUserStatus.objects.filter(user=request.user,
					delete_flag=False, msg_body__message__uuid=message_id)
			.extra(select={'sender_title':"SELECT MHLUsers_mhluser.title \
				FROM MHLUsers_mhluser INNER JOIN Messaging_message ON \
				MHLUsers_mhluser.user_ptr_id = Messaging_message.sender_id \
				INNER JOIN  Messaging_messagebody ON \
				Messaging_message.id = Messaging_messagebody.message_id \
				WHERE Messaging_messagebody.id = Messaging_messagebodyuserstatus.msg_body_id"}).
			order_by('-msg_body__message__send_timestamp').select_related(
				'msg_body', 'msg_body__message', 'msg_body__message__sender'))\

	# Integrity check.
	if (len(msgs) > 1):
		# shouldn't be possible!
		mail_admins('Duplicate message ID', ' '.join(['server: ',
				settings.SERVER_ADDRESS, '\n',
				'The message id with uuid', message_id, 'has returned with',
				'more than one Message!\nAt: ',
				str(inspect.getfile(inspect.currentframe())), ':',
						str(inspect.currentframe().f_back.f_lineno)
			]))
	if (len(msgs) == 0):
		raise Http404

	status_obj = msgs[0]

	# Get/set up data for KMS.
	request.session['key'] = request.device_assn.secret
	ss = form.cleaned_data['secret']

	current_user = request.role_user
	current_user_mobile = current_user.user.mobile_phone
	try:
		read_message(request, status_obj.msg_body, ss=ss)
	except KeyInvalidException:
		return err_GE021()
	msg = status_obj.msg_body.message
	recipients = MessageRecipient.objects.filter(message__uuid=message_id).\
		select_related('user').extra(select={'title':'SELECT title FROM MHLUsers_mhluser \
			WHERE MHLUsers_mhluser.user_ptr_id = Messaging_message_recipients.user_id'}).\
		only('user__first_name', 'user__last_name')

	attachments = MessageAttachment.objects.filter(message=msg)

	ccs = MessageCC.objects.filter(message__uuid=message_id).select_related('user').\
		extra(select={'title':'SELECT title FROM MHLUsers_mhluser \
			WHERE MHLUsers_mhluser.user_ptr_id = Messaging_message_ccs.user_id'}).\
		only('user__first_name', 'user__last_name', 'message')

	use_time_setting = False
	if 'use_time_setting' in request.POST and request.POST['use_time_setting'] == 'true':
		use_time_setting = True
	user = request.user
	local_tz = getCurrentTimeZoneForUser(user)
	action_history = get_message_action_history(status_obj.msg_body.message.id)
	response = {
		'data': {
				'body': status_obj.msg_body.clear_data,
				'timestamp': formatTimeSetting(user, msg.send_timestamp, 
										local_tz, use_time_setting),
				'send_timestamp': msg.send_timestamp,
				'sender': {
							'name': get_fullname_bystr(msg.sender.last_name,msg.sender.first_name,status_obj.sender_title)\
										if msg.sender else "System Message",
							'id': msg.sender.id if msg.sender else 0,
						},
				'recipients': [{
							'name': get_fullname_bystr(u.user.last_name,u.user.first_name,u.title),
							'id': u.user.id,
							} for u in recipients],
				'ccs': [{
							'name': get_fullname_bystr(u.user.last_name,u.user.first_name,u.title),
							'id': u.user.id,
							} for u in ccs],
				'attachments': [
						{
							'id': att.uuid,
							'filename': get_attachment_filename(request, att, ss),
							'filesize': att.size,
							'suffix':att.suffix,
						} for att in attachments],
				'message_type': msg.message_type if msg.message_type else 'NM',
				'callback_number': msg.callback_number,
				'callback_available': settings.CALL_ENABLE and bool(msg.callback_number)
					and bool(current_user_mobile),
				'urgent': bool(msg.urgent),
				'resolution_flag': bool(msg._resolved_by_id),
				'refer': _get_refer_from_mbus(status_obj, logo_size="Large"),
				'thread_uuid': msg.thread_uuid,
				'action_history': action_history,
				'action_history_count': len(action_history)
			},
		'warnings': {},
	}

	return HttpResponse(content=json.dumps(response), mimetype='application/json')