Skip to content

Commit

Permalink
added code for database connection and default data rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
SushantTamu committed Nov 9, 2023
1 parent dd59465 commit 4de917f
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 76 deletions.
45 changes: 35 additions & 10 deletions app/controllers/child_level_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def show

# GET /child_level_details/new
def new
@child_level_detail = ChildLevelDetail.new

@child_level_detail = ChildLevelDetail.new

end

# GET /child_level_details/1/edit
Expand All @@ -22,20 +24,33 @@ def edit

# POST /child_level_details or /child_level_details.json
def create

@child_level_detail = ChildLevelDetail.new(child_level_detail_params)

pid = params[:child_level_detail][:PID]
@child_level_detail = ChildLevelDetail.find_by(PID: pid)
respond_to do |format|
if @child_level_detail.save
format.html { redirect_to child_level_detail_url(@child_level_detail),
notice: "Child level detail was successfully created." }
format.json { render :show, status: :created, location: @child_level_detail }
if @child_level_detail
# A record with the same PID was found; update it
if @child_level_detail.update(child_level_detail_params)
format.html { redirect_to "/child_data?patient_detail_id=#{pid}" }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @child_level_detail.errors, status: :unprocessable_entity }
end
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @child_level_detail.errors, status: :unprocessable_entity }
# No record with the PID was found; create a new one
@child_level_detail = ChildLevelDetail.new(child_level_detail_params.merge(PID: pid))
if @child_level_detail.save
format.html { redirect_to "/child_data?patient_detail_id=#{pid}" }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @child_level_detail.errors, status: :unprocessable_entity }
end
end
end
end




# PATCH/PUT /child_level_details/1 or /child_level_details/1.json
def update
Expand Down Expand Up @@ -64,6 +79,16 @@ def destroy
def child_data
@patient_detail = PatientDetail.find(params[:patient_detail_id])
@pid = @patient_detail.PID

@child_data1 = ChildLevelDetail.find_by(PID: @pid)
# @abc=@child_data1.PrescriberName

# if @child_data1.PID.blank?
# @child_data1 = ChildLevelDetail.new

# end


end

private
Expand Down
22 changes: 11 additions & 11 deletions app/javascript/formSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ document.addEventListener("submit", function(event) {
if (event.submitter && event.submitter.id === "submitButton") {
var form = event.target;

var childLevelDetailID = new URLSearchParams(window.location.search).get('patient_detail_id');
// var pid = form.querySelector('[name="child_level_detail[PID]"]').value;
// var childLevelDetailID = new URLSearchParams(window.location.search).get('patient_detail_id');
// // var pid = form.querySelector('[name="child_level_detail[PID]"]').value;

if (childLevelDetailID) {
// If an ID exists, this is an update
form.action = '/child_level_details/' + childLevelDetailID;
form.method = 'patch';
} else {
// If there's no ID, it's a new record creation
form.action = '/patient_details/' + pid + '/child_level_details';
form.method = 'post';
}
// if (childLevelDetailID) {
// // If an ID exists, this is an update
// form.action = '/child_level_details/' + childLevelDetailID;
// form.method = 'patch';
// } else {
// // If there's no ID, it's a new record creation
// form.action = '/patient_details/' + pid + '/child_level_details';
// form.method = 'post';
// }

// Set the value of TeethScreening using your existing logic
var TeethScreeningStr = JSON.stringify(selectedOptions);
Expand Down
161 changes: 155 additions & 6 deletions app/views/child_level_details/child_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,171 @@
Back
</button>
<br/>
<%= form_with model: @child_level_detail, url: child_level_details_path, local: true, id: 'unique-form-id' do |form| %>

<%= form_with model: @child_level_detail, url: child_level_details_path, method: :post, local: true, id: 'unique-form-id' do |form| %>
<div id="preventativeFormContainer" style="display: none;">
<%= render 'preventative_form', form: form %>

<div class="form-group">
<label for="prescriberName">Sealant Prescriber’s Signature</label>
<input type="text" id="prescriberName" name="child_level_detail[PrescriberName]" value="<%= @child_data1 ? @child_data1.PrescriberName : '' %>">

</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" id="date" name="child_level_detail[ScreenDate]"value="<%= @child_data1 ? @child_data1.ScreenDate : '' %>">
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea id="comment" name="child_level_detail[ScreenComment]" rows="2" cols="20"><%= @child_data1&.ScreenComment.presence || '' %></textarea>

</div>
<div class="form-group">
<label for="providerName">Provider's Name</label>
<input type="text" id="providerName" name="child_level_detail[ProviderName]" value="<%= @child_data1 ? @child_data1.ProviderName : '' %>">
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" id="date" name="child_level_detail[ProviderDate]"value="<%= @child_data1 ? @child_data1.ProviderDate : '' %>">
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea id="comment" rows="2" cols="20" name="child_level_detail[PreventComment]"value="<%= @child_data1 ? @child_data1.PreventComment : '' %>"></textarea>
</div>
<div class="form-section">
<h3>Data for SEALS</h3>
</div>
<div class="form-group">
<label for="num1stMolarsSealed">Number of 1st molars sealed</label>
<input type="text" id="num1stMolarsSealed" name="child_level_detail[FirstSealedNum]"value="<%= @child_data1 ? @child_data1.FirstSealedNum : '' %>">
</div>
<div class="form-group">
<label for="num2ndMolarsSealed">Number of 2nd molars sealed</label>
<input type="text" id="num2ndMolarsSealed" name="child_level_detail[SecondSealedNum]"value="<%= @child_data1 ? @child_data1.SecondSealedNum : '' %>">
</div>
<div class="form-group">
<label for="numOtherSealed">Number of other permanent sealed</label>
<input type="text" id="numOtherSealed"name="child_level_detail[OtherPermNum]" value="<%= @child_data1 ? @child_data1.OtherPermNum : '' %>">
</div>
<div class="form-group">
<label for="numPrimaryTeethSealed">Number of primary teeth sealed</label>
<input type="text" id="numPrimaryTeethSealed" name="child_level_detail[PrimarySealed]" value="<%= @child_data1 ? @child_data1.PrimarySealed : '' %>">
</div>
<div class="form-group">
<label for="fluorideVarnish">Fluoride varnish provided</label>
<select name="child_level_detail[FluorideVarnish]" id="fluorideVarnish">
<option value="" <%= 'selected' if @child_data1&.FluorideVarnish.blank? %>>--Please select an option--</option>
<option value="Yes" <%= 'selected' if @child_data1&.FluorideVarnish == 'Yes' %>>Yes</option>
<option value="No" <%= 'selected' if @child_data1&.FluorideVarnish == 'No' %>>No</option>
</select>
</div>


<br/>
</div>

<div id="followUpFormContainer" style="display: none;">
<%= render 'followup_form', form: form %>
<br/>
<div>
<label for="Evaluator's Name">Evaluator's Name</label>
<input type="text" id="1st-molars" name="child_level_detail[EvaluatorsName]" value="<%= @child_data1 ? @child_data1.EvaluatorsName : '' %>">
</div>
<br/>
<div>
<label for="date">Date</label>
<label for="blank"></label>
<input type="date" id="date" name="date" name="child_level_detail[EvaluatorDate]" value="<%= @child_data1 ? @child_data1.EvaluatorDate : '' %>"><br>
</div>
<br/>
<div>
<label for="Comment">Comment</label>
<textarea id="comment" rows="2" cols="20" name="child_level_detail[EvaluatorComment]" value="<%= @child_data1 ? @child_data1.EvaluatorComment : '' %>"></textarea><br>
</div>
<br/>
<br/>
<div>
<H3>Data for SEALS</H3>
</div>
<div>
<label for="Number of teeth with retained sealant">Number of teeth with a retained sealant (0-8):</label>
<input type="text" id="Number_of_teeth_with_a_retained_sealant" name="child_level_detail[RetainedSealant]" value="<%= @child_data1 ? @child_data1.RetainedSealant : '' %>">
</div>
<br/>

<div>
<label for="Referred for Dental Treatment">Referred for Dental Treatment?</label>
<label for="Yes"> </label>
<label for="Yes">Yes</label>
<input type="radio" name="child_level_detail[ReferredDT]" value="yes" id="Referred_for_Dental_Treatment_Yes" value="<%= @child_data1 ? @child_data1.ReferredDT : '' %>">
<label for="No">No</label>
<input type="radio" name="child_level_detail[ReferredDT]" value="no" id="Referred_for_Dental_Treatment_No" value="<%= @child_data1 ? @child_data1.ReferredDT : '' %>">
</div>

<br/>

<div>
<label for="Referred for urgent Dental Treatment">Referred for urgent Dental Treatment?</label>
<label for="blank"> </label>
<label for="Yes">Yes</label>
<input type="radio" name="child_level_detail[ReferredUDT]" value="yes" id="Referred_for_urgent_Dental_Treatment_Yes" value="<%= @child_data1 ? @child_data1.ReferredUDT : '' %>">
<label for="No">No</label>
<input type="radio" name="child_level_detail[ReferredUDT]" value="no" id="Referred_for_urgent_Dental_Treatment_No" value="<%= @child_data1 ? @child_data1.ReferredUDT : '' %>">
</div>
<br/>

<div>
<label for="Total Number of Sealants received">Total Number of Sealants received:</label>
<input type="text" id="Total_Sealants_received" name="child_level_detail[SealantsRecd]" value="<%= @child_data1 ? @child_data1.SealantsRecd : '' %>">
</div>
<br/>

<div>
<label for="Total Number of Sealants needed">Total Number of Sealants needed:</label>
<input type="text" id="Total_Sealants_needed" name="child_level_detail[SealnatsNeeded]" value="<%= @child_data1 ? @child_data1.SealnatsNeeded : '' %>">
</div>
<br/>

<div>
<label for="Did the patients have caries experience">Did the patients have caries experience?</label>
<label for="blank"> </label>
<label for="Yes">Yes</label>
<input type="radio" name="child_level_detail[Experienced]" value="yes" id="Did_the_patients_have_caries_experience_Yes" value="<%= @child_data1 ? @child_data1.Experienced : '' %>">
<label for="No">No</label>
<input type="radio" name="child_level_detail[Experienced]" value="no" id="Did_the_patients_have_caries_experience_No" value="<%= @child_data1 ? @child_data1.Experienced : '' %>">
</div>
<br/>

<div>
<label for="Did the patient have untreated decay">Did the patient have untreated decay?</label>
<label for="blank"> </label>
<label for="Yes">Yes</label>
<input type="radio" name="child_level_detail[UntreatedDecayFollow]" value="yes" id="Did_the_patient_have_untreated_decay_Yes" value="<%= @child_data1 ? @child_data1.UntreatedDecayFollow : '' %>">
<label for="No">No</label>
<input type="radio" name="child_level_detail[UntreatedDecayFollow]" value="no" id="Did_the_patient_have_untreated_decay_No" value="<%= @child_data1 ? @child_data1.UntreatedDecayFollow : '' %>">
</div>
<br/>

<div>
<label for="Services the patient received">Services the patient received</label>
<label for="blank"> </label>
<select name="child_level_detail[Services]" value="<%= @child_data1 ? @child_data1.Services : '' %>">
<option value="">--Please select an option--</option>
<option value="Sealants">Sealants</option>
<option value="Fluoride_Varnish">Fluoride Varnish</option>
<option value="Oral_Assessment">Oral Assessment</option>
<option value="Prophylaxes">Prophylaxes</option>
</select>
</div>
<br/>
<label for="Overall Oral Health Status">Overall Oral Health Status:</label><br>
<textarea id="Overall_Oral_Health_Status" name="child_level_detail[ORHealthStatus]" value="<%= @child_data1 ? @child_data1.ORHealthStatus : '' %>" rows="4" cols="50"></textarea><br>
<br/>
</div>
<br/>
<%= form.hidden_field :PID, value: @pid %>

<input type="hidden" id="PID" name="child_level_detail[PID]" value="<%= @pid %>">
<input type="hidden" id ="TeethFollowup" name="child_level_detail[TeethFollowup]">
<input type="hidden" id ="TeethScreening" name="child_level_detail[TeethScreening]">
<input type="hidden" id ="TeethPreventative" name="child_level_detail[TeethPreventative]">
<input type="hidden" id ="TeethFollowup" name="child_level_detail[TeethFollowup]">

<input type="submit" value="Submit" id="submitButton">
<% end %>

Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
get 'statistics/school'
get 'statistics/event'
get 'statistics/schoolStats'
resources :child_details
resources :patient_details, param: :PID

resources :event_details
Expand All @@ -20,7 +19,7 @@
get '/signup', to: 'users#new'
post '/signup', to: 'users#create'
get '/child_data' => 'child_level_details#child_data'
get '/screening' => 'child_details#screening'


get '/auth/:provider/callback', to: 'sessions#omniauth'

Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20231027004131_create_child_level_details.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateChildLevelDetails < ActiveRecord::Migration[7.1]
def change
create_table :child_level_details do |t|
t.string :PID
create_table :child_level_details , id: false do |t|
t.string :PID, primary_key: true, null: false, unique: true
t.string :TeethScreening
t.string :TeethPreventative
t.string :TeethFollowup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveIdFromChildLevelDetails < ActiveRecord::Migration[7.1]
def change
remove_column :child_level_details, :id
end
end
47 changes: 2 additions & 45 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4de917f

Please sign in to comment.