GSOC OPENMRS Project news:Editing sync record items payload

4 08 2008

These days I am implementing the final part of my soc project . One of the features in the last commit was the ability of the Sync Administrator to edit the Sync record items payload .To that end I created a method in the DWRSynchronizationService.java that gets the sync Item content and then sent it to the web client .

public String getSyncItemContent(String guid, String key) {
    String content = "";
    Collection<SyncItem> itemList;
    if (guid != null && guid != "" && key != null && key != "") {
        itemList = Context.getSynchronizationService().getSyncRecord(guid).getItems();
        for (SyncItem item : itemList) {
            if (item.getKey().getKeyValue().equals(key))
            content = item.getContent();
        }
    }
    return content;
}

After creating that function, I have to configure it in dwr.xml

<create creator="new" javascript="DWRSynchronizationService">
<param name="class" value="org.openmrs.web.dwr.DWRSynchronizationService" />
<include method="testConnection"/>
<include method="syncToParent"/>
<include method="getSyncItemContent"/>
<include method="setSyncItemContent"/>
</create>

The content String got in synchronizationViewRecordList.jsp (via Ajax) is just in mxl tags format and it looks like :

<org.openmrs.ConceptName><guid type="string">f6b29ecf-b15e-102b-ac59-58f4c1e745a2</guid>
<concept type="org.openmrs.Concept">f5aa80e9-b15e-102b-ac59-58f4c1e745a2</concept>
<description type="string">edited A disease caused by a lack of vitamin C and characterized by
 spongy gums, loosening of the teeth, and bleeding into the skin and mucous membranes.</description>
<locale type="locale">en</locale><name type="string">VITAMIN C DEFICIENCY</name>
<dateCreated type="timestamp">2004-06-01T00:00:00.000+0200</dateCreated><shortName type="string"></shortName>
<creator type="org.openmrs.User">fc193cd8-b15e-102b-ac59-58f4c1e745a2</creator></org.openmrs.ConceptName>

It was quite useful to have that payload in a single text field on the Admin UI so that the Sync Admin can edit it like that ,but it could result in a sync failure if the admin alters the tags structure or changes some crucial data like the GUIDs . So we decided to parse it with javaScript and display the payload values in different text fields where the Admin can edit and save them . To save that content we have to rebuild it from html tags .

The parsing code is here:

  function showContentResult(result) {
    DWRUtil.setValue("loadContent", "");
    domParser = new DOMParser();
    xmlDocument = domParser.parseFromString(result,'application/xml');
    root=xmlDocument.documentElement;
    rootElt=root.nodeName;
    cn=root.childNodes;
    newHTML="<form id='contentForm' action='' method=''><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
    for(i=0;i<cn.length;i++){
      newHTML+="<tr class='syncTr' ";
      if(i%2==0)newHTML+="bgcolor='#C4D9D9'";
      else newHTML+="bgcolor='#E7EFEF'";
      newHTML+="><td><strong>"+cn[i].nodeName+"</strong></td><td>"+cn[i].attributes[0].value+"</td><td   height='30'>
<input id='field'"+i+" type='text' value='";
      if(cn[i].childNodes.length==1)
      newHTML+=cn[i].childNodes[0].nodeValue;
      newHTML+="' size='50' /></td></tr>";
    }
    newHTML+="<tr><td>&nbsp;</td><td>&nbsp;</td><td   height='35' align='left' valign='bottom'><input type='button' name='saveButton'
   value='  Save  ' onclick='setItemContent();'/></td></tr>";
    newHTML+="</table></form>";
    document.getElementById("contents").innerHTML = newHTML;

  }
  function getItemContent() {
    DWRUtil.setValue("loadContent","Loading Item payload ...");
    DWRSynchronizationService.getSyncItemContent(currentGuid, currentKey,showContentResult);

  }

And the screen shot is here:

An other task implemented was to perform standard search for sync records.This is actually implemented according to the record name.

In the next step , I have to finalize all maintenance tasks and update the help screen .I hope that will be the end of the soc , and our codes should get in production quickly .


Actions

Information

5 responses

4 08 2008
Ben

If you put your code into “pre” tags they will come out much more readable with the spacing all intact. :-)

5 08 2008
nzeyi

Just changed my theme and let you fix the code .
What about the new header image ? I guess you like animals , parks . Did you have any chance to meet those gorillas in S.A. ?
http://www.kwitizina.org
http://rwandatourism.com

5 08 2008
Ben

I like the new theme! I did not see the gorillas in SA…I didn’t know they were famous for them at all.
Its a shame you had to write all the xml serialization/deserialization for the form. Its looking good though! I know Chase will be very happy to have this kind of interface to fix the errors instead of his “command-line” one. :-)

6 08 2008
chase

awesomeness

26 04 2009
nzeyi

You are welcome

Leave a comment