GSoD 2020 - OpenMRS REST API Documentation

thanks @saurabh

2 Likes

@ayesh @gcliff

I tried creating a provider with the following payload

{
  "person": "070f0120-0283-4858-885d-a20d967729cf",
  "identifier": "doctor",
  "attributes": [
    {
      "attributeType": "2db18262-85ff-416f-8a84-da8767a1ab77",
      "value": "dummy value"
    }
  ],
  "retired": false
}

here the attribute type I had to create before making the provider post request and I created the providerAttributeType using the following payload which generated the UUID I have used above

{
  "name": "Provider Location",
  "description": "This attribute type will record the loication of the provider",
  "datatypeClassname": "org.openmrs.customdatatype.datatype.LongFreeTextDatatype",
  "minOccurs": 0,
  "maxOccurs": 1,
  "datatypeConfig": "default",
  "preferredHandlerClassname":   "org.openmrs.web.attribute.handler.LongFreeTextTextareaHandler",
  "handlerConfig": null
}

but while making a request to create a provider this error occurs . giving some error due to the value of the attribute passed?

Use an attribute type of type FreeTextDatatype

1 Like

ok @dkayiwa I am trying with FreeTextDatatype

@dkayiwa what would be the handler config in this case since the LongFreeTextDatatype dint expect any handler? It throws invalid handler config error at present.

{
    "error": {
        "message": "Invalid Submission",
        "code": "webservices.rest.error.invalid.submission",
        "globalErrors": [],
        "fieldErrors": {
            "handlerConfig": [
                {
                    "code": "AttributeType.handlerConfig.invalid",
                    "message": "Invalid configuration: {0}"
                }
            ]
        }
    }
}
``

I remember having discussed this with you in a few posts above on this exact same thread.

1 Like

@dkayiwa I remember this it was here before posting this I tried that but the error I got was different so I posted again

Reproduce it on this server https://qa-refapp.openmrs.org/ and share the POST data.

1 Like

@dkayiwa this is the request and post data

https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/providerattributetype
{
  "name": "Provider Location",
  "description": "This attribute type will record the location of the provider",
  "datatypeClassname": "org.openmrs.customdatatype.datatype.FreeTextDatatype",
  "minOccurs": 0,
  "maxOccurs": 1,
  "datatypeConfig": "default",
  "preferredHandlerClassname":   "org.openmrs.web.attribute.handler.FreeTextTextareaHandler",
  "handlerConfig": null
}

this was the error returned

{

    "error": {

        "message": "Invalid Submission",

        "code": "webservices.rest.error.invalid.submission",

        "globalErrors": [],

        "fieldErrors": {

            "handlerConfig": [

                {

                    "code": "AttributeType.handlerConfig.invalid",

                    "message": "Invalid configuration: {0}"

                }

            ]

        }

    }

}

Do not pass a null handlerConfig. Just leave it out if you do no have a value for it.

1 Like

sure trying again @dkayiwa :+1:

@dkayiwa with this POST body

{
  "name": "Provider Location",
  "description": "This attribute type will record the location of the provider",
  "datatypeClassname": "org.openmrs.customdatatype.datatype.FreeTextDatatype",
  "minOccurs": 0,
  "maxOccurs": 1,
  "datatypeConfig": "default",
  "preferredHandlerClassname":   "org.openmrs.web.attribute.handler.FreeTextTextareaHandler"
}

I got this error with the qa-refapp server

{
    "error": {
        "message": "Invalid Submission",
        "code": "webservices.rest.error.invalid.submission",
        "globalErrors": [],
        "fieldErrors": {
            "handlerConfig": [
                {
                    "code": "AttributeType.handlerConfig.invalid",
                    "message": "Invalid configuration: {0}"
                }
            ]
        }
    }
}

Can you share the full server side stack trace via pastebin.com?

1 Like

@dkayiwa I did not get a lot of error logs with this request as usually I get when requests dont work. This is the pastebin here. and screenshot of my request I tried in javascript

Before even thinking of the REST call, are you first of all able to save those exact values via the user interface? https://qa-refapp.openmrs.org/openmrs/admin/provider/providerAttributeType.form

1 Like

No @dkayiwa I havent tried with the UI. I will try doing with it!

@dkayiwa preferredHandlerClassname has no value as I have passed, is it the error?

I was able to create this with default value in preferredHandlerClassname

{
            "uuid": "cff22d83-27e6-4195-8398-229853c1283f",
            "display": "Provider Location",
            "name": "Provider Location",
            "description": "This attribute type will record the location of the provider",
            "minOccurs": 0,
            "maxOccurs": 1,
            "datatypeClassname": "org.openmrs.customdatatype.datatype.FreeTextDatatype",
            "datatypeConfig": "default",
            "preferredHandlerClassname": null,
            "handlerConfig": null,
            "retired": false,
            "auditInfo": {
                "creator": {
                    "uuid": "45ce6c2e-dd5a-11e6-9d9c-0242ac150002",
                    "display": "admin",
                    "links": [
                        {
                            "rel": "self",
                            "uri": "http://qa-refapp.openmrs.org/openmrs/ws/rest/v1/user/45ce6c2e-dd5a-11e6-9d9c-0242ac150002"
                        }
                    ]
                },
                "dateCreated": "2020-11-08T17:45:36.000+0000",
                "changedBy": null,
                "dateChanged": null
            },
            "links": [
                {
                    "rel": "self",
                    "uri": "http://qa-refapp.openmrs.org/openmrs/ws/rest/v1/providerattributetype/cff22d83-27e6-4195-8398-229853c1283f"
                }
            ],
            "resourceVersion": "1.9"
        }

Can you do the same via REST?

1 Like

yes @dkayiwa It works well now thank you for helping :smiley: ,

I will try with the UI also from the next time its helpful !!

I was working on the draft of Encounter section in rest documentation, and I was going through this thread here, and I saw the example in which we pass visit information for creating a encounter, what would be preferred way of creating a new encounter by passing a visit object or just a UUID of the ongoing visit of which this encounter is a part of, are there any specific use cases where passing in a visit object would be preferred?

cc @ayesh @gcliff.