82aeb03255f4f45baf5bd9e8c0d06ba57a071f8f tdreszer Fri May 27 14:46:46 2011 -0700 Fixed mistake of not using tags on hgFileUi filterBy boxes. This resulted in UChicago downloads page not showing control terms properly. diff --git src/hg/lib/cv.c src/hg/lib/cv.c index 3187468..46ce023 100644 --- src/hg/lib/cv.c +++ src/hg/lib/cv.c @@ -111,30 +111,40 @@ if (cvHashOfHashOfHashes == NULL) cvHashOfHashOfHashes = hashNew(0); struct hash *cvHashForTerm = hashFindVal(cvHashOfHashOfHashes,term); // Establish cv hash of Term Types if it doesn't already exist if (cvHashForTerm == NULL) { cvHashForTerm = raReadWithFilter(cvFile(), CV_TERM,CV_TYPE,term); if (cvHashForTerm != NULL) hashAdd(cvHashOfHashOfHashes,term,cvHashForTerm); } return cvHashForTerm; } +const struct hash *cvOneTermHash(char *type,char *term) +// returns a hash for a single term of a given type +// NOTE: in static memory: DO NOT FREE +{ +const struct hash *typeHash = cvTermHash(type); +if (typeHash != NULL) + return hashFindVal((struct hash *)typeHash,term); +return NULL; +} + const struct hash *cvTermTypeHash() // returns a hash of hashes of mdb and controlled vocabulary (cv) term types // Those terms should contain label,description,searchable,cvDefined,hidden // NOTE: in static memory: DO NOT FREE { // NOTE: "typeOfTerm" is specialized, so don't use cvTermHash static struct hash *cvHashOfTermTypes = NULL; // Establish cv hash of Term Types if it doesn't already exist if (cvHashOfTermTypes == NULL) { cvHashOfTermTypes = raReadWithFilter(cvFile(), CV_TERM,CV_TYPE,CV_TOT); // Patch up an ugly inconsistency with 'cell' struct hash *cellHash = hashRemove(cvHashOfTermTypes,CV_UGLY_TOT_CELLTYPE); if (cellHash) { @@ -254,30 +264,67 @@ const char *cvLabel(char *term) // returns cv label if term found or else just term { // Get the list of term types from thew cv struct hash *termTypeHash = (struct hash *)cvTermTypeHash(); struct hash *termHash = hashFindVal(termTypeHash,term); if (termHash != NULL) { char *label = hashFindVal(termHash,CV_LABEL); if (label != NULL) return label; } return term; } +const char *cvTag(char *type,char *term) +// returns cv Tag if term found or else NULL +{ +const struct hash *termHash = cvOneTermHash(type,term); +if (termHash != NULL) + return hashFindVal((struct hash *)termHash,CV_TAG); +return NULL; +} + +#ifdef OMIT +// may want this someday +const char *cvTerm(char *tag) +// returns the cv Term if tag found or else NULL +{ +// Get the list of term types from thew cv +struct hash *termTypeHash = (struct hash *)cvTermTypeHash(); +struct hashCookie hcTOT = hashFirst(termTypeHash); +struct hashEl *helType; +while ((helType = hashNext(&hcTOT)) != NULL) // Walk through each type + { + struct hash *typeHash = cvTermHash(helType->name); + struct hashCookie hcType = hashFirst(typeHash); + struct hashEl *helTerm; + while ((helTerm = hashNext(&hcType)) != NULL) // Walk through each term in this type + { + struct hash *termHash = (struct hash *)helTerm->val; + char *foundTag = hashFindVal(termHash,CV_TAG); + if (foundTag != NULL && sameString(tag,foundTag)) + { + return helTerm->name; + } + } + } +return NULL; +} +#endif///def OMIT + boolean cvTermIsHidden(char *term) // returns TRUE if term is defined as hidden in cv.ra { struct hash *termTypeHash = (struct hash *)cvTermTypeHash(); struct hash *termHash = hashFindVal(termTypeHash,term); if (termHash != NULL) { char *setting = hashFindVal(termHash,CV_TOT_HIDDEN); return cvHiddenIsTrue(setting); } return FALSE; } boolean cvTermIsEmpty(char *term,char *val) // returns TRUE if term has validation of "cv or None" and the val is None