func makeCodeHarmonizers()

in wstl1/mapping_engine/harmonization/harmonizecode/harmonize_code.go [165:210]


func makeCodeHarmonizers(lookups *hpb.CodeHarmonizationConfig) (map[string]CodeHarmonizer, error) {
	harmonizers := make(map[string]CodeHarmonizer)

	local := NewLocalCodeHarmonizer()

	for _, l := range lookups.CodeLookup {
		var raw []byte
		var err error
		switch t := l.Location.(type) {
		case *httppb.Location_LocalPath:
			if !strings.HasSuffix(t.LocalPath, ".json") {
				continue
			}
			raw, err = ioutil.ReadFile(t.LocalPath)
			if err != nil {
				return nil, fmt.Errorf("failed to read concept map file with error %v", err)
			}
		case *httppb.Location_GcsLocation:
			raw, err = gcsutil.ReadFromGcs(context.Background(), t.GcsLocation)
			if err != nil {
				return nil, fmt.Errorf("failed to read from GCS, %v", err)
			}
		case *httppb.Location_UrlPath:
			h, err := makeRemoteCodeHarmonizer(t.UrlPath, int(lookups.CacheTtlSeconds), int(lookups.CleanupIntervalSeconds))
			if err != nil {
				return nil, fmt.Errorf("unable to create remote code harmonizer from url %s: %v", t.UrlPath, err)
			}
			harmonizers[l.GetName()] = h
			continue
		default:
			return nil, fmt.Errorf("location type %T is not supported", t)
		}

		// TODO(): Add support for multiple FHIR versions.
		cm, err := unmarshalR3ConceptMap(raw)
		if err != nil {
			return nil, fmt.Errorf("unmarshal failed with error %v", err)
		}
		if err := local.Cache(cm); err != nil {
			return nil, err
		}
	}

	harmonizers[localHarmonizerName] = local
	return harmonizers, nil
}