Skip to content

Commit fa25a88

Browse files
Adding the health APIs to the SDK
1 parent 75b95f9 commit fa25a88

File tree

3 files changed

+116
-11
lines changed

3 files changed

+116
-11
lines changed

src/Service/EventService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getEvents($limit = 10, $groupId = null, $startTimeUts = null)
4242
*/
4343
public function create(Event $event)
4444
{
45-
$payload = [
45+
$payload = array(
4646
'group' => $event->groupId(),
4747
'title' => $event->name(),
4848
'description' => $event->description(),
@@ -51,7 +51,7 @@ public function create(Event $event)
5151
'end' => $event->endTimestamp(),
5252
'coordinates' => $event->coordinates(),
5353
'private' => '0',
54-
];
54+
);
5555

5656
return $this->createResponse($this->postFormData("/events/new", $payload));
5757
}

src/Service/FriendService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function declineFriendRequest($friendUserId)
105105
*/
106106
public function addFriend($message, $potentialFriendId = null, $potentialFriendEmail = null)
107107
{
108-
$payload = ['message' => $message];
108+
$payload = array('message' => $message);
109109
if (!is_null($potentialFriendId) && intval($potentialFriendId) > 0) {
110110
$payload['id'] = $potentialFriendId;
111111
}

src/Service/UserService.php

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class UserService extends TokenRefreshingService
2828
*/
2929
public function registerNewUser($firstName, $lastName, $email, $password, $phoneNumber, $countryCode = null)
3030
{
31-
$payload = [
31+
$payload = array(
3232
'first' => $firstName,
3333
'last' => $lastName,
3434
'email' => $email,
3535
'password' => $password,
3636
'mobile' => $phoneNumber,
3737
'country' => $countryCode,
38-
];
38+
);
3939
if (!empty($countryCode) && strlen($countryCode) === 2) {
4040
$payload['country'] = $countryCode;
4141
}
@@ -56,9 +56,7 @@ public function getUserById($id)
5656
return $this->getSelf();
5757
}
5858

59-
return $this->createResponse(
60-
$this->get(self::BASE . "/{$id}")
61-
);
59+
return $this->createResponse($this->get(self::BASE . "/{$id}"));
6260
}
6361

6462
/**
@@ -82,9 +80,7 @@ public function uploadLogo($absoluteFilePath)
8280
*/
8381
public function getSelf()
8482
{
85-
return $this->createResponse(
86-
$this->get(self::BASE)
87-
);
83+
return $this->createResponse($this->get(self::BASE));
8884
}
8985

9086
/**
@@ -103,4 +99,113 @@ public function getFriends($offset = 0, $limit = self::DEFAULT_PAGINATION_LIMIT)
10399

104100
return $this->createResponse($this->get("/friends?offset={$offset}&limit={$limit}"));
105101
}
102+
103+
/**
104+
* This returns all the available health conditions. In order to get the current user's data,
105+
* Please use the @see getHealthProfile
106+
*
107+
* @return array
108+
*/
109+
public function getAvailableHealthConditions()
110+
{
111+
return $this->createResponse($this->get('/health/available-conditions'));
112+
}
113+
114+
/**
115+
* This returns a list of approved health practices.
116+
*
117+
* @return array
118+
*/
119+
public function getHealthPractitioners()
120+
{
121+
return $this->createResponse($this->get('/health/practitioners'));
122+
}
123+
124+
/**
125+
* Use this to enrol at a health practice.
126+
*
127+
* @param int $practitionerId A valid health practitioner id
128+
*
129+
* @return array
130+
* @see getHealthPractitioners To select a health practitioner
131+
*/
132+
public function enrolAtHealthPractitioner($practitionerId)
133+
{
134+
$practitionerId = intval($practitionerId);
135+
return $this->createResponse($this->postFormData("/health/practitioner/{$practitionerId}/enrol"));
136+
}
137+
138+
/**
139+
* Use this to un-enrol from a health practice that you are currently enrolled at.
140+
*
141+
* @param int $practitionerId A valid health practitioner id
142+
*
143+
* @return array
144+
* @see getHealthPractitioners To select a health practitioner
145+
*/
146+
public function unEnrolFromHealthPractitioner($practitionerId)
147+
{
148+
$practitionerId = intval($practitionerId);
149+
return $this->createResponse($this->postFormData("/health/practitioner/{$practitionerId}/unenrol"));
150+
}
151+
152+
/**
153+
* Returns any health condition verifications done by a practitioner.
154+
*
155+
* @return array
156+
*/
157+
public function getHealthConditionVerifications()
158+
{
159+
return $this->createResponse($this->get('/health/condition-verifications'));
160+
}
161+
162+
/**
163+
* This returns the user's health data. THis data is usually submitted via the HubID health page in the site.
164+
*
165+
* @return array
166+
* @see https://hubculture.com/account/health Link to the HubID health page
167+
*/
168+
public function getHealthProfile()
169+
{
170+
return $this->createResponse($this->get('/health/profile'));
171+
}
172+
173+
/**
174+
* Use this to update the health profile of the current authenticated user.
175+
*
176+
* @param string $bloodType Blood type. Ex: A+
177+
* @param string|null $medications [optional] Any medication that the user is taking.
178+
* @param array $existingHealthConditionIds [optional] Valid health condition ids.
179+
* @param int|null $primaryPractitionerId [optional] Passing a valid practitioner id will enrol you in
180+
* their practice and you will be able to communicate with the
181+
* practitioner. You may also use the enrol method later.
182+
*
183+
* @return array
184+
* @see getHealthPractitioners To select a health practitioner
185+
* @see getAvailableHealthConditions to get the condition ids
186+
* @see enrolAtPractitioner to enrol at a health practice
187+
*/
188+
public function setHealthProfile(
189+
$bloodType,
190+
$medications = null,
191+
array $existingHealthConditionIds = array(),
192+
$primaryPractitionerId = null
193+
) {
194+
$payload = array();
195+
$validBloodType = array('A+', 'A-', 'B+', 'B-', 'O+', 'O-', 'AB+', 'AB-');
196+
if (in_array($bloodType, $validBloodType)) {
197+
$payload['health_blood_type'] = $bloodType;
198+
}
199+
if (!empty($medications)) {
200+
$payload['health_medications'] = $medications;
201+
}
202+
if (!empty($existingHealthConditionIds)) {
203+
$payload['health_conditions'] = implode(',', $existingHealthConditionIds);
204+
}
205+
if (!is_null($primaryPractitionerId) && intval($primaryPractitionerId) > 0) {
206+
$payload['primary_health_practitioner'] = $primaryPractitionerId;
207+
}
208+
209+
return $this->createResponse($this->put('/health/profile', $payload));
210+
}
106211
}

0 commit comments

Comments
 (0)