getSafetyData static method

Future<Map<String, dynamic>> getSafetyData(
  1. String chemical, {
  2. bool useCached = true,
})

Retrieves safety data for a chemical compound by name or identifier.

Parameters:

  • chemical: The name, CAS number, or other identifier for the chemical
  • useCached: Whether to use cached data if available (default: true)

Returns a map containing safety information including:

  • GHS classifications
  • Hazard statements (H-codes)
  • Precautionary statements (P-codes)
  • Signal word (Danger/Warning)
  • Pictograms

Implementation

static Future<Map<String, dynamic>> getSafetyData(String chemical, {bool useCached = true}) async {
  // Check cache first if enabled
  if (useCached && _cache.containsKey(chemical)) {
    return Map.from(_cache[chemical]!);
  }

  try {
    // Step 1: Search for the compound to get its CID
    final cid = await _getCompoundCID(chemical);
    if (cid == null) {
      return {'error': 'Compound not found'};
    }

    // Step 2: Get safety data using the CID
    final safetyData = await _fetchSafetyData(cid);

    // Cache the result
    _cache[chemical] = Map.from(safetyData);

    return safetyData;
  } catch (e) {
    return {'error': 'Failed to retrieve safety data: $e'};
  }
}