2017年9月27日水曜日

疾患予測WebAPI

疾患予測サーバが提供するWebAPIはHL7 FHIRのRiskAssessmentリソースを用いてリクエスト及びレスポンスを送る。

リクエスト

クライアントが疾患予測サーバに分類対象となるテキストを送る。以下は,リクエストを送るjavascriptプログラムの一部分。
  1. // ここで HL7 FHIR の RiskAssessment リソースで予測システム(api-predict)へリクエストを送る
  2. var riskAssessment = {
  3. "resourceType": "RiskAssessment",
  4. "status": "final",
  5. "basis": [
  6. {
  7. "reference": text
  8. }
  9. ],
  10. "comment": "Naive Bayes Classifier Ver.1.0"
  11. };
  12. $.ajax({
  13. url: 'http://192.168.11.251/~nlp_ai/api-predict.php',
  14. type: 'POST',
  15. headers: {
  16. 'Content-Type': 'application/json;charset=utf-8'
  17. },
  18. async: false,
  19. data: JSON.stringify(riskAssessment),
  20. processData: true,
  21. dataType: 'json'
  22. })
  23. .done(function(data, textStatus, jqXHR) {
  24. ・・・以下,疾患予測サーバからのレスポンスを処理する・・・

以下は,上記プログラムでサーバー側に送られたJSON形式のリクエストメッセージ。
  1. {
  2. "resourceType":"RiskAssessment",
  3. "status":"final",
  4. "basis":[
  5. {
  6. "reference":"ここに疾患分類対象のテキストを設定する。・・・"
  7. }
  8. ],
  9. "comment":"Naive Bayes Classifier Ver.1.0"
  10. }

本来,RiskAssessment.basis.referenceにはリスク評価に用いる情報(FamilyHistory, Observations, Procedures, Conditions, etc.)への参照(Reference)を記述することになっているが,ここでは,直接分類対象のテキストを設定した。

レスポンス

これに対するレスポンスは,複数のRiskAssessmentリソースをBundleリソースで束ねたものとした。
以下は,疾患予測サーバーが返すレスポンスメッセージ。
  1. {
  2. "status":"final",
  3. "resourceType":"RiskAssessment",
  4. "basis[0][reference]":"不妊症。",
  5. "comment":"Naive Bayes Classifier Ver.1.0",
  6. "bundle":{
  7. "resourceType":"Bundle",
  8. "type":"message",
  9. "entry":[
  10. {
  11. "resourceType":"RiskAssessment",
  12. "status":"final",
  13. "prediction":[
  14. {
  15. "outcome":{"text":"naimaku"},
  16. "probability":1.4142274696827
  17. }
  18. ]
  19. },{
  20. "resourceType":"RiskAssessment",
  21. "status":"final",
  22. "prediction":[
  23. {
  24. "outcome":{"text":"kinsyu"},
  25. "probability":1.398112511866
  26. }
  27. ]
  28. },{
  29. "resourceType":"RiskAssessment",
  30. "status":"final",
  31. "prediction":[
  32. {
  33. "outcome":{"text":"taigan"},
  34. "probability":0.48504086418881
  35. }
  36. ]
  37. },{
  38. "resourceType":"RiskAssessment",
  39. "status":"final",
  40. "prediction":[
  41. {
  42. "outcome":{"text":"ransou"},
  43. "probability":-0.20820912181313
  44. }
  45. ]
  46. },{
  47. "resourceType":"RiskAssessment",
  48. "status":"final",
  49. "prediction":[
  50. {
  51. "outcome":{"text":"keigan"},
  52. "probability":-0.21748840888999
  53. }
  54. ]
  55. }
  56. ]
  57. }
  58. }
Bundle.entry配列に疾患ごとのRiskAssessmentリソースで分類結果が返ってくる。疾患名は,RiskAssessment.prediction[0].outcome.textに,スコアはRiskAssessment.prediction[0].probabilityに設定されている。
下記は,上記のレスポンスを画面編集するクライアント側のプログラムの一部である。
  1. .done(function(data, textStatus, jqXHR) {
  2. var html = '<table class="table table-hover table-striped">';
  3. html += '<caption>予測結果(あくまでも予測です。気になる場合は病院に受診してください。)</caption>';
  4. html += '<tr>';
  5. html += '<th>#</th>';
  6. html += '<th>疾患</th>';
  7. html += '<th>判定スコア</th>';
  8. html += '</tr>';
  9. var i = 1;
  10. $.each(data.bundle.entry, function(index, riskAssessment){
  11. html += '<tr>';
  12. html += '<td>' + (i++) + '</td>';
  13. html += '<td>';
  14. html += DISEASE_NAME[riskAssessment.prediction[0].outcome.text];
  15. html += '</td>';
  16. html += '<td>';
  17. html += riskAssessment.prediction[0].probability;
  18. html += '</td>';
  19. html += '</tr>';
  20. });
  21. html += '</table>';
  22. $("#predict-result-list").html(html);
  23. })

0 件のコメント:

コメントを投稿