File size: 1,263 Bytes
907b200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace App\Services;

use Illuminate\Support\Facades\Http;

class ScreeningService
{
    protected string $baseUrl;

    public function __construct()
    {
        $this->baseUrl = rtrim((string) config('services.drug_repurposing.url'), '/');
    }

    private function client()
    {
        $client = Http::timeout(300);

        $token = config('services.drug_repurposing.token');
        if ($token) {
            $client = $client->withToken($token);
        }

        return $client;
    }

    /**
     * POST /api/v1/disease-targets
     */
    public function getTargets(array $input): array
    {
        $payload = [
            'disease_name' => $input['disease_name'],
            'top_n'        => (int) ($input['top_n'] ?? 10),
        ];

        $response = $this->client()->post(
            $this->baseUrl . '/api/v1/disease-targets',
            $payload
        );

        $response->throw();

        return $response->json();
    }

    /**
     * POST /api/v1/screen
     */
    public function screen(array $payload): array
    {
        $response = $this->client()->post(
            $this->baseUrl . '/api/v1/screen',
            $payload
        );

        $response->throw();

        return $response->json();
    }
}