import hashlib


def activity_hash(dataset):
    """Return the hash string that uniquely identifies an activity.

    Uses the following fields, in order:
        * name
        * reference product
        * unit
        * location
        * start date
        * end date

    An empty string is used if a field isn't present. All fields are cast to lower case.

    """
    fields = (
        "name",
        "reference product",
        "unit",
        "location",
        "start date",
        "end date",
    )
    string = "".join(dataset.get(field, '').lower() for field in fields)
    return hashlib.md5(string.encode('utf-8')).hexdigest()