Skip to content

Commit

Permalink
additional fix for issue #34
Browse files Browse the repository at this point in the history
  • Loading branch information
seg1129 committed Nov 7, 2017
1 parent c406764 commit 38902b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
22 changes: 16 additions & 6 deletions ehb_datasources/drivers/nautilus/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ehbDriver(Driver, RequestHandler):
NAU_REC_EXT_REF = 'ext-ref'
VALID_NAU_ELEM_IDENTIFIERS = [NAU_REC_ID, NAU_REC_NAME, NAU_REC_EXT_REF]
NAU_ERROR_MAP = {
'': 'UNKNOWN ERROR.',
'0': 'UNKNOWN ERROR.',
'1': 'Unable to communicate with Laboratory System because of expired or incorrect credentials.',
'2': 'Username not provided.',
Expand All @@ -35,7 +36,8 @@ class ehbDriver(Driver, RequestHandler):
'7': 'Unsupported request type.',
'8': 'Form data is not valid.',
'100': 'NAU socket service not found.',
'101': 'NAU invalid authorization header.'
'101': 'NAU invalid authorization header.',
'500': 'server error.'
}

def __init__(self, url, user, password, secure):
Expand Down Expand Up @@ -136,17 +138,25 @@ def get_sample_data(self, *args, **kwargs):
try:
return json.loads(response)[0]
except KeyError:
try: # grab error number and process error
try: # grab error number and process error
responseDict = json.loads(response)
status = responseDict['error']
errorMsg = self.NAU_ERROR_MAP.get(status, 'UNKNOWN ERROR')
log.error(errorMsg)
return {"error": errorMsg}
except TypeError:
pass
except KeyError:
except (KeyError, TypeError):
log.error('Error retrieving sample data')
return {"error": "Unable to retrieve sample data"}
return {"error": "Unable to retrieve sample data."}
except IndexError:
if (response == '[]'):
log.error('Zero samples returned, validate user has access to protocol in nautilus.')
return {"error": "Zero samples returned, validate user has access to protocol in nautilus."}
else:
log.error('Error retrieving sample data')
return {"error": "Unable to retrieve sample data."}
except:
log.error('Error retrieving sample data')
return {"error": "Unable to retrieve sample data."}

def extract_aliquots(self, sample_data):
aliquots = []
Expand Down
8 changes: 5 additions & 3 deletions ehb_datasources/drivers/redcap/formBuilderJson.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,17 @@ def build_field(self, field, record, master_dependency_map):
ffi[name]={'type':ft}
field_class="field_input"
text_field_id="input_"+field.get('field_name')
today_button=''
if field.get('text_validation_type_or_show_slider_number') == 'date_ymd':
field_class="field_input_date form-control"
text_field_id="date"+text_field_id
today_button="""<input type="button" value="Today" class="todaybutton" id="datebtn_{0}" /> <br/>
<span style="color:red" class="datespan" id="datespan_{0}"></span>""".format(field.get('field_name'))
return """<div class="col-xs-3 date-field"><div class="input-group date"><input style="min-width: 100px;" type="text" value="{0}" name="{1}" class="{2}" id="{3}" {4} /><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span></div></div>{5}
""".format(value, name, field_class, text_field_id, onchange, today_button)
return """<div class="date-field"><div class="input-group date"><input style="min-width: 100px;" type="text" value="{0}" name="{1}" class="{2}" id="{3}" {4} /><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span></div></div>{5}
""".format(value, name, field_class, text_field_id, onchange, today_button)

return """<input type="text" value="{0}" name="{1}" class="{2}" id="{3}" {4} />
""".format(value, name, field_class, text_field_id, onchange)
""".format(value, name, field_class, text_field_id, onchange, today_button)
elif ft == 'notes':
ffi[name]={'type':ft}
return """<textarea rows="5" cols="20" name="{0}" class="field_input" {1}>{2}</textarea>
Expand Down
3 changes: 1 addition & 2 deletions ehb_datasources/tests/unit_tests/test_form_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def test_construct_form(form_builder, redcap_metadata_json, redcap_record_json):
assert '<input type="text" value="100" name="height" class="field_input" id="input_height" />' in form
assert '<input type="text" value="20" name="weight" class="field_input" id="input_weight" />' in form
assert '<textarea rows="5" cols="20" name="comments" class="field_input" >Test Data2</textarea>' in form



def test_construct_form2_branch_logic_functions(form_builder, redcap_metadata_json2, redcap_record_json2):
form = form_builder.construct_form(
json.loads(redcap_metadata_json2.decode('utf-8')),
Expand Down

0 comments on commit 38902b9

Please sign in to comment.