Skip to content

Commit

Permalink
yaay
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsalisbury committed Dec 7, 2016
1 parent 97b1c1e commit 91d83f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
36 changes: 35 additions & 1 deletion api/antibiotic.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
<?php
require_once 'database.php';
class Antibiotic {

class Diagnosis
protected $id;
protected $name;
protected $notes;
protected $relatedAntibiotics;

public function __construct($id=0) {
if ($id !== 0) {
$db = getDatabase();
$query = $db->prepare( "SELECT * from antibiotic WHERE id = :id " ); // return all fields (*) from the table WHERE the id is the var $id passed to the function
$query->bindParam( ':id', $id );
$query->execute(); // Run the SQL query on our database
$query->setFetchMode( PDO::FETCH_OBJ ); // A PHP method to tell the database we want to return all the data as objects with each table represented as a property of that object. This will be the case for most of our calls that return information from the database. http://php.net/manual/en/pdo.constants.php
$data = $query->fetchAll();

$data = $data[0];

// Build our local object
$this->id = $data->id;
$this->name = $data->name;
$this->notes = $data->notes;
}
}


public function get () {
$res['id'] = $this->id;
$res['name'] = $this->name;
$res['notes'] = $this->notes;

return $res;
}

}
20 changes: 13 additions & 7 deletions api/diagnosis.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
include 'database.php';
require_once 'database.php';
require_once 'antibiotic.php';
class Diagnosis {

protected $id;
Expand All @@ -26,25 +27,30 @@ public function __construct($id=0) {
}
}

private function buildRelatedAntibiotics () {
private function buildRelatedAntibiotics() {
$db = getDatabase();
$query = $db->prepare( "SELECT * from diagnosis_antibiotic WHERE diagnosis_id = :id " ); // return all fields (*) from the table WHERE the id is the var $id of current diagnosis
$query = $db->prepare( "SELECT antibiotic_id from diagnosis_antibiotic WHERE diagnosis_id = :id " ); // return all fields (*) from the table WHERE the id is the var $id of current diagnosis
$query->bindParam( ':id', $this->id );
$query->execute(); // Run the SQL query on our database
$query->setFetchMode( PDO::FETCH_OBJ );
$data = $query->fetchAll();


$this->relatedAntibiotics = $data;
foreach ($data as $row) {
$anti = new Antibiotic($row->antibiotic_id);
$this->relatedAntibiotics[] = $anti->get();
}
}

public function get () {
public function get() {
$res['id'] = $this->id;
$res['name'] = $this->name;
$res['notes'] = $this->notes;
$res['relatedAntibiotics'] = $this->relatedAntibiotics;

return $res;
}

public function getRelatedAntibiotics() {
return $this->relatedAntibiotics;
}

}

0 comments on commit 91d83f7

Please sign in to comment.