Alfred John Gregory studied medicine at London Hospital and qualified as a member of the Royal College of Surgeons (MRCS) of England and a licentiate of the Apothecaries Society of London (LSA) in 1886. He continued his studies at the University of Durham, graduating as a Bachelor of Medicine and Bachelor of Surgery in 1888, and as Doctor of Medicine (MD) in 1891. The same year he was awarded the Diploma in Public Health and emigrated to the Cape of Good Hope, settling in Cape Town. At first he did not apply for registration as a medical practitioner, working as a clerk in a commercial firm and, from December 1891, in the census office. There he took charge of the sickness and infirmities section of the Cape census of 1891. He was licensed to practice in the Cape Colony on either 28 June or 28 July 1892 and became an unofficial adviser on health matters to the colonial secretary's office. For example, in 1893 he compiled a report on "The public health of the Cape Colony" for the Leprosy Commission and in November that year inspected all the cemeteries and burial grounds on the Cape Peninsula. On 1 December 1893 he was officially appointed as adviser on health matters to the government. Among others he published 'On the importation of small-pox over sea into South Africa, with remarks on quarantine' (Public Health, 1894) and Report on suburban cemetaries (Cape Town, 1896).
In December 1896, when an assistant was required for the medical officer of health of the Cape Colony, Dr George Turner*, Gregory was appointed without the post being advertised - a controversial procedure that was criticised as being dishonest. He wrote the Report on public health for that year, as Dr Turner was in Kimberley helping to combat the rinderpest. During the next few years he often acted for Turner. In March 1901 he succeeded Turner as medical officer of health and held the position until the Union of South Africa was formed in 1910. He was also medical adviser to the Cape government, and in May 1903 represented the Cape Colony at the International Medical Congress in Madrid. His Report of the conference of the principal medical officers of health for the different British South African colonies... was published in Cape Town in 1906. In October that year he became the head of the newly created Department of Public Health in the Cape Colony. Under his direction the provision of health care in the colony was far in advance of that in Natal and the Boer republics, partly as a result of the comprehensive public health act of 1897.
Gregory was a self-confident man with a forceful personality, served on the Colonial Medical Council from 1900 and played a dominating role in the Cape medical profession. However, he was not popular and his career was marked by controversial episodes. He probably deserves the credit for calling attention to the ravages of tuberculosis among the black and coloured populations of the Cape, a matter he raised repeatedly from about 1895 onwards. In 1911 he failed to secure the position of medical officer of health for the Union and after a brief period in a temporary post he retired that same year. From 1912 to 1914 he served as chairman of the Tuberculosis Commission, issuing its First report... in 1912. The commission's final report was criticised in parliament and in the South African Medical Record, particularly the fact that its proceedings were protracted and too costly and that Gregory as chairman had been overpaid.
Gregory was a member of the Cape of Good Hope Branch of the British Medical Association. He joined the South African Philosophical Society in 1895 and remained a member until at least 1900. He was furthermore a foundation member of the South African Association for the Advancement of Science in 1902 and served on its first council. From July 1903 to 1909 he served on the council of the University of the Cape of Good Hope. He returned to England in May 1914 to live in Bournemouth, but during World War I (1914-1918) served for some time in the South African Military Hospital in Richmond (now part of greater London). He was honoured by being appointed an Officer of the Order of the British Empire (OBE).