Check Taiwan TFDA medical device safety alerts via open data API. Uses the government open data API at data.fda.gov.tw which provides medical device safety alert data in JSON format.
| 1268 | |
| 1269 | |
| 1270 | class TFDAOpenDataChecker: |
| 1271 | """Check Taiwan TFDA medical device safety alerts via open data API. |
| 1272 | |
| 1273 | Uses the government open data API at data.fda.gov.tw which provides |
| 1274 | medical device safety alert data in JSON format. |
| 1275 | """ |
| 1276 | |
| 1277 | def __init__(self, session, state: dict, seed_mode: bool = False): |
| 1278 | self.session = session |
| 1279 | self.state = state |
| 1280 | self.seed_mode = seed_mode |
| 1281 | |
| 1282 | def check(self, source_id: str, source: dict) -> Optional[dict]: |
| 1283 | url = source["url"] |
| 1284 | prev = self.state.get(source_id, {}) |
| 1285 | prev_ids = set(prev.get("seen_ids", [])) |
| 1286 | |
| 1287 | try: |
| 1288 | resp = self.session.get(url, timeout=30, headers={ |
| 1289 | "Accept": "application/json", |
| 1290 | }) |
| 1291 | resp.raise_for_status() |
| 1292 | data = resp.json() |
| 1293 | except Exception as e: |
| 1294 | print(f" ERROR TFDA OpenData: {e}") |
| 1295 | return None |
| 1296 | |
| 1297 | if not isinstance(data, list) or not data: |
| 1298 | print(" WARNING: TFDA OpenData returned empty or non-list response") |
| 1299 | return None |
| 1300 | |
| 1301 | print(f" INFO: Parsed {len(data)} entries from TFDA OpenData API") |
| 1302 | |
| 1303 | new_items = [] |
| 1304 | all_ids = list(prev_ids) |
| 1305 | |
| 1306 | for row in data: |
| 1307 | title = row.get("Title", row.get("title", "")) |
| 1308 | if not title: |
| 1309 | continue |
| 1310 | link = row.get("Link", row.get("link", "")) |
| 1311 | pub_date = row.get("Release date", row.get("PublishDate", "")) |
| 1312 | if pub_date: |
| 1313 | pub_date = pub_date[:10] |
| 1314 | |
| 1315 | eid = link or title |
| 1316 | if eid in prev_ids: |
| 1317 | continue |
| 1318 | all_ids.append(eid) |
| 1319 | |
| 1320 | if not link or not link.startswith("http"): |
| 1321 | link = "https://www.fda.gov.tw/" |
| 1322 | |
| 1323 | new_items.append({ |
| 1324 | "title": title, |
| 1325 | "link": link, |
| 1326 | "pub_date": pub_date, |
| 1327 | "description": f"TFDA medical device safety alert: {title[:200]}", |