I have been using the following code to import all sub-modules in the fhir.resources
package to list the standard resource names that exist for FHIR
, but I realize this is a poor way to do it, and that silly peripheral module names are thrown in (like fhir.resources.fhirreference
) which make this way of doing it objectively wrong. What might be the correct way to list all FHIR Resource names?
import os
import pkgutil
import fhir.resources
def list_resource_types():
path = os.path.dirname(fhir.resources.__file__)
types = [name for _, name, _ in pkgutil.iter_modules([path])]
for i in sorted(i for i in types if i.lower()==i):
print(i)
Thanks! ~Will