Commit | Line | Data |
---|---|---|
1c21f490 MS |
1 | <?php |
2 | // Pull in the NuSOAP code | |
3 | require_once('nusoap/lib/nusoap.php'); | |
4 | // Create the client instance | |
5 | ||
6 | function create_soap_client() { | |
7 | $client = new soapclient( | |
8 | 'http://siap.ufcspa.edu.br/ws/siap_ws.php?wsdl', true); | |
9 | $err = $client->getError(); | |
10 | if ($err) { | |
11 | // Display the error | |
12 | echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; | |
13 | // At this point, you know the call that follows will fail | |
14 | } | |
15 | return $client; | |
16 | } | |
17 | ||
18 | function call_soap_method($client, $method, $parameters) { | |
19 | $result = $client->call($method, $parameters); | |
20 | // Check for a fault | |
21 | if ($client->fault) { | |
22 | echo '<h2>Fault</h2><pre>'; | |
23 | print_r($result); | |
24 | echo '</pre>'; | |
25 | $result = NULL; | |
26 | } else { | |
27 | // Check for errors | |
28 | $err = $client->getError(); | |
29 | if ($err) { | |
30 | // Display the error | |
31 | echo '<h2>Error</h2><pre>' . $err . '</pre>'; | |
32 | $result = NULL; | |
33 | } | |
34 | } | |
35 | return $result; | |
36 | } | |
37 | ||
38 | function print_wordlist($wordlist){ | |
39 | foreach($wordlist as $word){ | |
40 | echo '<p>'.$word['id'].' => '.$word['nome'].'</p>'; | |
41 | } | |
42 | } | |
43 | ||
44 | ||
45 | header('Content-type: text/html; charset=ISO-8859-1'); | |
46 | ||
47 | $client = create_soap_client(); | |
48 | ||
29f1ed3c | 49 | // Obtem os tipos de busca existentes (procedencia, sistema, patologia...) |
1c21f490 MS |
50 | $search_types = call_soap_method($client, 'get_search_types', array()); |
51 | if ($search_types) { | |
52 | echo '<h2>Tipos de busca para Imagem</h2><pre>'; | |
53 | print_wordlist($search_types); | |
54 | echo '</pre>'; | |
55 | } | |
56 | ||
29f1ed3c MS |
57 | // Obtem as palavras chaves para cada um dos tipos de busca. |
58 | foreach ($search_types as $search_type) { | |
1c21f490 MS |
59 | $result = call_soap_method($client, 'get_search_type_keywords', array('search_type' => $search_type['id'])); |
60 | if ($result) { | |
61 | echo '<h2>Palavras-chave para '.$search_type['nome'].':</h2><pre>'; | |
62 | print_wordlist($result); | |
63 | echo '</pre>'; | |
64 | } | |
65 | } | |
66 | ||
29f1ed3c MS |
67 | // Realiza uma busca por palavra chave. |
68 | // Obs: sistema, procedencia e patologia DEVEM SER PASSADOS POR ID (string vazia quando nao estiver selecionado) | |
1c21f490 MS |
69 | $search_results = call_soap_method($client, 'search', array('search_request' => array( |
70 | 'palavra'=>'abscesso', 'sistema'=>8, 'procedencia'=>15, 'patologia'=>''))); | |
71 | ||
72 | if ($search_results) { | |
73 | echo '<h2>Resultados da busca para "abscesso" no sistema nervoso:</h2><pre>'; | |
74 | echo 'Mostrando ' .sizeof($search_results).' resultados. <br><br>'; | |
75 | foreach($search_results as &$result){ | |
76 | echo 'Nome: '.$result['nome'].'<br>'; | |
77 | echo 'Sistema: '.$result['sistema'].'<br>'; | |
78 | echo 'Procedencia: '.$result['procedencia'].'<br>'; | |
79 | echo 'Patologia: '.$result['patologia'].'<br>'; | |
80 | echo 'URL: '.$result['url'].'<br>'; | |
81 | echo '<br>'; | |
82 | ||
83 | } | |
84 | echo '</pre>'; | |
85 | } | |
86 | ||
87 | ||
88 | // Display the request and response | |
89 | echo '<h2>Request</h2>'; | |
90 | echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; | |
91 | echo '<h2>Response</h2>'; | |
92 | echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; | |
93 | ||
94 | ?> |