从R / Shiny进行批量FHIR API调用

时间:2019-04-27 02:22:43

标签: python r api shiny hl7-fhir

我正在尝试从R进行批量FHIR API调用。我遇到了R包[RonFHIR][1]。但是,我对endpoint needs authorization感到困惑,不了解如何传递授权请求或所需的授权参数是什么。 github page上有一个示例,但无法正常运行。

或者,有SMARTonFHIR框架,它也有一个开放的服务器,但是我仍然得到同样的东西。

library(RonFHIR)
client <- fhirClient$new("https://r3.smarthealthit.org")
Warning: The endpoint requires authorization.

我正在尝试从R / Shiny进行API调用,并将示例FHIR数据导入R会话。使用上述软件包的任何解决方案或使用python / R的替代解决方案都将有所帮助。或者直接在光泽中使用JS SMARTonFHIR客户端的可能性将是理想的。  我试图直接使用JS SMART / FHIR客户端,而不是依赖于RonFhir软件包。基本上将这个Plunker example包装起来,但是没有成功。下面是代码。当var names list NULL发送到Shiny时,Shiny UI上的输出仅为todaysDiagnoses。如果var smart从JS返回到R,它将仅返回所有链接,而不返回患者信息。

app.r

library(shiny)
library(shinyjs)

if (interactive()) {
  # testing url
  options(shiny.port = 8100)
  APP_URL <- "http://localhost:8100/"
} else {
  # deployed URL
  APP_URL <- "https://servername/path-to-app"
}

ui <- fluidPage(
  tags$head(
    tags$script(src = "https://code.jquery.com/jquery-2.0.3.min.js")
  ),
  tags$script(src = "https://cdn.rawgit.com/smart-on-fhir/client-js/v0.1.8/dist/fhir-client.js"),
  includeScript(path = "get-data.js"),
  includeScript(path = "demo-settings.js"),
  bootstrapPage(
    # include the js code
    # includeScript("demo-settings.js"),
    # a div named mydiv
    tags$div(
      id = "mydiv",
      style = "width: 50px; height :50px; left: 100px; top: 100px;
                 background-color: gray; position: absolute"
    ),

    # an element for unformatted text
    verbatimTextOutput("results")
  )
)


server <- function(input, output) {
  output$results = renderPrint({
    print(input$mydata)
  })

}
shinyApp(ui = ui, server)


#demo-settings.js$(document).ready(function() {
document.getElementById("mydiv").onclick = function() {
  var smart = FHIR.client({
    serviceUrl:'https://r2.smarthealthit.org',
    patientId:'smart-1137192'
  })

  var todaysDiagnoses = smart.api.search({
    type:'Condition',
    query:{
      dateRecorded:'2014-05-01'
    }
  })
  Shiny.onInputChange("mydata", todaysDiagnoses)
}

Shiny.addCustomMessageHandler("myCallbackHandler", function(color) {
  document.getElementById("mydiv").style.backgroundColor = color
    })
})

demo-settings.js

$(document).ready(function() {

  document.getElementById("mydiv").onclick = function() {
    //var number = Math.random();

var smart = FHIR.client({
  serviceUrl: 'https://r2.smarthealthit.org',
  patientId: 'smart-1137192'
});

  var todaysDiagnoses = smart.api.search({
  type: 'Condition',
  query: {dateRecorded: '2014-05-01'}
  });

    Shiny.onInputChange("mydata", todaysDiagnoses);
  };

  Shiny.addCustomMessageHandler("myCallbackHandler",
    function(color) {
      document.getElementById("mydiv").style.backgroundColor = color;
    }
  );
});

get-data.js

    function getPatientName(pt) {
    if (pt.name) {
        var names = pt.name.map(function(name) {
            return name.given.join(" ") + " " + name.family.join(" ");
        });
        return names.join(" / ")
    } else {
        return "anonymous";
    }
}

function getMedicationName(medCodings) {
    var coding = medCodings.find(function(c) {
        return c.system == "http://www.nlm.nih.gov/research/umls/rxnorm";
    });

    return coding && coding.display || "Unnamed Medication(TM)"
}

function displayPatient(pt) {
    document.getElementById('patient_name').innerHTML = getPatientName(pt);
}

var med_list = document.getElementById('med_list');

function displayMedication(medCodings) {
    med_list.innerHTML += "<li> " + getMedicationName(medCodings) + "</li>";
}

// Create a FHIR client (server URL, patient id in `demo`)
var smart = FHIR.client(demo),
    pt = smart.patient;

// Create a patient banner by fetching + rendering demographics
smart.patient.read().then(function(pt) {
    displayPatient(pt);
});

// A more advanced query: search for active Prescriptions, including med details
smart.patient.api.fetchAllWithReferences({
        type: "MedicationOrder"
    }, ["MedicationOrder.medicationReference"]).then(function(results, refs) {
            results.forEach(function(prescription) {
                if (prescription.medicationCodeableConcept) {
                    displayMedication(prescription.medicationCodeableConcept.coding);
                } else if (prescription.medicationReference) {
                    var med = refs(prescription, prescription.medicationReference);
                    displayMedication(med && med.code.coding || []);
                }
            });

0 个答案:

没有答案