abayomi
(Abayomi Abebe)
October 4, 2022, 7:44am
1
Application Name: Platform
Version Number: 2.4.3 Build 0ff0ed
Question:
I’m new to Openmrs. I’m trying create my own module. I already looked these articles
Creating Your First Module - Documentation - OpenMRS Wiki
Creating Modules - Documentation - OpenMRS Wiki
Making Your First Module · GitBook
With these articles i already developed basic module. now i need to know how to connect this module to database and retrieve data? please help me? thanks in advance.
abayomi
(Abayomi Abebe)
October 6, 2022, 12:07pm
3
Thanks for the reply. I’m receiving error.
it’s showing java.sql.SQLSyntaxErrorException: Unknown column ‘this_.changed_by’ in ‘field list’ but i cannot find the place.
my code: - package org.openmrs.module.basicexample.web.controller;import org.springfram - Pastebin.com
please help me to fix this.
Your Item class its supposed to inherit all attributes from BaseOpenmrsData in the liquibase file. since your extending BaseOpenmrsData
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.search.annotations.Field;
This file has been truncated. show original
abayomi
(Abayomi Abebe)
October 11, 2022, 9:02am
5
Thanks for the reply. how can i save record.
I tried post request to http://localhost:8080/openmrs/ws/rest/v1/item but it showing me
Request processing failed; nested exception is org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException
It means your missing out the save method in the controller that does post payload from the endpoint to the database:
Take a look at this for-example openmrs-module-webservices.rest/DrugResource1_8.java at fa0e04d6cde6e3a7f55a672217b2419257692ee6 · openmrs/openmrs-module-webservices.rest · GitHub
Do you mind sharing the link to the repository so that I could have a look at where your going wrong.
abayomi
(Abayomi Abebe)
October 11, 2022, 10:36am
8
Thanks for the reply. here is the code.
Try autowiring the service in the ItemResource class
@Autowired
BasicexampleService basicexampleService;
then on save method try out this
Item item = basicexampleService.saveItem(t);
abayomi
(Abayomi Abebe)
October 11, 2022, 12:16pm
10
I change it but still getting the same error
Please share the github repository link here
abayomi
(Abayomi Abebe)
October 11, 2022, 4:57pm
12
Thanks for the reply. here is the repository
abayomi
(Abayomi Abebe)
October 14, 2022, 3:42am
14
Can you help me to solve this plz?
Dear @abayomi please check on the repo issues, there are comments which I have created.
Regards,
1 Like
abayomi
(Abayomi Abebe)
October 18, 2022, 3:12am
17
Thank you very much. i will check that.
abayomi
(Abayomi Abebe)
October 18, 2022, 10:59am
18
Thank you very much for the help. i did the modification as you mentioned. but still not working.
getting error
Request processing failed; nested exception is org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException
i updated github code repo. can you check what’s wrong???
Please check again, everything works now if you replace the with what i have changed but remember I did make changes on setOwner using User currentUser = Context.getAuthenticatedUser(); to set the owner value you will be required to update the tests so as to pass.
abayomi
(Abayomi Abebe)
October 19, 2022, 11:53am
20
opened 12:16PM - 18 Oct 22 UTC
https://github.com/abayomiabebe/rest/blob/cc4c5c448f3727d1145177852d3b695cfd2056… 3b/api/src/main/java/org/openmrs/module/basicexample/api/impl/BasicexampleServiceImpl.java#L51
@Override
public Item saveItem(Item item) throws APIException {
if (item.getOwner() == null) {
User currentUser = Context.getAuthenticatedUser();
item.setOwner(currentUser);
}
return dao.saveItem(item);
}
after i replace these there is an error
There are test failures.[ERROR] [ERROR] Please refer to D:\rest\api\target\surefire-reports for the individual test results.
in that file there is an error
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.555 sec <<< FAILURE! saveItem_shouldSetOwnerIfNotSet(org.openmrs.module.basicexample.api.BasicexampleServiceTest) Time elapsed: 0.48 sec <<< ERROR! org.openmrs.api.APIException: A user context must first be passed to setUserContext()...use Context.openSession() (and closeSession() to prevent memory leaks!) before using the API
so i keep the old code as it is. but i changed other modifications. now i’m receiving
Request processing failed; nested exception is java.lang.NullPointerException
abayomi
(Abayomi Abebe)
November 1, 2022, 6:11am
21
I’m stuck here. can you help me
Hello, @abayomi check on the github and merge the PR
1 Like