How would you make this function work on any table?
In another answer, @SQLRaptor makes the suggestion of using STRING_AGG. Working with that, it seems like the following should do the trick:

SELECT  AdmitDateTime, RoomID, med.stuffMeds
FROM    AbstractData AD
OUTER APPLY (
    SELECT  STRING_AGG(DataItemID, ', ') WITHIN GROUP (ORDER BY DataItemID ASC) stuffMeds
    FROM    EmrAcctPha_Medication med
    WHERE   AD.VisitID = med.VisitID
) med