Directory structure refactoring.
[siap.git] / ws / siacc_wsclient.php
diff --git a/ws/siacc_wsclient.php b/ws/siacc_wsclient.php
new file mode 100644 (file)
index 0000000..46cee23
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+// Pull in the NuSOAP code
+require_once('nusoap/lib/nusoap.php');
+// Create the client instance
+
+function create_soap_client() {
+    $client = new soapclient(
+            'http://siap.ufcspa.edu.br/ws/siap_ws.php?wsdl', true);
+    $err = $client->getError();
+    if ($err) {
+        // Display the error
+        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
+        // At this point, you know the call that follows will fail
+    }
+    return $client;
+} 
+
+function call_soap_method($client, $method, $parameters) {
+    $result = $client->call($method, $parameters);
+    // Check for a fault
+    if ($client->fault) {
+        echo '<h2>Fault</h2><pre>';
+        print_r($result);
+        echo '</pre>';
+        $result = NULL;
+    } else {
+        // Check for errors
+        $err = $client->getError();
+        if ($err) {
+            // Display the error
+            echo '<h2>Error</h2><pre>' . $err . '</pre>';
+            $result = NULL;
+        }              
+    }
+    return $result;
+}
+
+function print_wordlist($wordlist){
+    foreach($wordlist as $word){   
+        echo '<p>'.$word['id'].' => '.$word['nome'].'</p>';
+    }
+}
+
+
+header('Content-type: text/html; charset=ISO-8859-1');
+
+$client = create_soap_client();
+
+$search_types = call_soap_method($client, 'get_search_types', array());
+if ($search_types) {
+    echo '<h2>Tipos de busca para Imagem</h2><pre>';
+    print_wordlist($search_types);
+    echo '</pre>';
+}
+
+foreach ($search_types as &$search_type) {
+    $result = call_soap_method($client, 'get_search_type_keywords', array('search_type' => $search_type['id']));
+    if ($result) {
+        echo '<h2>Palavras-chave para '.$search_type['nome'].':</h2><pre>';
+        print_wordlist($result);
+        echo '</pre>';
+    }  
+}
+
+
+$search_results = call_soap_method($client, 'search', array('search_request' => array(
+                'palavra'=>'abscesso', 'sistema'=>8, 'procedencia'=>15, 'patologia'=>'')));
+
+if ($search_results) {
+    echo '<h2>Resultados da busca para "abscesso" no sistema nervoso:</h2><pre>';
+    echo 'Mostrando ' .sizeof($search_results).' resultados. <br><br>'; 
+    foreach($search_results as &$result){
+        echo 'Nome: '.$result['nome'].'<br>';
+        echo 'Sistema: '.$result['sistema'].'<br>';
+        echo 'Procedencia: '.$result['procedencia'].'<br>';
+        echo 'Patologia: '.$result['patologia'].'<br>';
+        echo 'URL: '.$result['url'].'<br>';
+        echo '<br>';
+
+    }
+    echo '</pre>';
+}
+
+
+// Display the request and response
+echo '<h2>Request</h2>';
+echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
+echo '<h2>Response</h2>';
+echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
+
+?>