2

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

10 Rep
  • 2,217
  • 7
  • 19
  • 33
negfrequency
  • 1,801
  • 3
  • 18
  • 30
  • Have you just considered copying the names from the HL7 spec? https://www.hl7.org/fhir/resourcelist.html. (Alphabetical tab is probably easiest) – Lloyd McKenzie Jul 23 '20 at 20:16
  • given the dynamic and evolving nature of the fhir standard, i dont entirely feel comfortable with this approach – negfrequency Jul 23 '20 at 21:06
  • 1
    The set of resources available in a given release is fixed - and new releases only come out ever 2-3 years. If you want to keep up with the CI build, then something programatic would be needed - but the reality is that that list could change at any time, and in theory could change multiple times in a single day. For 'real' use, you'd at minimum need to tie yourself to a connectathon or ballot snapshot, and those only come out 3-4 times per year max. – Lloyd McKenzie Jul 24 '20 at 02:37

0 Answers0