Hi!
I have to anonymize HL7 file (replace all personal data with x). How can i
process an uploaded file "on the fly". This is what i've tried (when it
runs it actually saves the original file content, not the processed)
*# Model*
db.define_table('filetypes',
Field('filetype','string'),
Field('seperator','string'),
Field('omit','string'),
format='%(filetype)s'
)
db.define_table('anonymize',
Field('filetype','reference filetypes'),
Field('uploaded_file','upload')
)
*# Controller*
def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html
if you need a simple wiki simple replace the two lines below with:
return auth.wiki()
"""
form = SQLFORM(db.anonymize)
data = ''
import re
hl7 =
{'PID':{'pattern':'PID\|','separator':'|','omit':(0,1,2,3)},'NK1':{'pattern':'NK1\|','separator':'|','omit':(0,)},'PV1':{'pattern':'PV1\|','separator':'|','omit':(0,)},'IN1':{'pattern':'IN1\|','separator':'|','omit':(0,)}}
if request.vars.uploaded_file != None and
request.vars.uploaded_file.filename != '':
if re.search('|'.join([hl7[k]['pattern'] for k in hl7]),
request.vars.uploaded_file.value):
for line in request.vars.uploaded_file.value.splitlines():
replaced_text = ''
for k in hl7:
replaced_text = '|'.join([len(val) * 'x' if idx not in
hl7[k]['omit'] else val for idx, val in enumerate([splitted_text for
splitted_text in line.split(hl7[k]['separator'])])]) if
re.search(hl7[k]['pattern'],line) else replaced_text
data += (replaced_text if replaced_text != '' else line) +
'\n'
request.vars.uploaded_file.value = data
else:
data = 'No HL7 Format'
else:
data = u'No file chosen'
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
return locals()
I thought that the line
request.vars.uploaded_file.value = data
replaces the original data of the uploaded file, so that the form.process()
processes the new (replaced) value
What i am doing wrong here?
Thanks,
Gerd
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.