public void setService(Class<?> type, Object service) { if (!realServices.containsKey(type)) { Object realService = null; try { realService = Context.getService(type); } catch (Exception e) { //let's not fail if context is not configured } realServices.put(type, realService); } Context.getServiceContext().setService(type, service); }
/** * Prevents regression after patch from #2174: * "Prevent duplicate proxies and AOP in context services" * * @see Context#getService(Class) */ @Test public void getService_shouldReturnTheSameObjectWhenCalledMultipleTimesForTheSameClass() { PatientService ps1 = Context.getService(PatientService.class); PatientService ps2 = Context.getService(PatientService.class); Assert.assertTrue(ps1 == ps2); }
@Test public void shouldStartModules() throws ClassNotFoundException { Class<?> atdServiceClass = Context.loadClass("org.openmrs.module.atdproducer.service.ATDService"); Class<?> dssServiceClass = Context.loadClass("org.openmrs.module.dssmodule.DssService"); Assert.assertNotNull(atdServiceClass); Assert.assertNotNull(dssServiceClass); Assert.assertNotNull(Context.getService(atdServiceClass)); Assert.assertNotNull(Context.getService(dssServiceClass)); } }
/** * Returns the HTML Form Entry service from the Context * * @return HTML Form Entry service */ public static HtmlFormEntryService getService() { return Context.getService(HtmlFormEntryService.class); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public ConceptMap getByUniqueId(String uniqueId) { return Context.getService(RestHelperService.class).getObjectByUuid(ConceptMap.class, uniqueId); }
private static Object getProviderRoleById(Integer providerRoleId) { // we have to fetch the provider role by reflection, since the provider management module is not a required dependency try { Class<?> providerManagementServiceClass = Context.loadClass("org.openmrs.module.providermanagement.api.ProviderManagementService"); Object providerManagementService = Context.getService(providerManagementServiceClass); Method getProviderRole = providerManagementServiceClass.getMethod("getProviderRole", Integer.class); return getProviderRole.invoke(providerManagementService, providerRoleId); } catch(Exception e) { throw new RuntimeException("Unable to get provider role by id; the Provider Management module needs to be installed if using the providerRoles attribute", e); } }
public static List<Provider> getProviders(List<ProviderRole> providerRoles) { if (providerRoles == null || providerRoles.size() == 0) { return new ArrayList<Provider>(); } ProviderManagementService providerManagementService = Context.getService(ProviderManagementService.class); //Service returns list of org.openmrs.module.providermanagement.Provider, not org.openmrs.Provider return new ArrayList<Provider>(providerManagementService.getProvidersByRoles(providerRoles)); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUpdatableProperties() */ @Override public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); //this actually throws a ResourceDoesNotSupportOperationException return orderResource.getUpdatableProperties(); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUpdatableProperties() */ @Override public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); //this actually throws a ResourceDoesNotSupportOperationException return orderResource.getUpdatableProperties(); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#doGetAll(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public NeedsPaging<CohortMember1_8> doGetAll(Cohort parent, RequestContext context) throws ResponseException { List<CohortMember1_8> members = new ArrayList<CohortMember1_8>(); for (Patient cohortMember : Context.getService(RestHelperService.class).getPatients(parent.getMemberIds())) { members.add(new CohortMember1_8(cohortMember, parent)); } return new NeedsPaging<CohortMember1_8>(members, context); }
private Patient getPatient(String patientUniqueId) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceByName( RestConstants.VERSION_1 + "/patient")).getByUniqueId(patientUniqueId); if (patient == null) throw new ObjectNotFoundException(); return patient; }
/** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#asRepresentation(T, * org.openmrs.module.webservices.rest.web.representation.Representation) */ @Override public SimpleObject asRepresentation(User instance, Representation rep) throws ConversionException { UserAndPassword1_8 userPass = new UserAndPassword1_8(instance); UserResource1_8 userResource = (UserResource1_8) Context.getService(RestService.class).getResourceByName( RestConstants.VERSION_1 + "/user"); return userResource.asRepresentation(userPass, rep); }
public Patient getPatientForUpdate(String uuid, Map<String, Object> propertiesToUpdate) { Patient patient = getByUniqueId(uuid); PersonResource1_8 personResource = (PersonResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Person.class); personResource.setConvertedProperties(patient, (Map<String, Object>) propertiesToUpdate.get("person"), personResource.getUpdatableProperties(), false); return patient; }
@Override public void contextRefreshed() { // initialize all resources and search handlers Context.getService(RestService.class).initialize(); log.info("Clearing caches..."); ConversionUtil.clearCache(); ReflectionUtil.clearCaches(); SwaggerSpecificationCreator.clearCache(); }
@Override protected void delete(PatientProgramAttribute delegate, String reason, RequestContext context) throws ResponseException { delegate.setVoided(true); delegate.setVoidReason(reason); Context.getService(ProgramWorkflowService.class).savePatientProgram(delegate.getPatientProgram()); }
@Before public void before() { service = Context.getConceptService(); restHelperService = Context.getService(RestHelperService.class); }
@Before public void beforeEachTests() throws Exception { personAttributeSimpleObject.putAll(new ObjectMapper().readValue(PERSON_ATTRIBUTE_JSON, HashMap.class)); resource = (PersonAttributeResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( PersonAttribute.class); }
@Before public void before() { service = Context.getConceptService(); restHelperService = Context.getService(RestHelperService.class); Concept concept = service.getConceptByUuid(RestTestConstants1_8.CONCEPT2_UUID); ConceptMap next = concept.getConceptMappings().iterator().next(); //The UUID property is not set in standardTestDataset.xml. next.setUuid(UUID.randomUUID().toString()); service.saveConcept(concept); conceptMapUuid = next.getUuid(); }
@Before public void before() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_HTML_FORM_ENTRY_SERVICE_DATASET)); service = Context.getService(HtmlFormEntryService.class); }
@Test public void shouldEditAnOrderSetMember() throws Exception { OrderSetMember orderSetMember = Context.getService(RestHelperService.class).getObjectByUuid(OrderSetMember.class, orderSetMemberUuid); Assert.assertEquals(null, orderSetMember.getOrderTemplate()); String json = "{\n" + "\"orderTemplate\": \"NEW TEST TEMPLATE\"\n" + " }"; deserialize(handle(newPostRequest(getURI() + "/" + getUuid(), json))); Assert.assertTrue(PropertyUtils.getProperty(orderSetMember, "orderTemplate").equals("NEW TEST TEMPLATE")); }