-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #16 Support creating and editing drug exposures.
- Loading branch information
Showing
30 changed files
with
773 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
class Interleave.DrugExposure | ||
constructor: () -> | ||
render: (link) -> | ||
$(link).on 'click', (e) -> | ||
$modal = $('#drug_exposure_modal') | ||
$drug_exposure = $('#drug_exposure_modal .drug_exposure') | ||
$.ajax(this.href).done (response) -> | ||
$drug_exposure.html(response) | ||
$modal.foundation 'open' | ||
$('.datepicker').datepicker | ||
onClose: (dateText, inst) -> | ||
$(inst.input).focusout() | ||
return | ||
changeMonth: true | ||
changeYear: true | ||
interleaveDatapointConceptsUrl = $('#concepts_interleave_datapoint_url').attr('href') | ||
$('.drug_exposure_form').enableClientSideValidations() | ||
$('#drug_exposure_drug_concept_id').select2 | ||
ajax: | ||
url: interleaveDatapointConceptsUrl | ||
dataType: 'json' | ||
delay: 250 | ||
data: (params) -> | ||
{ | ||
q: params.term | ||
page: params.page | ||
} | ||
processResults: (data, params) -> | ||
params.page = params.page or 1 | ||
results = $.map(data.concepts, (obj) -> | ||
obj.id = obj.concept_id | ||
obj.text = obj.text | ||
obj | ||
) | ||
|
||
{ | ||
results: results | ||
pagination: more: params.page * 10 < data.total | ||
} | ||
cache: true | ||
escapeMarkup: (markup) -> | ||
markup | ||
minimumInputLength: 2 | ||
|
||
$('#drug_exposure_condition_concept_id').on 'select2:select', (e) -> | ||
$(this).blur() | ||
return | ||
|
||
$('.drug_exposure_form').on('ajax:success', (e, data, status, xhr) -> | ||
$modal.foundation 'close' | ||
Turbolinks.visit(location.toString()) | ||
$('.drug_exposures_list').fadeOut() | ||
).on 'ajax:error', (e, xhr, status, error) -> | ||
|
||
$('.drug_exposure_form .cancel-link').on 'click', (e) -> | ||
$modal.foundation 'close' | ||
e.preventDefault() | ||
|
||
return | ||
e.preventDefault() | ||
return | ||
return | ||
|
||
$(document).on 'page:load ready', -> | ||
return unless $('.drug_exposures.index').length > 0 | ||
ui = new Interleave.DrugExposure | ||
ui.render('.drug_exposure_link') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#drug_exposures { | ||
@include grid-row(); | ||
|
||
.interleave_datapoint { | ||
@include grid-column( | ||
$columns: 20 | ||
); | ||
} | ||
|
||
.drug_exposures_list { | ||
@include grid-column( | ||
$columns: 24 | ||
); | ||
|
||
th .current { | ||
padding-right: 2em; | ||
background-repeat: no-repeat; | ||
background-position: right center; | ||
} | ||
|
||
th .asc { | ||
background-image: asset_url("drop25.png"); | ||
} | ||
|
||
th .desc { | ||
background-image: asset_url("drop27.png"); | ||
} | ||
|
||
table { | ||
@include grid-column( | ||
$columns: 24 | ||
); | ||
} | ||
} | ||
} | ||
|
||
#drug_exposure_modal { | ||
position: fixed; | ||
bottom: 0; | ||
top: 30% !important; | ||
right: 0; | ||
left: 0; | ||
width: 100%; | ||
} | ||
|
||
#drug_exposure { | ||
@include grid-row(); | ||
|
||
.ui-autocomplete-input { | ||
width: 90%; | ||
height: 2.5rem; | ||
} | ||
.ui-button { | ||
width: 5%; | ||
height: 2.5rem; | ||
} | ||
|
||
.drug_exposure_start_date { | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
input { | ||
margin-bottom: 0; | ||
} | ||
} | ||
.drug_exposure_end_date { | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
input { | ||
margin-bottom: 0; | ||
} | ||
} | ||
.drug_concept_id { | ||
label { | ||
display: block; | ||
} | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
select { | ||
margin-bottom: 0; | ||
} | ||
|
||
.select2 { | ||
width: 100% !important; | ||
} | ||
} | ||
|
||
.drug_type_concept_id { | ||
label { | ||
display: block; | ||
} | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
select { | ||
margin-bottom: 0; | ||
} | ||
} | ||
.navigation { | ||
padding: 1rem; | ||
@include grid-column-offset(12); | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
class DrugExposuresController < ApplicationController | ||
helper_method :sort_column, :sort_direction | ||
before_filter :load_interleave_registry, only: [:index, :new, :create, :edit] | ||
before_filter :load_interleave_person, only: [:index, :new, :create, :edit] | ||
before_filter :load_drug_exposure, only: [:edit, :update] | ||
before_filter :load_interleave_datapoint, only: [:new, :edit] | ||
|
||
def index | ||
params[:page]||= 1 | ||
options = {} | ||
options[:sort_column] = sort_column | ||
options[:sort_direction] = sort_direction | ||
@datapoint = @registry.interleave_datapoints.find(params[:datapoint_id]) | ||
add_breadcrumbs(registry: @registry, interleave_person: @interleave_person, datapoint: @datapoint) | ||
@drug_exposures = DrugExposure.by_person(@interleave_person.person.person_id).by_interleave_data_point(@datapoint.id, options).paginate(per_page: 10, page: params[:page]) | ||
end | ||
|
||
def new | ||
@drug_exposure = DrugExposure.new() | ||
@drug_exposure.interleave_datapoint = @datapoint | ||
@datapoint.initialize_defaults(@drug_exposure) | ||
@concepts = [] | ||
@type_concepts = load_concepts('drug_type_concept_id') | ||
@route_concepts = load_concepts('route_concept_id') | ||
# @dose_unit_concepts = [] | ||
respond_to do |format| | ||
format.html { render :layout => false } | ||
end | ||
end | ||
|
||
def create | ||
@drug_exposure = DrugExposure.new(drug_exposure_params) | ||
interleave_registry_cdm_source = @registry.interleave_registry_cdm_sources.where(cdm_source_name: InterleaveRegistryCdmSource::CDM_SOURCE_EX_NIHILO).first | ||
@drug_exposure.person = @interleave_person.person | ||
respond_to do |format| | ||
if @drug_exposure.create_with_sub_datapoints!(interleave_registry_cdm_source) | ||
format.js { } | ||
else | ||
format.js { render json: { errors: @drug_exposure.errors.full_messages }, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
@drug_exposure.interleave_datapoint = @datapoint | ||
@concepts = [[@drug_exposure.drug_concept.concept_name, @drug_exposure.drug_concept_id]] | ||
@type_concepts = load_concepts('drug_type_concept_id') | ||
@route_concepts = load_concepts('route_concept_id') | ||
# @dose_unit_concepts = [[@drug_exposure.dose_unit_concept.concept_name, @drug_exposure.dose_unit_concept_id]] | ||
|
||
respond_to do |format| | ||
format.html { render :layout => false } | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @drug_exposure.update_attributes(drug_exposure_params) | ||
format.js { } | ||
else | ||
format.js { render json: { errors: @drug_exposure.errors.full_messages }, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
def drug_exposure_params | ||
params.require(:drug_exposure).permit(:interleave_datapoint_id, :drug_concept_id, :drug_exposure_start_date, :drug_exposure_end_date, :drug_type_concept_id, :route_concept_id, :dose_unit_concept_id) | ||
end | ||
|
||
def load_drug_exposure | ||
@drug_exposure = DrugExposure.find(params[:id]) | ||
end | ||
|
||
def sort_column | ||
['drug_exposure_start_date', 'drug_exposure_end_date', 'drug_concept.concept_name', 'drug_type_concept.concept_name'].include?(params[:sort]) ? params[:sort] : 'drug_exposure_start_date' | ||
end | ||
|
||
def sort_direction | ||
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' | ||
end | ||
end |
Oops, something went wrong.