tutor / medlineplus
MedlinePlus Web Service Guzzle 客户端
Requires
- php: ^5.6 || ^7.0
- gimler/guzzle-description-loader: ^0.0.4
- guzzlehttp/guzzle: ^6.2
- guzzlehttp/guzzle-services: ^1.1
This package is not auto-updated.
Last update: 2024-09-20 02:54:10 UTC
README
提供Guzzle库查询MedlinePlus Web Service的实现。
MedlinePlus提供基于搜索的Web服务,可以访问以XML格式提供的MedlinePlus健康主题数据。使用此Web服务,软件开发者可以构建利用MedlinePlus健康主题信息的应用程序。该服务接受关键字搜索请求,并按顺序返回相关健康主题(英文或西班牙文)。关键字搜索可以限制到特定字段。服务还返回健康主题摘要、搜索结果片段、外部链接和其他相关数据。
用法
要使用MedlinePlus API客户端,只需实例化客户端。
<?php require dirname(__FILE__).'/../vendor/autoload.php'; use Tutor\MedlinePlus\MedlinePlusClient; $client = MedlinePlusClient::factory(); // if you want to see what is happening, add debug => true to the factory call $client = MedlinePlusClient::factory(['debug' => true]);
使用__call方法调用命令(包含自动完成phpDocs)
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'term' => '"diabetes medicines" OR "diabetes drugs"', ]);
或者使用getCommand方法(在这种情况下,您需要处理$response['data']数组)
<?php $client = MedlinePlusClient::factory(); //Retrieve the Command from Guzzle $command = $client->getCommand('Query', [ 'term' => '"diabetes medicines" OR "diabetes drugs"', ]); $command->prepare(); $response = $command->execute(); $data = $response['data'];
示例
您可以在示例目录中执行示例。
您可以通过services.json了解可用的方法和调用它们的参数。
https://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term=asthma
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'term' => 'asthma', ]);
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'term' => '"diabetes medicines" OR "diabetes drugs"', ]);
https://wsearch.nlm.nih.gov/ws/query?db=healthTopicsSpanish&term=asma
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'db' => 'healthTopicsSpanish', 'term' => 'asma', ]);
字段搜索
搜索词的文本可以包含限制符,以将搜索限制在特定的健康主题字段。语法是:。可以通过这种方式搜索的字段有
- 标题
- 副标题
- mesh(仅适用于英文搜索)
- 全文摘要
- 组
https://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term=title:asthma
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'term' => 'title:asthma', ]);
后续请求
https://wsearch.nlm.nih.gov/ws/query?file=viv_0Uu9LP&server=qvlbsrch04&retstart=20
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'file' => 'viv_0Uu9LP', 'server' => 'qvlbsrch04', 'retstart' => 20, ]);
可选参数
https://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term=diabetes&retmax=50
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'term' => 'diabetes', 'retmax' => 50, ]);
https://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term=asthma&rettype=all
<?php $client = MedlinePlusClient::factory(); $response = $client->query([ 'term' => 'asthma', 'rettype' => 'all', ]);
TODO
- 添加更多示例
- 添加测试
- 添加一些响应模型
欢迎贡献
发现错误,请提交问题,最好是带有调试输出和您所做的事情。修复错误?请提交拉取请求,我将查看。
许可
MedlinePlus\MedlinePlusClient API客户端的使用可在MIT许可证下获得。