@Test public void testCreateNewPatient() throws Exception { String json = "{\"names\": [{\"givenName\":\"john\",\"familyName\":\"James\"}],\"gender\":\"M\", \"age\":23 }"; SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class); SimpleObject patient = (SimpleObject) (controller.createNewPatient(post, request, response)); System.out.println(patient); System.out.println(patient.get("uuid")); Patient p = Context.getPatientService().getPatientByUuid(patient.get("uuid").toString()); Assert.assertNotNull(p); Assert.assertEquals("James", p.getFamilyName()); Assert.assertTrue(p.getAge() == 23); }
@RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody public Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initPatientController(); validatePost(post); Person person = new Person(); addNames(person, post); person.setGender(post.get("gender").toString()); if (post.get("birthdate") != null) { if (post.get("time") != null) { String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }; for (int i = 0; i < supportedFormats.length; i++) { try { Date date = new SimpleDateFormat(supportedFormats[i]).parse(post.get("time").toString()); person.setBirthdate(date); person.setBirthdateEstimated(Boolean.FALSE); } catch (Exception ex) {} } } } else if (post.get("age") != null) { person.setBirthdateFromAge(Integer.parseInt(post.get("age").toString()), new Date()); person.setBirthdateEstimated(Boolean.TRUE); } Integer userLocation = Integer.parseInt(Context.getPersonService().getPersonByUuid( Context.getAuthenticatedUser().getPerson().getUuid()).getAttribute("Health Center").getValue()); Location location = Context.getLocationService().getLocation(userLocation); PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("attributes") != null) { addAttributes(person, post); } if (post.get("addresses") != null) { addAddresses(person, post); } return RestUtil.created(response, getPatientAsSimpleObject(savePatient(person, post, location))); }
RaxaPatientController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody public Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initPatientController(); validatePost(post); Person person = new Person(); addNames(person, post); person.setGender(post.get("gender").toString()); if (post.get("birthdate") != null) { if (post.get("time") != null) { String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }; for (int i = 0; i < supportedFormats.length; i++) { try { Date date = new SimpleDateFormat(supportedFormats[i]).parse(post.get("time").toString()); person.setBirthdate(date); person.setBirthdateEstimated(Boolean.FALSE); } catch (Exception ex) {} } } } else if (post.get("age") != null) { person.setBirthdateFromAge(Integer.parseInt(post.get("age").toString()), new Date()); person.setBirthdateEstimated(Boolean.TRUE); } Integer userLocation = Integer.parseInt(Context.getPersonService().getPersonByUuid( Context.getAuthenticatedUser().getPerson().getUuid()).getAttribute("Health Center").getValue()); Location location = Context.getLocationService().getLocation(userLocation); PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("attributes") != null) { addAttributes(person, post); } if (post.get("addresses") != null) { addAddresses(person, post); } return RestUtil.created(response, getPatientAsSimpleObject(savePatient(person, post, location))); } }
RaxaPatientController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody public Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initPatientController(); validatePost(post); Person person = new Person(); addNames(person, post); person.setGender(post.get("gender").toString()); if (post.get("birthdate") != null) { if (post.get("time") != null) { String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }; for (int i = 0; i < supportedFormats.length; i++) { try { Date date = new SimpleDateFormat(supportedFormats[i]).parse(post.get("time").toString()); person.setBirthdate(date); person.setBirthdateEstimated(Boolean.FALSE); } catch (Exception ex) {} } } } else if (post.get("age") != null) { person.setBirthdateFromAge(Integer.parseInt(post.get("age").toString()), new Date()); person.setBirthdateEstimated(Boolean.TRUE); } Integer userLocation = Integer.parseInt(Context.getPersonService().getPersonByUuid( Context.getAuthenticatedUser().getPerson().getUuid()).getAttribute("Health Center").getValue()); Location location = Context.getLocationService().getLocation(userLocation); PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("attributes") != null) { addAttributes(person, post); } if (post.get("addresses") != null) { addAddresses(person, post); } return RestUtil.created(response, getPatientAsSimpleObject(savePatient(person, post, location))); }  }
RaxaPatientController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody public Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initPatientController(); validatePost(post); Person person = new Person(); addNames(person, post); person.setGender(post.get("gender").toString()); if (post.get("birthdate") != null) { if (post.get("time") != null) { String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }; for (int i = 0; i < supportedFormats.length; i++) { try { Date date = new SimpleDateFormat(supportedFormats[i]).parse(post.get("time").toString()); person.setBirthdate(date); person.setBirthdateEstimated(Boolean.FALSE); } catch (Exception ex) {} } } } else if (post.get("age") != null) { person.setBirthdateFromAge(Integer.parseInt(post.get("age").toString()), new Date()); person.setBirthdateEstimated(Boolean.TRUE); } Integer userLocation = Integer.parseInt(Context.getPersonService().getPersonByUuid( Context.getAuthenticatedUser().getPerson().getUuid()).getAttribute("Health Center").getValue()); Location location = Context.getLocationService().getLocation(userLocation); PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("attributes") != null) { addAttributes(person, post); } if (post.get("addresses") != null) { addAddresses(person, post); } return RestUtil.created(response, getPatientAsSimpleObject(savePatient(person, post, location))); }  void initPatientController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET, params = "safesearch") @WSDoc("Gets Summarized representation of Patients for the given search") @ResponseBody() String safeSearchPatients(@RequestParam String safesearch, HttpServletRequest request); }
RaxaPatientController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody public Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initPatientController(); validatePost(post); Person person = new Person(); addNames(person, post); person.setGender(post.get("gender").toString()); if (post.get("birthdate") != null) { if (post.get("time") != null) { String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }; for (int i = 0; i < supportedFormats.length; i++) { try { Date date = new SimpleDateFormat(supportedFormats[i]).parse(post.get("time").toString()); person.setBirthdate(date); person.setBirthdateEstimated(Boolean.FALSE); } catch (Exception ex) {} } } } else if (post.get("age") != null) { person.setBirthdateFromAge(Integer.parseInt(post.get("age").toString()), new Date()); person.setBirthdateEstimated(Boolean.TRUE); } Integer userLocation = Integer.parseInt(Context.getPersonService().getPersonByUuid( Context.getAuthenticatedUser().getPerson().getUuid()).getAttribute("Health Center").getValue()); Location location = Context.getLocationService().getLocation(userLocation); PersonAttribute locationAttribute = new PersonAttribute(); locationAttribute.setAttributeType(Context.getPersonService().getPersonAttributeTypeByName("Health Center")); locationAttribute.setValue(location.getId().toString()); person.addAttribute(locationAttribute); if (post.get("attributes") != null) { addAttributes(person, post); } if (post.get("addresses") != null) { addAddresses(person, post); } return RestUtil.created(response, getPatientAsSimpleObject(savePatient(person, post, location))); }  void initPatientController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New Patient") @ResponseBody Object createNewPatient(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET, params = "safesearch") @WSDoc("Gets Summarized representation of Patients for the given search") @ResponseBody() String safeSearchPatients(@RequestParam String safesearch, HttpServletRequest request);  }