@Test public void testCreateNewProviderUser() throws Exception { String json = "{\"firstName\":\"Darth\",\"lastName\":\"Vader\",\"gender\":\"M\",\"userName\":\"johnJames\",\"password\":\"Hello123\",\"type\":\"provider\",\"location\":\"dc5c1fcc-0459-4201-bf70-0b90535ba362\"} }"; SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class); Object user = controller.createNewUser(post, request, response); System.out.println(user); User u = Context.getUserService().getUserByUsername("johnJames"); Provider p = Context.getProviderService().getProviders("Darth Vader", null, null, null).iterator().next(); Assert.assertEquals("Darth Vader", p.getName()); Assert.assertEquals("1", u.getPerson().getAttribute("Health Center").getValue()); }
@RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() public Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initUserController(); validatePost(post); Person person = new Person(); PersonName name = new PersonName(post.get("firstName").toString(), null, post.get("lastName").toString()); name.setPreferred(true); person.addName(name); person.setGender(post.get("gender").toString()); Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString()); if (location == null) { throw new ResponseException( "Location uuid not found") {}; } PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("email") != null) { PersonAttribute emailAttribute = new PersonAttribute(); emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email")); emailAttribute.setValue(post.get("email").toString()); person.addAttribute(emailAttribute); } if (post.get("phone") != null) { PersonAttribute phoneAttribute = new PersonAttribute(); phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact")); phoneAttribute.setValue(post.get("phone").toString()); person.addAttribute(phoneAttribute); } if (post.get("donateOrgans") != null) { PersonAttribute donateOrgansAttribute = new PersonAttribute(); donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs")); donateOrgansAttribute.setValue(post.get("donateOrgans").toString()); person.addAttribute(donateOrgansAttribute); } String type = post.get("type").toString(); if (type.equals(TYPE[0])) { person = savePatient(person, post, location); } else if (type.equals(TYPE[1])) { saveProvider(person, post); } User user = new User(person); user.setUsername(post.get("userName").toString()); if (type.equals(TYPE[1])) { user.addRole(Context.getUserService().getRole("System Developer")); user.addRole(Context.getUserService().getRole("Provider")); } User newUser = service.saveUser(user, post.get("password").toString()); service.setUserProperty(newUser, OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, location.getId().toString()); return RestUtil.created(response, getUserAsSimpleObject(newUser)); }
RaxaUserController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() public Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initUserController(); validatePost(post); Person person = new Person(); PersonName name = new PersonName(post.get("firstName").toString(), null, post.get("lastName").toString()); name.setPreferred(true); person.addName(name); person.setGender(post.get("gender").toString()); Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString()); if (location == null) { throw new ResponseException( "Location uuid not found") {}; } PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("email") != null) { PersonAttribute emailAttribute = new PersonAttribute(); emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email")); emailAttribute.setValue(post.get("email").toString()); person.addAttribute(emailAttribute); } if (post.get("phone") != null) { PersonAttribute phoneAttribute = new PersonAttribute(); phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact")); phoneAttribute.setValue(post.get("phone").toString()); person.addAttribute(phoneAttribute); } if (post.get("donateOrgans") != null) { PersonAttribute donateOrgansAttribute = new PersonAttribute(); donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs")); donateOrgansAttribute.setValue(post.get("donateOrgans").toString()); person.addAttribute(donateOrgansAttribute); } String type = post.get("type").toString(); if (type.equals(TYPE[0])) { person = savePatient(person, post, location); } else if (type.equals(TYPE[1])) { saveProvider(person, post); } User user = new User(person); user.setUsername(post.get("userName").toString()); if (type.equals(TYPE[1])) { user.addRole(Context.getUserService().getRole("System Developer")); user.addRole(Context.getUserService().getRole("Provider")); } User newUser = service.saveUser(user, post.get("password").toString()); service.setUserProperty(newUser, OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, location.getId().toString()); return RestUtil.created(response, getUserAsSimpleObject(newUser)); } }
RaxaUserController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() public Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initUserController(); validatePost(post); Person person = new Person(); PersonName name = new PersonName(post.get("firstName").toString(), null, post.get("lastName").toString()); name.setPreferred(true); person.addName(name); person.setGender(post.get("gender").toString()); Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString()); if (location == null) { throw new ResponseException( "Location uuid not found") {}; } PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("email") != null) { PersonAttribute emailAttribute = new PersonAttribute(); emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email")); emailAttribute.setValue(post.get("email").toString()); person.addAttribute(emailAttribute); } if (post.get("phone") != null) { PersonAttribute phoneAttribute = new PersonAttribute(); phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact")); phoneAttribute.setValue(post.get("phone").toString()); person.addAttribute(phoneAttribute); } if (post.get("donateOrgans") != null) { PersonAttribute donateOrgansAttribute = new PersonAttribute(); donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs")); donateOrgansAttribute.setValue(post.get("donateOrgans").toString()); person.addAttribute(donateOrgansAttribute); } String type = post.get("type").toString(); if (type.equals(TYPE[0])) { person = savePatient(person, post, location); } else if (type.equals(TYPE[1])) { saveProvider(person, post); } User user = new User(person); user.setUsername(post.get("userName").toString()); if (type.equals(TYPE[1])) { user.addRole(Context.getUserService().getRole("System Developer")); user.addRole(Context.getUserService().getRole("Provider")); } User newUser = service.saveUser(user, post.get("password").toString()); service.setUserProperty(newUser, OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, location.getId().toString()); return RestUtil.created(response, getUserAsSimpleObject(newUser)); }  }
RaxaUserController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() public Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initUserController(); validatePost(post); Person person = new Person(); PersonName name = new PersonName(post.get("firstName").toString(), null, post.get("lastName").toString()); name.setPreferred(true); person.addName(name); person.setGender(post.get("gender").toString()); Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString()); if (location == null) { throw new ResponseException( "Location uuid not found") {}; } PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("email") != null) { PersonAttribute emailAttribute = new PersonAttribute(); emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email")); emailAttribute.setValue(post.get("email").toString()); person.addAttribute(emailAttribute); } if (post.get("phone") != null) { PersonAttribute phoneAttribute = new PersonAttribute(); phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact")); phoneAttribute.setValue(post.get("phone").toString()); person.addAttribute(phoneAttribute); } if (post.get("donateOrgans") != null) { PersonAttribute donateOrgansAttribute = new PersonAttribute(); donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs")); donateOrgansAttribute.setValue(post.get("donateOrgans").toString()); person.addAttribute(donateOrgansAttribute); } String type = post.get("type").toString(); if (type.equals(TYPE[0])) { person = savePatient(person, post, location); } else if (type.equals(TYPE[1])) { saveProvider(person, post); } User user = new User(person); user.setUsername(post.get("userName").toString()); if (type.equals(TYPE[1])) { user.addRole(Context.getUserService().getRole("System Developer")); user.addRole(Context.getUserService().getRole("Provider")); } User newUser = service.saveUser(user, post.get("password").toString()); service.setUserProperty(newUser, OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, location.getId().toString()); return RestUtil.created(response, getUserAsSimpleObject(newUser)); }  void initUserController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response); }
RaxaUserController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() public Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initUserController(); validatePost(post); Person person = new Person(); PersonName name = new PersonName(post.get("firstName").toString(), null, post.get("lastName").toString()); name.setPreferred(true); person.addName(name); person.setGender(post.get("gender").toString()); Location location = Context.getLocationService().getLocationByUuid(post.get("location").toString()); if (location == null) { throw new ResponseException( "Location uuid not found") {}; } PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("email") != null) { PersonAttribute emailAttribute = new PersonAttribute(); emailAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Email")); emailAttribute.setValue(post.get("email").toString()); person.addAttribute(emailAttribute); } if (post.get("phone") != null) { PersonAttribute phoneAttribute = new PersonAttribute(); phoneAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Primary Contact")); phoneAttribute.setValue(post.get("phone").toString()); person.addAttribute(phoneAttribute); } if (post.get("donateOrgans") != null) { PersonAttribute donateOrgansAttribute = new PersonAttribute(); donateOrgansAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Donate Organs")); donateOrgansAttribute.setValue(post.get("donateOrgans").toString()); person.addAttribute(donateOrgansAttribute); } String type = post.get("type").toString(); if (type.equals(TYPE[0])) { person = savePatient(person, post, location); } else if (type.equals(TYPE[1])) { saveProvider(person, post); } User user = new User(person); user.setUsername(post.get("userName").toString()); if (type.equals(TYPE[1])) { user.addRole(Context.getUserService().getRole("System Developer")); user.addRole(Context.getUserService().getRole("Provider")); } User newUser = service.saveUser(user, post.get("password").toString()); service.setUserProperty(newUser, OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCATION, location.getId().toString()); return RestUtil.created(response, getUserAsSimpleObject(newUser)); }  void initUserController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Post user information") @ResponseBody() Object createNewUser(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response);  }