You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助修改Google Apps Script获取NPPES NPI数据库指定/全量信息

修改Google Apps Script以获取完整的NPI医生信息

以下是修改后的脚本,可返回你需要的名、姓、完整地址、许可证代码、电话号码、传真号码,同时保留原有的有效性验证逻辑:

/**
Google AppScript for retrieving detailed provider info from NPI
Returns first name, last name, full address, license number, phone, fax
Validates active US individual (NPI-1) providers
**/

function validateNPI(npi) {
  const nppesUrl = 'https://npiregistry.cms.hhs.gov/api/?number=__NPI__&version=2.1';
  const response = JSON.parse(UrlFetchApp.fetch(nppesUrl.replace('__NPI__', npi)).getContentText());

  // 验证NPI有效性
  if (response.Errors || !(entry = response.results[0])) {
    return "Not a valid active NPI";
  }

  // 验证是否为个人类型NPI
  if (entry.enumeration_type !== 'NPI-1') {
    return "Not an individual, type 1 NPI";
  }

  // 获取美国执业地址
  const locationAddr = entry.addresses.filter(a => a.address_purpose === 'LOCATION')[0];
  if (!locationAddr || locationAddr.country_code !== 'US') {
    return "Not based in US";
  }

  // 提取个人姓名信息
  const firstName = entry.basic.first_name || '';
  const lastName = entry.basic.last_name || '';

  // 构建完整地址
  const fullAddress = [
    locationAddr.address_1 || '',
    locationAddr.address_2 || '',
    locationAddr.city || '',
    locationAddr.state || '',
    locationAddr.postal_code || ''
  ].filter(part => part).join(', ');

  // 提取医疗许可证代码(筛选类型为"MEDLIC"的条目)
  const license = entry.identifiers?.filter(id => id.type === 'MEDLIC')[0]?.identifier || 'No license found';

  // 提取电话和传真
  const phone = locationAddr.telephone_number || '';
  const fax = locationAddr.fax_number || '';

  // 返回二维数组,适配Google Sheets的单元格输出
  return [[firstName, lastName, fullAddress, license, phone, fax]];
}

关键修改说明:

  • 个人姓名:从entry.basic对象中提取first_name和last_name,处理空值避免返回undefined
  • 完整地址:将地址的街道、补充地址、城市、州、邮编拼接成可读字符串,自动过滤空的地址段
  • 许可证代码:从entry.identifiers中筛选类型为MEDLIC(医疗许可证)的条目,若没有则返回提示文本
  • 空值处理:所有字段都添加了空值判断,避免因API返回缺失字段导致脚本报错
  • 输出格式:保持二维数组结构,确保在Google Sheets中调用时能自动填充到对应列

内容的提问来源于stack exchange,提问作者Chi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 21:15:36