def extract_relation(res,resource_type):
    """
    this function takes a unique resource and create the entries for relation.csv
    Logic:
    Profile:
        Bound (Req) = element.binding[strength = required].valueset
        Bound (Ext) = element.binding[strength = extensible].valueset
        Bound (Pref) = element.binding[strength = preferred].valueset
        Bound (Exam) = element.binding[strength = example].valueset
        Extension = element.type[code = extension].profile

    ValueSet:
        valuesFrom = compose.include.system
        valuesFrom = expansion.contains.system
        includes = compose.include.valueSet
    """
    dict_relat=[]
    relation_type_data={"required":"Bound_Req","extensible":"Bound_Ext","preferred":"Bound_Pref","example":"Bound_Exam"}
   # if res.get("id")=="be-ext-laterality":
   #     print(resource_type,res.get("id"))
    if resource_type in ["Profile","Data type"]:
        elements=res.get('snapshot', {}).get('element',[] )
        for element in  elements:
            binding=element.get("binding",{}).get("strength") 
            value=element.get("binding",{}).get("valueSet")
            if binding:
              #  print(value)
                stripped = value.split("|", 1)[0] #remove pipes
             #   if res.get("id")=="be-allergyintolerance":
            #      print(stripped)
                #print(resource_type,"binding -> ",binding,value)
                dict_relat.append({"source":res.get("id"),"target_url":stripped,"relation":relation_type_data[binding]})
            for l in element.get("type",[]):
                if l.get("code",{})=="Extension":
                    #pass
                    if l.get("profile"):
                        dict_relat.append({"source":res.get("id"),"target_url":l.get("profile")[0],"relation":"extension"})
                for target_profile in l.get("targetProfile",[]):
                    dict_relat.append({"source":res.get("id"),"target_url":target_profile,"relation":"references"})

                 #   print()

        elements=res.get('differential', {}).get('element', [])

        for element in  elements:
            binding=element.get("binding",{}).get("strength") 
            value=element.get("binding",{}).get("valueSet")
            if binding:
               # print(res.get("id"),value)
              #  print(value,res.get("id"))
                stripped = value.split("|", 1)[0] #remove pipes

                #print(resource_type,"binding -> ",binding,value)
                dict_relat.append({"source":res.get("id"),"target_url":stripped,"relation":relation_type_data[binding]})
            for l in element.get("type",[]):
                if l.get("code",{})=="Extension":
                    #pass
                    if l.get("profile"):
                    #    print(l.get("profile")[0],res.get("id"))
                        dict_relat.append({"source":res.get("id"),"target_url":l.get("profile")[0],"relation":"extension"})
                for target_profile in l.get("targetProfile",[]):
                    dict_relat.append({"source":res.get("id"),"target_url":target_profile,"relation":"references"})

                 #   print()
    elif resource_type=="ValueSet":
        for s in res.get("compose",{}).get("include",[]):
            #print(s)
            if s.get("system"):
                dict_relat.append({"source":res.get("id"),"target_url":s.get("system"),"relation":"valuesFrom"})
            if s.get("valueSet"):
              #  print(s.get("valueSet"))
                dict_relat.append({"source":res.get("id"),"target_url":s.get("valueSet")[0],"relation":"includes"})

        #print(res.get("expansion",{}).get("contains",[]))

    return dict_relat