-
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.
- Loading branch information
1 parent
46ec168
commit 5f06584
Showing
6 changed files
with
98 additions
and
88 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,37 @@ | ||
module DocDoc | ||
class HouseVisit | ||
def initialize(horse_and_buggy, patient, starting_location) | ||
@horse_and_buggy = horse_and_buggy | ||
@patient = patient | ||
@starting_location = starting_location | ||
end | ||
|
||
attr_reader :starting_location | ||
|
||
def start | ||
@horse_and_buggy.visit_house(@patient.home) | ||
if @horse_and_buggy.status_code >= 400 | ||
@illness = OpenStruct.new(type: 'http', status: @horse_and_buggy.status_code) | ||
end | ||
rescue Capybara::Poltergeist::StatusFailError | ||
@illness = OpenStruct.new(type: 'http', description: 'Could not reach server') | ||
end | ||
|
||
def illness | ||
@illness ||= begin | ||
if @patient.home && @patient.home.match(/#/) | ||
hyper_fragment = @patient.home.split('#').last | ||
begin | ||
nil if @horse_and_buggy.find("##{hyper_fragment}") | ||
rescue Capybara::Ambiguous | ||
OpenStruct.new(type: 'fragment', description: 'More than one dom node has this id') | ||
rescue Capybara::ElementNotFound | ||
OpenStruct.new(type: 'fragment', description: 'No dom node with this id found') | ||
end | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
end |
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,3 @@ | ||
module DocDoc | ||
Patient = Struct.new(:home) | ||
end |
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,17 @@ | ||
module DocDoc | ||
class Prescription | ||
def initialize(treatments) | ||
@treatments = treatments | ||
end | ||
|
||
def treatments | ||
@treatments | ||
end | ||
|
||
def to_s | ||
{ | ||
links: treatments | ||
}.to_json.to_s | ||
end | ||
end | ||
end |
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,15 @@ | ||
module DocDoc | ||
class Quarantine | ||
def initialize(horse_and_buggy, danger_zone) | ||
@horse_and_buggy = horse_and_buggy | ||
@danger_zone = danger_zone | ||
end | ||
|
||
def patients | ||
@horse_and_buggy.visit(@danger_zone) | ||
@horse_and_buggy.all('a').map do |link| | ||
Patient.new(link['href']) | ||
end.uniq(&:home) | ||
end | ||
end | ||
end |
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,21 @@ | ||
module DocDoc | ||
class Treatment | ||
def initialize(patient, illness, house_visit) | ||
@patient = patient | ||
@illness = illness | ||
@house_visit = house_visit | ||
end | ||
|
||
def as_json | ||
{ | ||
page: @house_visit.starting_location, | ||
href: @patient.home, | ||
error: @illness.to_h | ||
} | ||
end | ||
|
||
def to_json(_) | ||
as_json.to_json | ||
end | ||
end | ||
end |