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

2024-05-16 10:06:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从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/shinny进行API调用,并将样本FHIR数据放入R session。使用上述包的任何解决方案或使用python/R的替代解决方案都将很有帮助。或者直接在shinn中使用JS SMARTonFHIR客户端是理想的选择。 我尝试直接使用JS SMART/FHIR客户端,而不是依赖RonFhir包。基本上是包装这个Plunker example,但是没有成功。下面是代码。当var todaysDiagnoses发送到shiny时,shiny UI上的输出只是names list NULL。{var}不只是从cdr}返回所有的链接。在

附录r

^{pr2}$

演示-设置.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;
    }
  );
});

得到-数据.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 || []);
                }
            });

Tags: nameclientptreturnsmartvarfunctionmed