Openmrs API Context Dao is null while building project

I am trying to run the pharmacy api by following steps but I am getting the following error Context Dao is null.Can someone help me out how can I run this project. Thanks Here is the code I am using it.

package test; import org.openmrs.module.drugorders.api.impl.*;

import org.openmrs.util.DatabaseUpdateException;

import org.openmrs.util.InputRequiredException;

import org.openmrs.util.OpenmrsUtil;

import org.openmrs.Patient;

import org.openmrs.api.context.Context; import org.openmrs.api.context.ServiceContext; import org.openmrs.api.db.ContextDAO; import org.openmrs.module.ModuleMustStartException;

import org.openmrs.module.drugorders.api.db.hibernate.*;import;

import java.util.List;

import java.util.Properties;import org.hibernate.*;

import org.hibernate.cfg.Configuration;

public class DrugApiTest { public static void main(String[] args) {

/*    // TODO Auto-generated method stub

    drugordersServiceImpl orderService = new drugordersServiceImpl();

    HibernatedrugordersDAO dao = new HibernatedrugordersDAO();

    Configuration conf = new Configuration();

    SessionFactory sessionFactory = conf.buildSessionFactory();








    catch(Exception ex)





public static void API_INIT() throws ModuleMustStartException, DatabaseUpdateException, InputRequiredException



     File propsFile = new File(OpenmrsUtil.getApplicationDataDirectory(), "");

      Properties props = new Properties();

      OpenmrsUtil.loadProperties(props, propsFile);
      Context.startup("jdbc:mysql://localhost:3306/openmrs?autoReconnect=true", "root", "root", props);

      try {


        Context.authenticate("siqlain", "Admin123");

        List<Patient> patients = Context.getPatientService().getPatients("John");

        for (Patient patient : patients) {

          System.out.println("Found patient with name " + patient.getPersonName() + " and uuid: " + patient.getUuid());



      finally {




Our recommendation is that you use the REST API. Did you get a chance to look at this?

Thanks, But I downloaded the pharmacy module from here I want to test the pharmacy api.I want to update the module but I don’t know how can I run and build this project.Can you help me out which approach I used.Just for note I build the project and run but it’s say ContextDao is null.

Have you evaluated bahmni?

Yes,I have idea about bahmni but not in detail.Can you provide the links related to my query?

I need a pharmacy module like appointment module which provide us the rest api.Is there any available module in openmrs which provide the rest api for the client.If bahmni do this please let me know.


In order for us to guide you accordingly, can you give us some background of what you are doing? Are you implementing OpenMRS in a hospital? Are you just playing with modules for learning purposes? Or are you doing something else?

I am just doing it for learning purpose right now.My university group is doing Final year project about pharmacy module.We want to learn about the existing pharmacy module and want to develop front-end in angular,that’s the sole purpose right now.

Can you paste at the errors you get on running mvn clean install against that module?

Daniel I am able to build that module successfully.The problem is that when I used the code of that module which is located here and I try to use the api,I got the error i.e contextDAO is null. By using these steps which provided by openmrs guide

Can you please look at the code of pharmacy and tell me how will I would be able to write rest-api for that module. Thanks for your continuously help.

As for writing the REST API, can you start by looking at these?

thanks,I will look at it and let you know.

Daniel I built the sample webservices which get the concept from openmrs.I added it to my localhost openmrs reference application and It loaded successfully but I am not able to see it on the openmrs-api document.Does it need any configuration?

Can we look at your code?

I uploaded my code on github.Please have a look