# Can't create Obs through REST with many levels of groupMembers

**URL:** <https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505>\
**Category:** Development\
**Tags:** observations, rest, encounters\
**Created:** [January 10, 2017, 1:22pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505 "2017-01-10T13:22:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkruszynski](https://talk.openmrs.org/letter_avatar/mkruszynski/32/5_5575768a8748004e209b776fc1b2916d.png) [@mkruszynski](https://talk.openmrs.org/u/mkruszynski)\
**Post date:** [January 10, 2017, 1:22pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/1 "2017-01-10T13:22:15Z")

</div>

Hello, I’m not able to create Obs with groupMembers during creating Encounter. Firstly I was trying to create an encounter (_/encounter_ endpoint) using following JSON in request:

```
{
   "encounterType":"72607bf4-28f6-4866-91d4-6798c0ea0ae1",
   "encounterDatetime":"2017-01-09T00:00:00.000+0100",
   "patient":"f045c657-ab4b-4309-b560-18f7d616e9f4",
   "provider":"f045c657-ab4b-4309-b560-18f7d616e9f4",
   "obs":[
      {
         "concept":"54915241-0aaa-4c33-b3bd-9213815a2454",
         "obsDatetime":"2017-01-09T00:00:00.000+0100",
         "groupMembers":[
            {
               "concept":"19d83cea-66a5-4bbf-a5a3-737b1be686f6",
               "obsDatetime":"2017-01-09T00:00:00.000+0100",
               "groupMembers":[
                  {
                     "concept":"b7d4fa65-2cc4-47c6-8196-2f3ffcdff318",
                     "value":"No",
                     "obsDatetime":"2017-01-09T00:00:00.000+0100"
                  },
                  {
                     "concept":"96bd2056-d77a-4438-ae10-92b872b0255d",
                     "value":"Yes",
                     "obsDatetime":"2017-01-09T00:00:00.000+0100"
                  }
               ]
            },
            {
               "concept":"f1b54f69-7169-4369-8f7a-722e96916abc",
               "value":"2nd",
               "obsDatetime":"2017-01-09T00:00:00.000+0100"
            },
            {
               "concept":"973fb9f2-114a-47c4-abe2-f2d2d9dcd799",
               "value":"Maybe",
               "obsDatetime":"2017-01-09T00:00:00.000+0100"
            }
         ]
      }
   ]
}
```

When I was using this method, Concepts with uuid’s b7d4fa65-2cc4-47c6-8196-2f3ffcdff318 and 96bd2056-d77a-4438-ae10-92b872b0255d aren’t created, and the both parents of these Concepts has a null value.

The next attempt was using a _/obs_ endpoint. Firstly I was creating an encounter without observations, then the observations was assigning to this encounter by the _/obs_ endpoint using following JSON:

```
{
   "concept":"54915241-0aaa-4c33-b3bd-9213815a2454",
   "encounter":"e42a4933-1cc6-4c76-9e91-24c4cfc53c8e",
   "obsDatetime":"2017-01-09T00:00:00.000+0100",
   "person":"f045c657-ab4b-4309-b560-18f7d616e9f4",
   "groupMembers":[
      {
         "concept":"19d83cea-66a5-4bbf-a5a3-737b1be686f6",
         "encounter":"e42a4933-1cc6-4c76-9e91-24c4cfc53c8e",
         "obsDatetime":"2017-01-09T00:00:00.000+0100",
         "person":"f045c657-ab4b-4309-b560-18f7d616e9f4",
         "groupMembers":[
            {
               "concept":"b7d4fa65-2cc4-47c6-8196-2f3ffcdff318",
               "encounter":"e42a4933-1cc6-4c76-9e91-24c4cfc53c8e",
               "value":"No",
               "obsDatetime":"2017-01-09T00:00:00.000+0100",
               "person":"f045c657-ab4b-4309-b560-18f7d616e9f4",
               "groupMembers":[]
            },
            {
               "concept":"96bd2056-d77a-4438-ae10-92b872b0255d",
               "encounter":"e42a4933-1cc6-4c76-9e91-24c4cfc53c8e",
               "value":"Yes",
               "obsDatetime":"2017-01-09T00:00:00.000+0100",
               "person":"f045c657-ab4b-4309-b560-18f7d616e9f4",
               "groupMembers":[]
            }
         ]
      },
      {
         "concept":"f1b54f69-7169-4369-8f7a-722e96916abc",
         "encounter":"e42a4933-1cc6-4c76-9e91-24c4cfc53c8e",
         "value":"2nd",
         "obsDatetime":"2017-01-09T00:00:00.000+0100",
         "person":"f045c657-ab4b-4309-b560-18f7d616e9f4",
         "groupMembers":[]
      },
      {
         "concept":"973fb9f2-114a-47c4-abe2-f2d2d9dcd799",
         "encounter":"e42a4933-1cc6-4c76-9e91-24c4cfc53c8e",
         "value":"Maybe",
         "obsDatetime":"2017-01-09T00:00:00.000+0100",
         "person":"f045c657-ab4b-4309-b560-18f7d616e9f4",
         "groupMembers":[]
      }
   ]
}
```

In response I’m getting 400 code and message:

```
Error while creating observation. Response body:
{
   "error":{
      "message":"Invalid Submission",
      "code":"webservices.rest.error.invalid.submission",
      "globalErrors":[
         {
            "code":"error.noValue",
            "message":"error.noValue"
         }
      ],
      "fieldErrors":{
         "groupMembers":[
            {
               "code":"Obs.error.inGroupMember",
               "message":"A member of this obs group has an error"
            }
         ]
      }
   }
}
```

After the addition of the required value to the observation, the most nested Observation are not created again.

There isn’t any stack traces. I’m working with version 1.12.0 Build 8f283e.

Is there some way to create the observations with more than one level of groupMembers? Can you help me to figure out where is the problem?

Regards!

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 11, 2017, 10:44am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/2 "2017-01-11T10:44:08Z")

</div>

Are you able to reproduce that problem on this server [int-refapp.openmrs.org](http://int-refapp.openmrs.org) which runs a newer version of the rest module than yours?

---

<div class="post-metadata">

**Author:** ![mkruszynski](https://talk.openmrs.org/letter_avatar/mkruszynski/32/5_5575768a8748004e209b776fc1b2916d.png) [@mkruszynski](https://talk.openmrs.org/u/mkruszynski)\
**Post date:** [January 11, 2017, 4:00pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/3 "2017-01-11T16:00:39Z")

</div>

I can’t reproduce this issue on this server, because when I’m sending following JSON to _/encounter_ endpoint:

```
{
   "encounterType":"51617df0-d203-48c7-a8b2-a080c7809c99",
   "encounterDatetime":"2017-01-10T00:00:00.000+0100",
   "patient":"1e070c06-589a-40ed-8f79-168e011c607a",
   "provider":"af7c3340-0503-11e3-8ffd-0800200c9a66",
   "obs":[
      {
         "concept":"6e437431-f5eb-43b2-bb49-550a2a554aa9",
         "obsDatetime":"2017-01-10T00:00:00.000+0100",
         "groupMembers":[
            {
               "concept":"1d79a15e-0d4a-47f2-bc4a-9f98abec0977",
               "obsDatetime":"2017-01-10T00:00:00.000+0100",
               "groupMembers":[
                  {
                     "concept":"c4bbc28a-c692-452f-b361-41c653a67fb4",
                     "value":"Yes",
                     "obsDatetime":"2017-01-10T00:00:00.000+0100"
                  },
                  {
                     "concept":"c204edc8-ebb8-4b02-91ea-cac95f0cf71b",
                     "value":"No",
                     "obsDatetime":"2017-01-10T00:00:00.000+0100"
                  }
               ]
            },
            {
               "concept":"7437bfbe-80d1-4085-a573-f8c56a9400fa",
               "value":"Maybe",
               "obsDatetime":"2017-01-10T00:00:00.000+0100"
            },
            {
               "concept":"d0c48e8d-c5f1-48c8-bf98-39440858a863",
               "value":"2nd",
               "obsDatetime":"2017-01-10T00:00:00.000+0100"
            }
         ]
      }
   ]
}
```

I’m getting an error:

```
{
  "error": {
    "message": "[provider on class org.openmrs.Encounter]",
    "code": "org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource:697",
    "detail": "org.openmrs.module.webservices.rest.web.response.ConversionException: provider on class org.openmrs.Encounter\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.getProperty(BaseDelegatingResource.java:697)\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setConvertedProperties(BaseDelegatingResource.java:600)\n\tat org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource.convert(DelegatingCrudResource.java:103)\n\tat org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource.create(DelegatingCrudResource.java:76)\n\tat org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController.create(MainResourceController.java:92)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:650)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:731)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:60)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:72)\n\tat org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:64)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\n\tat org.openmrs.module.webservices.rest.web.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:104)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\n\tat org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:82)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\n\tat org.openmrs.module.owa.filter.OwaFilter.doFilter(OwaFilter.java:57)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\n\tat org.openmrs.module.xforms.web.XformsFilter.doFilter(XformsFilter.java:69)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)\n\tat org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:54)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:108)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)\n\tat org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)\n\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)\n\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n\tat java.lang.Thread.run(Thread.java:745)\nCaused by: java.lang.NoSuchMethodException: Property 'provider' has no getter method\n\tat org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1127)\n\tat org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)\n\tat org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)\n\tat org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290)\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.getProperty(BaseDelegatingResource.java:691)\n\t... 78 more\n"
  }
}
```

Can you point out what is wrong with my request?

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 11, 2017, 4:08pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/4 "2017-01-11T16:08:02Z")

</div>

Remove the provider property because it was removed in platform 2.x which that server is running.

---

<div class="post-metadata">

**Author:** ![wyclif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/wyclif/32/19607_2.png) [@wyclif](https://talk.openmrs.org/u/wyclif)\
**Post date:** [January 11, 2017, 6:51pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/5 "2017-01-11T18:51:17Z")

</div>

The error message suggests that one of the group members in the tree is invalid, it’s not like it’s because of the many levels of group members.

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [January 11, 2017, 11:15pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/6 "2017-01-11T23:15:58Z")

</div>

@mkruszynski can you verify if it works with two levels but fails with 3 levels? (Or rather, works with n levels but fails with n+1?)

---

<div class="post-metadata">

**Author:** ![mkruszynski](https://talk.openmrs.org/letter_avatar/mkruszynski/32/5_5575768a8748004e209b776fc1b2916d.png) [@mkruszynski](https://talk.openmrs.org/u/mkruszynski)\
**Post date:** [January 12, 2017, 8:07am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/7 "2017-01-12T08:07:51Z")

</div>

@darius it is working for 2 levels, but for 3 it fails. When I want to create Observation with the most nested groupMembers from the latest above example (Concept with uuid _1d79a15e-0d4a-47f2-bc4a-9f98abec0977_) I’m getting similar error like in first post - this Concept has no value. When I add some value to this Concept - groupMembers aren’t created. In API documentation value field is optional, why it is required here?

Also I want to mention that all Concepts used in my tries has type ‘Text’.

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 12, 2017, 9:22am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/8 "2017-01-12T09:22:32Z")

</div>

@mkruszynski do you think you can create a failing unit test for this?

---

<div class="post-metadata">

**Author:** ![mkruszynski](https://talk.openmrs.org/letter_avatar/mkruszynski/32/5_5575768a8748004e209b776fc1b2916d.png) [@mkruszynski](https://talk.openmrs.org/u/mkruszynski)\
**Post date:** [January 12, 2017, 9:48am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/9 "2017-01-12T09:48:33Z")

</div>

@dkayiwa We have already created a test, the code is added below.

```
private Map prepareObservations() throws ConceptNameAlreadyInUseException {

    Map observations = new HashMap<>();

        String parent = createConcept("Concept1");
        String child1 = createConcept("Concept2");
        String child1Child1 = createConcept("Concept3");
        String child1Child2 = createConcept("Concept4");
        String child2 = createConcept("Concept5");
        String child3 = createConcept("Concept6");

        observations.put(parent + "/" + child1 + "/" + child1Child1, "Yes");
        observations.put(parent + "/" + child1 + "/" + child1Child2, "No");
        observations.put(parent + "/" + child2, "2nd");
        observations.put(parent + "/" + child3, "Maybe");

        return observations;
    }

    private String createConcept(String name) throws ConceptNameAlreadyInUseException {
        Concept concept = new Concept();
        ConceptName conceptName = new ConceptName(name);

        concept.setNames(Collections.singletonList(conceptName));
        concept.setDatatype(new Concept.DataType("TEXT"));
        concept.setConceptClass(new Concept.ConceptClass("Test"));

        return conceptService.createConcept(DEFAULT_CONFIG_NAME, concept).getUuid();
    }

    private void checkEncounterObs(List observations) {
        assertEquals(1L, observations.size());

        Observation observation = observations.get(0);

        assertNull(observation.getValue());
        isConceptEquals(observation, "Concept1");

        List groupMembers = observation.getGroupMembers();
        assertEquals(3L, groupMembers.size());

        for (Observation obs : groupMembers) {
            if (isConceptEquals(obs, "Concept2")) {
                assertNull(obs.getValue());

                List childGroupMembers = obs.getGroupMembers();
                assertEquals(2L, childGroupMembers.size());

                for (Observation childObs : childGroupMembers) {
                    if (isConceptEquals(obs, "Concept3")) {
                        assertEquals("Yes", childObs.getValue().getDisplay());
                    } else if (isConceptEquals(obs, "Concept4")) {
                        assertEquals("No", childObs.getValue().getDisplay());
                    } else {
                        fail();
                    }
                }
            } else if (isConceptEquals(obs, "Concept5")) {
                assertEquals("2nd", obs.getValue().getDisplay());
                assertEquals(0L, obs.getGroupMembers().size());
            } else if (isConceptEquals(obs, "Concept6")) {
                assertEquals("Maybe", obs.getValue().getDisplay());
                assertEquals(0L, obs.getGroupMembers().size());
            } else {
                fail();
            }
        }
}

private boolean isConceptEquals(Observation obs, String conceptName) {
        return StringUtils.equals(obs.getConcept().getDisplay(), conceptName);
}
```

In method _prepareObservations_ we are creating an Observations structure for our system. Value in map is assigning to the most nested child. If something is unclear, I can explain workflow of this test.

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 12, 2017, 12:48pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/10 "2017-01-12T12:48:17Z")

</div>

@mkruszynski i mean tests that i can just directly (without any changes) run in the rest webservices module. Something like [https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1\_0/controller/openmrs1\_9/EncounterController1\_9Test.java](https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterController1_9Test.java) or [https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1\_0/controller/openmrs1\_9/ObsController1\_9Test.java](https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ObsController1_9Test.java)

---

<div class="post-metadata">

**Author:** ![mkruszynski](https://talk.openmrs.org/letter_avatar/mkruszynski/32/5_5575768a8748004e209b776fc1b2916d.png) [@mkruszynski](https://talk.openmrs.org/u/mkruszynski)\
**Post date:** [January 13, 2017, 10:51am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/11 "2017-01-13T10:51:32Z")

</div>

@dkayiwa I made some sample test. I placed it on my [fork of given repository](https://github.com/mkruszynski/openmrs-module-webservices.rest/tree/ObsTest). I hope it will be enough to find out this issue.

---

<div class="post-metadata">

**Author:** ![raff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/raff/32/11894_2.png) [@raff](https://talk.openmrs.org/u/raff)\
**Post date:** [January 16, 2017, 12:46pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/12 "2017-01-16T12:46:32Z")

</div>

@dkayiwa, are you looking into that? If not, @adamg or @tmarzeion, could you please create an issue and fix Marcin’s test at [https://github.com/openmrs/openmrs-module-webservices.rest/compare/master...mkruszynski:ObsTest](https://github.com/openmrs/openmrs-module-webservices.rest/compare/master...mkruszynski:ObsTest)

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 16, 2017, 9:31pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/13 "2017-01-16T21:31:42Z")

</div>

@mkruszynski in your unit test, you have a NullPointerException because your obs does not have a concept hence the failure at obs.getConcept().getDatatype()

---

<div class="post-metadata">

**Author:** ![tmarzeion](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tmarzeion/32/4092_2.png) [@tmarzeion](https://talk.openmrs.org/u/tmarzeion)\
**Post date:** [January 17, 2017, 8:40am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/14 "2017-01-17T08:40:52Z")

</div>

@mkruszynskiI’ve created ticket for this issue: [RESTWS-636](https://issues.openmrs.org/browse/RESTWS-636) Ill try to take a look on this issue soon

---

<div class="post-metadata">

**Author:** ![tmarzeion](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tmarzeion/32/4092_2.png) [@tmarzeion](https://talk.openmrs.org/u/tmarzeion)\
**Post date:** [January 17, 2017, 10:56am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/15 "2017-01-17T10:56:39Z")

</div>

@mkruszynski @raff @dkayiwaI’ve fixed @mkruszynski’s test, so its possible to reproduce this issue via test. Good news is that this error is somewhere in REST-WS, not int CORE.

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 17, 2017, 11:05am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/16 "2017-01-17T11:05:59Z")

</div>

Great work @tmarzeion! 🙂So are you gonna fix it?

---

<div class="post-metadata">

**Author:** ![tmarzeion](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tmarzeion/32/4092_2.png) [@tmarzeion](https://talk.openmrs.org/u/tmarzeion)\
**Post date:** [January 17, 2017, 11:44am UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/17 "2017-01-17T11:44:46Z")

</div>

Yeah I’ll try @dkayiwa

---

<div class="post-metadata">

**Author:** ![mkruszynski](https://talk.openmrs.org/letter_avatar/mkruszynski/32/5_5575768a8748004e209b776fc1b2916d.png) [@mkruszynski](https://talk.openmrs.org/u/mkruszynski)\
**Post date:** [January 18, 2017, 1:50pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/18 "2017-01-18T13:50:03Z")

</div>

Thanks for help. Is it possible to put this fix in version 1.12 too? We would be thankful as we are using this version in our system.

---

<div class="post-metadata">

**Author:** ![tmarzeion](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tmarzeion/32/4092_2.png) [@tmarzeion](https://talk.openmrs.org/u/tmarzeion)\
**Post date:** [January 18, 2017, 1:53pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/19 "2017-01-18T13:53:59Z")

</div>

Fixed and merged: [https://github.com/openmrs/openmrs-module-webservices.rest/pull/264](https://github.com/openmrs/openmrs-module-webservices.rest/pull/264)

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 18, 2017, 2:13pm UTC](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505/20 "2017-01-18T14:13:58Z")

</div>

@mkruszynski you should be able to use the module as it is on your platform.

[Next page](https://talk.openmrs.org/t/cant-create-obs-through-rest-with-many-levels-of-groupmembers/9505.md?page=2)
