Home > OPENMRS > Create Your first module in OPENMRS

Create Your first module in OPENMRS

OPENMRS community is a worldwide network of volunteers from many different backgrounds including technology, health care, and international development. If you are willing to start the work as a developer in openmrs, the first thing you have to do is create a simple module. Though i have followed the screen cast offerd by openmrs university, i have found some issues with it. So this post is for clearing your concerns on it.

Configure Eclipse Environment

  1. First download this file.
  2. In Eclipse, do File -> Import -> Install -> Install Software Items from File
  3. Select the file you donwloaded
  4. Before you proceed make sure Install latest version of selected software is not selected.

Now let’s move with maven to build our module. Here is settings.xml


<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
 http://maven.apache.org/xsd/settings-1.0.0.xsd">

 <pluginGroups>
 <pluginGroup>org.openmrs.maven.plugins</pluginGroup>
 </pluginGroups>
 <profiles>
 <profile>
 <id>OpenMRS</id>
 <activation>
 <activeByDefault>true</activeByDefault>
 </activation>
 <properties>
 <archetypeCatalog>http://mavenrepo.openmrs.org/nexus/content/repositories/public/archetype-catalog.xml</archetypeCatalog>
 <archetypeRepository>http://mavenrepo.openmrs.org/nexus/content/repositories/public</archetypeRepository>
 </properties>
 <repositories>
 <repository>
 <id>openmrs-repo</id>
 <name>OpenMRS Nexus Repository</name>
 <url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
 </repository>
 </repositories>
 <pluginRepositories>
 <pluginRepository>
 <id>openmrs-repo</id>
 <name>OpenMRS Nexus Repository</name>
 <url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
 <snapshots>
 <enabled>false</enabled>
 </snapshots>
 </pluginRepository>
 </pluginRepositories>
 </profile>
 </profiles>

</settings>

In maven use

mvn -s path_to_settings.xml [other options] [<goal(s)>] [<phase(s)>]

This will not override your local settings for the mvn. Now type

mvn module-wizard:generate -s path_to_settings.xml

And add only the following.

ArtifactId= conceptname

Module Name=Concept Name

Module Description = Concept name management.

add admin links:y

others put default values.

This will generate your first module as conceptname. This contains two sub modules.

  1. conceptname-api
  2. conceptname-omod

Add following class to the conceptname-omod submodule


/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC. All Rights Reserved.
 */
package org.openmrs.module.conceptname.web.controller;

import org.openmrs.Concept;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * The main controller.
 */
@Controller
public class ConceptNameManageController {

 @ModelAttribute
 public Concept getConcept(@RequestParam(required=false, value="conceptId")Concept concept){
 return concept;
 }
 @RequestMapping(value="/module/conceptname/viewConceptNames",method=RequestMethod.GET)
 public void showForm(){

 }
}

Then Change the AdminList.java as follows

/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC. All Rights Reserved.
 */
package org.openmrs.module.conceptname.extension.html;

import java.util.LinkedHashMap;
import java.util.Map;

import org.openmrs.module.Extension;
import org.openmrs.module.web.extension.AdministrationSectionExt;

/**
 * This class defines the links that will appear on the administration page under the
 * "conceptname.title" heading.
 */
public class AdminList extends AdministrationSectionExt {

 /**
 * @see AdministrationSectionExt#getMediaType()
 */
 public Extension.MEDIA_TYPE getMediaType() {
 return Extension.MEDIA_TYPE.html;
 }

 /**
 * @see AdministrationSectionExt#getTitle()
 */
 public String getTitle() {
 return "Concept Name Management";
 }

 /**
 * @see AdministrationSectionExt#getLinks()
 */
 public Map<String, String> getLinks() {
 LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
 map.put("/module/conceptname/viewConceptNames.form", "conceptname.manage");
 return map;
 }

}

Now add the viewConceptNames.jsp file to the webapp folder.


<%@ include file="/WEB-INF/template/include.jsp"%>
<%@ include file="/WEB-INF/template/header.jsp"%>

<%@ include file="template/localHeader.jsp"%>

<form method="get">
Choose a Concept :<openmrs_tag:conceptField formFieldName="conceptId"/>
<input type="submit" value="View"/>
</form>
<hr/>
<table>
 <tr>
 <th>Concept ID</th>
 <td>${ concept.conceptId }</td>
 </tr>
 <tr>
 <th>UUID</th>
 <td>${ concept.uuid }</td>
 </tr>
 <tr>
 <th>Names</th>
 <td>
 <table border="1">
 <tr>
 <th>Locale</th>
 <th>Preferred</th>
 <th>Type</th>
 <th>Names</th>
 <th>Tags</th>
 </tr>
 <c:forEach var="cn" items="${ concept.names }">
 <tr>
 <td>${ cn.locale }</td>
 <td>${ cn.localePreferred }</td>
 <td>${ cn.conceptNameType }</td>
 <td><c:out escapeXml="true" value="${ cn.name }"/></td>
 <td>
 <c:forEach var="t" items="${ cn.tags }" varStatus="status">
 <c:out escapeXml="true" value="${ t.tag }"/>
 <c:if test="${ not status.last }">,</c:if>
 </c:forEach>
 </td>
 </tr>
 </c:forEach>
 </table>
 </td>
 </tr>

</table>
<%@ include file="/WEB-INF/template/footer.jsp"%>

Now do mvn package -s path_to_settings.xml. Then run your OPENMRS standalone version and  got o Admin-> manage module-> insatll the .omod file. Now You can view it under the Admin->Concept Name Management.

Advertisements
Categories: OPENMRS
  1. smuwanga
    October 30, 2015 at 9:38 am

    Hello, many thanks for this.

    The last step;
    [mvn package -s path_to_settings.xml. Then run your OPENMRS standalone version and got o Admin-> manage module-> insatll the .omod file. Now You can view it under the Admin->Concept Name Management ] has been very helpful.

    By the way, for the 1.9.9 OpenMRS, I managed to find the .omod file in the target folder of myModule.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: