Given a messy, nested JSON file of patient demographics, write a Python script to flatten the data and remove duplicates.
Implement flatten_and_deduplicate(records), where records is a list of JSON objects. Return a list of flattened dictionaries, using dot-separated keys for nested objects and numeric indexes for list elements. Preserve the first occurrence of each duplicate record and retain the original record order. Assume object keys do not contain periods and values are valid JSON primitives or nested objects and arrays.
def flatten_and_deduplicate(records):