Cre­at­ing OpenMRS Mod­ules

This ar­ti­cle demon­strates how to build a ba­sic OpenMRS ‘hello-world’ mod­ule us­ing the OpenMRS mod­ule frame­work as the base—a sim­ple page that will be only shown to users if they are logged in. The soft­ware pre-req­ui­sites are the NetBeans IDE and SVN. Expe

OpenSource For You - - DEVELOPERS -

First, cre­ate a direc­tory for the de­vel­op­ment work—I called mine de­vel­op­ment— and change to it us­ing the cd com­mand. Do an psN check­out of the OpenMRp mod­ule frame­work with the fol­low­ing com­mand:

svn check­out­ules/hel­loworld/

Now launch NetBeans. rse File > Open Project, browse to the de­vel­op­ment direc­tory, se­lect the pom. xml file, and click Open. Once the project is open, the sub-projects can be opened by ex­pand­ing the project and open­ing the API and OMOD (right-click it and se­lect Open). iet’s as­sume your mod­ule name is Hello World and its ID is: hel­loworld.

Note: The mod­ule ID is a unique (among mod­ules) string that can dis­tin­guish the mod­ule from oth­ers. The mod­ule name can be any­thing that best de­scribes it.

Once you have de­cided on the mod­ule ID and name, it’s time to change some of the project prop­er­ties. In case you want to skip this step, you can ap­ply a diff to the checked­out ver­sion of the code by down­load­ing it from: https://gist. Oth­er­wise, mod­ify the prop­er­ties in the IROORwLng fiOHV, UHSODFLng @mod­[email protected] with the mod­ule ID and @mod­ule_­pack­[email protected] with the mod­ule pack­age name: omod/src/main/re­sources/Hel­loWorld.hbm.xml omod/src/main/re­sources/mes­sages.prop­er­ties oPod/VrF/PaLn/rHVourFHV/Fon­fig.xPO omod/src/main/re­sources/mes­sages_es.prop­er­ties omod/src/main/re­sources/mes­sages_fr.prop­er­ties omod/src/main/re­sources/mod­uleAp­pli­ca­tionCon­text.xml OWhHU PHWDdDWD WhDW nHHdV WR bH PRdL­fiHd Ln WhH fiOH RPRd/ VUF/PDLn/UHVRuUFHV/FRn­fig.xPO LV VhRwn bHORw: <id>hel­loworld</id> <name>hel­loworld</name> <ver­sion>1.0</ver­sion> <pack­age>org.openmrs.mod­ule.hel­loworld</pack­age> <au­thor>Ben Wolfe</au­thor> <de­scrip­tion>Ba­sic OpenMRS Sam­ple Mod­ule</de­scrip­tion>

Ba­sic func­tion­al­ity

Now, let’s add some more ba­sic func­tion­al­ity: when a user

with View Hello World SHUPLVVLRn YLHwV D VSHFL­fiF SDgH, D hel­loworld VWULng wLOO bH SULnWHd D VSHFL­fiF nuPbHU RI WLPHV (the num­ber is taken from the mes­sages.prop­er­ties fiOH Dnd LV equal to the global prop­er­ties).

Now edit the Fon­fig fiOH DW: hel­loworld/omod/src/main/ rHVourFHV/Fon­fig.xPO and add the fol­low­ing priv­i­lege un­der the priv­i­lege tag: <priv­i­lege> <name>View Hello World Phrase</name> <de­scrip­tion>Able to view the “Hello World” greet­ing</ de­scrip­tion> </priv­i­lege>

Then, add the global prop­erty—the num­ber of times to print hel­loworld— in mes­sages.prop­er­ties: <glob­alProp­erty> <prop­erty>hel­­peatNum­ber</prop­erty> <de­fault­Value>3</de­fault­Value> <de­scrip­tion>Num­ber of rep­e­ti­tions of the phrase “Hello World”</de­scrip­tion> </glob­alProp­erty>

Af­ter this, cre­ate viewHel­loWorld in /hel­loworld/omod/ src/main/we­bapp with the fol­low­ing com­mands: <%@ LncOudH fiOH ”/:EB-I1F/WHPSOaWH/LncOudH.MVS” %> <RSHnPrV:rHquLrH SrLvLOHgH ”VLHw HHOOR :RrOd” RWhHr­wLVH ”/ORgLn. hWP” rHdLrHcW ”/PR­duOH/hHOORwRrOd/vLHwHHOOR:RrOd.hWP” /> <%@ LncOudH fiOH ”/:EB-I1F/WHPSOaWH/hHadHr.MVS” %> <br/> <RSHnPrV:gORbaO3rRSHrWy NHy ”hHOORwRrOd.rHSHaW1uPbHr” var ”rHSHaW1uP” /> <c:fRrEach bHgLn ”1” Hnd ”${rHSHaW1uP}”>

<VSrLng:PHVVagH cRdH ”hHOORwRrOd.hHOOR:RrOd”/> <br/> </c:fRrEach> <br/> <%@ LncOudH fiOH ”/:EB-I1F/WHPSOaWH/fRRWHr.MVS” %>

You can ac­cess this page at the fol­low­ing lo­ca­tion af­ter mod­ule in­stal­la­tion: <Web ad­dress of the OpenMRS in­stal­la­tion> /mod­ule/hel­loworld/ viewHel­loWorld.htm

Adding to the user dash­board

In or­der to make it vis­i­ble to users in their homepage af­ter log­ging in (i.e., on the dash­board), add the fol­low­ing to <A3,>/hHOOoworOd/oPod/VrF/PaLn/rHVourFHV/Fon­fig.xPO. Ad­minList is a class that pro­vides func­tion­al­ity to ex­tend the dash­board view when mod­ule de­vel­op­ers want to add con­tent to it. Like this, there are other ex­ten­sion points also, which OHW RnH Ddd FRnWHnW WR VSHFL­fiF SDUWV RI WhH VFUHHn, whHnHYHU re­quired by the mod­ule de­vel­oper: <ex­ten­sion> <point>­min.list</point> <class>org.openmrs.mod­ule.hel­loworld.ex­ten­sion.html. Ad­minList</class> </ex­ten­sion>

Once this is done, it’s time to edit Ad­ to add con­tent to it. This needs to be added to the ad­min.list ex­ten­sion point. The fol­low­ing should be the con­tent of the ad­min.list fiOH:

pack­age org.openmrs.mod­ule.hel­loworld.ex­ten­sion.html; LPSRrW Mava.uWLO.HaVh0aS; LPSRrW Mava.uWLO.0aS; LPSRrW Rrg.RSHnPrV.PR­duOH.ExWHnVLRn; LPSRrW Rrg.RSHnPrV.PR­duOH.wHb.HxWHnVLRn.AdPLnLVWraWLRnSHcWLRnExW; SubOLc cOaVV AdPLn/LVW HxWHndV AdPLnLVWraWLRnSHcWLRnExW { SubOLc ExWHnVLRn.0EDIABT<3E gHW0HdLaTySH() {

rHWurn ExWHnVLRn.0EDIABT<3E.hWPO; } SubOLc SWrLng gHWTLWOH() {

re­turn “hel­loworld.ti­tle”;


Fig­ure 1: OMOD file

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.