Get Specific Class of Concepts using Rest API

Hello,

I am trying to get a specific class of concepts (For example Diagnosis class). But I am getting wrong result. My URL Looks:

/openmrs/ws/rest/v1/concept?class=8d4918b0-c2cc-11de-8d13-0010c6dffd0f

Diagnosis Class UUID is: 8d4918b0-c2cc-11de-8d13-0010c6dffd0f

Thanks in advance.

Are you able to reproduce the problem on qa-refapp.openmrs.org?

Hi Dainel, I have tried it here: https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/concept?class=8d4918b0-c2cc-11de-8d13-0010c6dffd0f

It returns wrong result:

{
    "results": [
        {
            "uuid": "18316c68-b5f9-4986-b76d-9975cd0ebe31",
            "display": "True",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/18316c68-b5f9-4986-b76d-9975cd0ebe31"
                }
            ]
        },
        {
            "uuid": "141216AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Enterobiasis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/141216AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "71617AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Aspirin",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/71617AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "0d8a135b-0acf-47f3-a51c-77aefe7787db",
            "display": "False",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/0d8a135b-0acf-47f3-a51c-77aefe7787db"
                }
            ]
        },
        {
            "uuid": "115914AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Mastitis-Postpartum",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/115914AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "116135AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Major Puerperal Infection, Postpartum",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/116135AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "MALARIA",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "73667AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Codeine",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/73667AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "72609AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Caffeine",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/72609AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "104811AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "HEPARINOIDS / HYALURONIDASE",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/104811AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "104813AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "HEPARINOIDS / SALICYLIC ACID",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/104813AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "143388AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Convulsions in the newborn",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/143388AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "149579AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Acute Pharyngitis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/149579AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "80106AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Morphine",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/80106AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "111633AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Urinary tract infection",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/111633AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "48AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Pregnancy, miscarriage",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/48AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "111636AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Urinary incontinence",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/111636AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "119685AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Cystitis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/119685AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5018AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Diarrhea, chronic",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5018AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "148787AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Angioedema",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/148787AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "460AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Oedema",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/460AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "119656AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Decubitus Ulcer",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/119656AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "112287AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Trachoma",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/112287AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "132636AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Nutritional Marasmus",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/132636AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "110834AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Gastritis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/110834AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "108AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Bronchospasm",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/108AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "111AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Dyspepsia",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/111AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "130AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Puerperal sepsis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/130AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "121AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Myalgia",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/121AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Systolic blood pressure",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5086AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Diastolic blood pressure",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5086AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "123123AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Viral conjunctivitis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/123123AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5087AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Pulse",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5087AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "138706AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Herpes Simplex",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/138706AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "119481AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Diabetes Mellitus",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/119481AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Temperature (C)",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "124AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "AMOEBIASIS",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/124AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Weight (kg)",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Height (cm)",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "119558AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Dental caries",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/119558AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "112198AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Trichiasis of eyelid",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/112198AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "140501AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Fatigue",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/140501AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "113881AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Post-traumatic stress disorder",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/113881AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "148888AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Anaphylaxis",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/148888AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "5092AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Blood oxygen saturation",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/5092AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "139277AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Granuloma inguinale",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/139277AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "122604AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Cholera due to Vibrio Cholerae",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/122604AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "140AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Scabies",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/140AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "119537AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Depression",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/119537AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        },
        {
            "uuid": "119523AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            "display": "Other Specified Dermatomycoses",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/119523AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                }
            ]
        }
    ],
    "links": [
        {
            "rel": "next",
            "uri": "http://127.0.0.1:8081/openmrs/ws/rest/v1/concept?class=8d4918b0-c2cc-11de-8d13-0010c6dffd0f&startIndex=50"
        }
    ]
}

Can you give just one example that is wrong in the returned results? And then explain why it is wrong?

Hi Dainel, I would like to get Diagnosis class concepts.

Diagnosis Class UUID is: 8d4918b0-c2cc-11de-8d13-0010c6dffd0f

But there is Drug Class concept in the result: { “uuid”: “71617AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”, “display”: “Aspirin”, “links”: [ { “rel”: “self”, “uri”: “http://127.0.0.1:8081/openmrs/ws/rest/v1/concept/71617AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA” } ] }

Only the fuzzy search supports searching by class, so you need to add the searchType request parameter with its value set to fuzzy

1 Like

Hi Wyclif, Did you mean like this: https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/concept?class=8d4918b0-c2cc-11de-8d13-0010c6dffd0f&searchType =fuzzy

Its returning the same result.

Are you sure that the results you’re getting back don’t have that concept class actually? You might want to confirm with the database

I did check. This is a concept class uuid. It’s same everywhere.

@jaks80 the REST API does not (currently) support getting all concepts of a given class. If you’d like to add support for this, you could create a ticket, and ideally provide a pull request.

As Wyclif says, you can do a fuzzy search that limits to a particular class, but you have to provide three query parameters:

  • searchType=fuzzy
  • class=uuid
  • name=pne (e.g. if you’re searching for pneumonia)

This is the Java code that gets invoked:

Thanks @darius, That will server my purpose.

Hi @darius, I have tried this.

When I do “searchType=fuzzy&class=diagnosis_class_uuid&name=pne” it returns pneumonia results, but when I do: “searchType=fuzzy&class=diagnosis_class_uuid&name=ibup” it returns Ibuprofens which is drug class concepts. Should it not restrict drug class concepts here since diagnosis_class_uuid is in the class parameter.

Are you sure that you passed an existing uuid for diagnosis_class_uuid? If yes, are you able to reproduce it at demo.openmrs.org?

It seems like demo.openmrs.org server doesn’t have much concept in database.

But definately in https://qa-refapp.openmrs.org server I can reproduce this issue.

Can you share the exact url and uuid values you use to reproduce it on qa-refapp?

Hi @dkayiwa,

This is working fine as @darius mentioned above

searchType=fuzzy class=uuid name=pne

concept?class=8d4918b0-c2cc-11de-8d13-0010c6dffd0f&searchType=fuzzy&name=pne

But this is not filtering properly:

concept?class=8d4918b0-c2cc-11de-8d13-0010c6dffd0f&searchType=fuzzy&q=pne

I think its my lack of understanding between “q” and “name” parameter. May be fuzzy search suppose to work only with “name”.

q is a generic request parameter used for searches across all resources, on the other hand name is specific to the concept search. So yes, they are treated differently.

1 Like

Thank you for the clarificatoin @wyclif