diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/api/pom.xml b/api/pom.xml index 7d9e7fa..8d2b12a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -101,6 +101,12 @@ json-simple 1.1.1 + + + com.google.guava + guava + 27.0.1-jre + diff --git a/api/src/main/java/org/openmrs/module/dhisconnector/DHISConnectorActivator.java b/api/src/main/java/org/openmrs/module/dhisconnector/DHISConnectorActivator.java index 538aac1..f3ca6f4 100644 --- a/api/src/main/java/org/openmrs/module/dhisconnector/DHISConnectorActivator.java +++ b/api/src/main/java/org/openmrs/module/dhisconnector/DHISConnectorActivator.java @@ -11,55 +11,89 @@ */ package org.openmrs.module.dhisconnector; +import java.io.File; + +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openmrs.module.ModuleActivator; +import org.openmrs.util.OpenmrsUtil; /** * This class contains the logic that is run every time this module is either started or stopped. */ public class DHISConnectorActivator implements ModuleActivator { - + protected Log log = LogFactory.getLog(getClass()); - + + public static final String DHISCONNECTOR_MAPPINGS_FOLDER = File.separator + "dhisconnector" + File.separator + + "mappings"; + /** * @see ModuleActivator#willRefreshContext() */ - public void willRefreshContext() { log.info("Refreshing DHIS Connector Module"); } - + @Override + public void willRefreshContext() { + log.info("Refreshing DHIS Connector Module"); + } + /** * @see ModuleActivator#contextRefreshed() */ + @Override public void contextRefreshed() { log.info("DHIS Connector Module refreshed"); } - + /** * @see ModuleActivator#willStart() */ + @Override public void willStart() { log.info("Starting DHIS Connector Module"); } - + /** * @see ModuleActivator#started() */ + @Override public void started() { + String mappingsDirecoryPath = OpenmrsUtil.getApplicationDataDirectory() + DHISCONNECTOR_MAPPINGS_FOLDER; + File mappingsDirecory = new File(mappingsDirecoryPath); + + if (!mappingsDirecory.exists()) { + try { + if (!mappingsDirecory.mkdirs()) { + log.warn("Not able to create resource folder"); + } else { + File directory = new File(getClass().getClassLoader().getResource("mappings").getFile()); + FileUtils.copyDirectory(directory, mappingsDirecory); + log.debug("Copiyed all the mapping files to:" + mappingsDirecory); + } + + } + catch (Exception e) { + e.printStackTrace(); + log.error("Error while creating " + DHISCONNECTOR_MAPPINGS_FOLDER + "Directory"); + } + } log.info("DHIS Connector started"); } - + /** * @see ModuleActivator#willStop() */ + @Override public void willStop() { log.info("Stopping DHIS Connector Module"); } - + /** * @see ModuleActivator#stopped() */ + @Override public void stopped() { log.info("DHIS Connector Module stopped"); } - + } diff --git a/api/src/main/java/org/openmrs/module/dhisconnector/ReportToDataSetMapping.java b/api/src/main/java/org/openmrs/module/dhisconnector/ReportToDataSetMapping.java index 3bcd5f2..c44d8ca 100644 --- a/api/src/main/java/org/openmrs/module/dhisconnector/ReportToDataSetMapping.java +++ b/api/src/main/java/org/openmrs/module/dhisconnector/ReportToDataSetMapping.java @@ -50,6 +50,9 @@ public class ReportToDataSetMapping extends BaseOpenmrsObject { @Column(name = "org_unit_uid", nullable = false) private String orgUnitUid; + @Column(name = "is_full_mapping") + private String isFullMapping; + @Column(name = "last_run") private Date lastRun; @@ -61,10 +64,11 @@ public class ReportToDataSetMapping extends BaseOpenmrsObject { public ReportToDataSetMapping() { } - public ReportToDataSetMapping(String mapping, Location location, String orgUnitId) { + public ReportToDataSetMapping(String mapping, Location location, String orgUnitId, String isFullMapping) { setMapping(mapping); setLocation(location); setOrgUnitUid(orgUnitId); + setIsFullMapping(isFullMapping); } public Integer getId() { @@ -75,6 +79,14 @@ public void setId(Integer id) { this.id = id; } + public String getIsFullMapping() { + return isFullMapping; + } + + public void setIsFullMapping(String isFullMapping) { + this.isFullMapping = isFullMapping; + } + public String getOrgUnitUid() { return orgUnitUid; } diff --git a/api/src/main/java/org/openmrs/module/dhisconnector/api/DHISConnectorService.java b/api/src/main/java/org/openmrs/module/dhisconnector/api/DHISConnectorService.java index 0456e3c..296f0e4 100644 --- a/api/src/main/java/org/openmrs/module/dhisconnector/api/DHISConnectorService.java +++ b/api/src/main/java/org/openmrs/module/dhisconnector/api/DHISConnectorService.java @@ -15,6 +15,7 @@ import java.util.Date; import java.util.List; +import org.openmrs.Location; import org.openmrs.api.OpenmrsService; import org.openmrs.module.dhisconnector.ReportToDataSetMapping; import org.openmrs.module.dhisconnector.api.model.DHISDataValueSet; @@ -101,9 +102,11 @@ public interface DHISConnectorService extends OpenmrsService { void deleteReportToDataSetMapping(Integer reportToDataSetMappingId); - String runAndPushReportToDHIS(ReportToDataSetMapping reportToDatasetMapping); + String runAndPushReportToDHIS(ReportToDataSetMapping reportToDatasetMapping, Location location, String orgUnitUid, boolean isEndOfFullMapping); String runAllAutomatedReportsAndPostToDHIS(); + + String runReportsAndPostToDHIS(List mps); String transformToDHISPeriod(Calendar startDate, Calendar endDate, String periodType, Date lastRun); diff --git a/api/src/main/java/org/openmrs/module/dhisconnector/api/impl/DHISConnectorServiceImpl.java b/api/src/main/java/org/openmrs/module/dhisconnector/api/impl/DHISConnectorServiceImpl.java index ab75230..7c5ea7d 100644 --- a/api/src/main/java/org/openmrs/module/dhisconnector/api/impl/DHISConnectorServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/dhisconnector/api/impl/DHISConnectorServiceImpl.java @@ -35,7 +35,9 @@ import java.util.Date; import java.util.Enumeration; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; @@ -79,6 +81,7 @@ import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; import org.openmrs.Location; +import org.openmrs.api.AdministrationService; import org.openmrs.api.context.Context; import org.openmrs.api.impl.BaseOpenmrsService; import org.openmrs.module.dhisconnector.Configurations; @@ -122,12 +125,13 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import com.google.common.base.Splitter; + /** * It is a default implementation of {@link DHISConnectorService}. */ public class DHISConnectorServiceImpl extends BaseOpenmrsService implements DHISConnectorService { - private DHISConnectorDAO dao; public static final String DHISCONNECTOR_MAPPINGS_FOLDER = File.separator + "dhisconnector" + File.separator @@ -148,6 +152,8 @@ public class DHISConnectorServiceImpl extends BaseOpenmrsService implements DHIS public static final String DATASETS_PATH = "/api/dataSets/"; + public static final String GLOBAL_PROPERTY_FULL_MAPPING = "dhisconnector.fullmappingvalues"; + public static final String ORGUNITS_PATH = "/api/organisationUnits/"; public static String JSON_POST_FIX = ".json?paging=false"; @@ -526,9 +532,11 @@ public String postDataToDHISEndpoint(String endpoint, String data) { client = new DefaultHttpClient(); BasicHttpContext localcontext = new BasicHttpContext(); - HttpPost httpPost = new HttpPost( - dhisURL.getPath() + endpoint + (configs.useAdxInsteadOfDxf() ? (endpoint.indexOf("?") > -1 ? "&" - : "?" + "dataElementIdScheme=CODE&orgUnitIdScheme=CODE&idScheme=CODE") : "")); + HttpPost httpPost = new HttpPost(dhisURL.getPath() + endpoint + + (configs.useAdxInsteadOfDxf() + ? (endpoint.indexOf("?") > -1 ? "&" + : "?" + "dataElementIdScheme=CODE&orgUnitIdScheme=CODE&idScheme=CODE") + : "")); Credentials creds = new UsernamePasswordCredentials(user, pass); Header bs = new BasicScheme().authenticate(creds, httpPost, localcontext); @@ -693,7 +701,7 @@ public Object postDataValueSet(DHISDataValueSet dataValueSet) { JAXBContext jaxbImportSummaryContext = JAXBContext.newInstance(ImportSummaries.class); Unmarshaller importSummaryUnMarshaller = jaxbImportSummaryContext.createUnmarshaller(); - return (ImportSummaries) importSummaryUnMarshaller.unmarshal(new StringReader(responseString)); + return importSummaryUnMarshaller.unmarshal(new StringReader(responseString)); } else { return mapper.readValue(responseString, DHISImportSummary.class); } @@ -717,7 +725,6 @@ public List getMappings() { File[] files = mappingsDirecory.listFiles(new FilenameFilter() { - @Override public boolean accept(File dir, String name) { return name.endsWith(DHISCONNECTOR_MAPPING_FILE_SUFFIX); @@ -1290,19 +1297,20 @@ public void deleteReportToDataSetMapping(Integer reportToDataSetMappingId) { } @Override - public String runAndPushReportToDHIS(ReportToDataSetMapping reportToDatasetMapping) { + public String runAndPushReportToDHIS(ReportToDataSetMapping reportToDatasetMapping, Location location, String orgUnitUid, + boolean isEndOfFullMapping) { if (reportToDatasetMapping != null) { Calendar startDate = Calendar.getInstance(Context.getLocale()); Calendar endDate = Calendar.getInstance(Context.getLocale()); DHISMapping mapping = getMapping(reportToDatasetMapping.getMapping()); if (mapping != null) { - Location location = reportToDatasetMapping.getLocation(); + //Location location = reportToDatasetMapping.getLocation(); String periodType = mapping.getPeriodType(); PeriodIndicatorReportDefinition ranReportDef = (PeriodIndicatorReportDefinition) Context .getService(ReportDefinitionService.class) .getDefinitionByUuid(mapping.getPeriodIndicatorReportGUID()); - String orgUnitUid = reportToDatasetMapping.getOrgUnitUid(); + //String orgUnitUid = reportToDatasetMapping.getOrgUnitUid(); Date lastRun = reportToDatasetMapping.getLastRun(); if (location != null && ranReportDef != null) { String period = transformToDHISPeriod(startDate, endDate, periodType, lastRun); @@ -1314,8 +1322,10 @@ public String runAndPushReportToDHIS(ReportToDataSetMapping reportToDatasetMappi Object response = sendReportDataToDHIS(ranReport, mapping, period, orgUnitUid); if (response != null) { - reportToDatasetMapping.setLastRun(endDate.getTime()); - saveReportToDataSetMapping(reportToDatasetMapping); + if (isEndOfFullMapping) { + reportToDatasetMapping.setLastRun(endDate.getTime()); + saveReportToDataSetMapping(reportToDatasetMapping); + } return getPostSummary(response); } @@ -1384,9 +1394,9 @@ private String getPostSummary(Object o) { if (o != null) { try { if (o instanceof ImportSummaries) - s += mapper.writeValueAsString(mapper.readTree(mapper.writeValueAsString((ImportSummaries) o))); + s += mapper.writeValueAsString(mapper.readTree(mapper.writeValueAsString(o))); else if (o instanceof DHISImportSummary) - s += mapper.writeValueAsString((DHISImportSummary) o); + s += mapper.writeValueAsString(o); } catch (IOException e) { e.printStackTrace(); @@ -1459,15 +1469,52 @@ public Report runPeriodIndicatorReport(PeriodIndicatorReportDefinition reportDef @Override public String runAllAutomatedReportsAndPostToDHIS() { - String responses = ""; + List mps = getAllReportToDataSetMappings(); + return runReportsAndPostToDHIS(mps); + } + + @Override + public String runReportsAndPostToDHIS(List mps) { + String responses = ""; + + ///////////// + AdministrationService as = Context.getAdministrationService(); + String fullMappingProperty = as.getGlobalProperty(GLOBAL_PROPERTY_FULL_MAPPING); + Map locOrgUnits = null; + if (StringUtils.isNotBlank(fullMappingProperty) && fullMappingProperty.contains("=")) + locOrgUnits = Splitter.on(",").withKeyValueSeparator("=").split(fullMappingProperty); + else + locOrgUnits = new HashMap(); + /////////////// + if (mps != null) { for (ReportToDataSetMapping m : mps) { - String resp = runAndPushReportToDHIS(m); - - if (StringUtils.isNotBlank(resp)) - responses += " => " + resp; + if (StringUtils.isNotBlank(m.getIsFullMapping()) && m.getIsFullMapping().equals("Y")) { + int counting = 0; + boolean isEndOfFullMapping = false; + for (Map.Entry mapentry : locOrgUnits.entrySet()) { + if (StringUtils.isNotBlank((String) mapentry.getKey()) + && StringUtils.isNotBlank((String) mapentry.getValue())) { + if (locOrgUnits.size() - 1 == counting) + isEndOfFullMapping = true; + String resp = runAndPushReportToDHIS(m, + Context.getLocationService().getLocationByUuid((String) mapentry.getKey()), + (String) mapentry.getValue(), isEndOfFullMapping); + + if (StringUtils.isNotBlank(resp)) + responses += " => " + resp; + counting++; + } + } + + } else { + String resp = runAndPushReportToDHIS(m, m.getLocation(), m.getOrgUnitUid(), true); + + if (StringUtils.isNotBlank(resp)) + responses += " => " + resp; + } } } diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index e801508..ab5748b 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -64,11 +64,30 @@ + + + + + + + + + + Add new column to the table dhisconnector_report_to_dataset table + + + + + + + + SELECT COUNT(*) FROM diff --git a/api/src/main/resources/messages.properties b/api/src/main/resources/messages.properties index 5862775..675fcf0 100644 --- a/api/src/main/resources/messages.properties +++ b/api/src/main/resources/messages.properties @@ -7,6 +7,7 @@ ${project.parent.artifactId}.runReports=Run Reports ${project.parent.artifactId}.url=URL ${project.parent.artifactId}.user=Username ${project.parent.artifactId}.pass=Password +${project.parent.artifactId}.fullMapping=Custom Location Mapping ${project.parent.artifactId}.save=Save ${project.parent.artifactId}.saveSuccess=DHIS Server Successfully Configured ${project.parent.artifactId}.saveFailure=DHIS Server Configuration Failed diff --git a/omod/.gitignore b/omod/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/omod/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/omod/pom.xml b/omod/pom.xml index 6875eb6..74bce4e 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -28,6 +28,21 @@ reportingrest-api + + org.openmrs.module + webservices.rest-omod + ${webservicesRestVersion} + provided + + + + org.openmrs.module + webservices.rest-omod + ${webservicesRestVersion} + provided + + + org.openmrs.module webservices.rest-omod-common @@ -93,6 +108,12 @@ commons-io 2.4 + + + com.google.guava + guava + 27.0.1-jre + @@ -222,6 +243,7 @@ + deploy-web diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/extension/html/AdminList.java b/omod/src/main/java/org/openmrs/module/dhisconnector/extension/html/AdminList.java index 68d2040..e1dbffb 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/extension/html/AdminList.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/extension/html/AdminList.java @@ -48,6 +48,7 @@ public Map getLinks() { map.put("/module/dhisconnector/dhis2BackupImport.form", "dhisconnector.dhis2Backup.import"); map.put("/module/dhisconnector/dhis2BackupExport.form", "dhisconnector.dhis2Backup.export"); map.put("/module/dhisconnector/uploadMapping.form", "dhisconnector.uploadMapping"); + map.put("/module/dhisconnector/fullMapping.form", "dhisconnector.fullMapping"); map.put("/module/dhisconnector/exportMappings.form", "dhisconnector.exportMapping"); map.put("/module/dhisconnector/createMapping.form", "dhisconnector.createMapping"); map.put("/module/dhisconnector/manageMappings.form", "dhisconnector.manageMappings"); diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorController.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorController.java index 5fdb7e3..db2d33b 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorController.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorController.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -51,111 +52,112 @@ import org.springframework.web.context.request.WebRequest; import org.springframework.web.multipart.MultipartFile; +import com.google.common.base.Splitter; + /** * Controller for the DHIS Connector Module admin pages */ @Controller public class DHISConnectorController { - + protected final Log log = LogFactory.getLog(getClass()); - + public static final String GLOBAL_PROPERTY_URL = "dhisconnector.url"; - + public static final String GLOBAL_PROPERTY_USER = "dhisconnector.user"; - + public static final String GLOBAL_PROPERTY_PASS = "dhisconnector.pass"; - + + public static final String GLOBAL_PROPERTY_FULL_MAPPING = "dhisconnector.fullmappingvalues"; + @RequestMapping(value = "/module/dhisconnector/manage", method = RequestMethod.GET) public void manage(ModelMap model) { model.addAttribute("user", Context.getAuthenticatedUser()); } - + @RequestMapping(value = "/module/dhisconnector/createMapping", method = RequestMethod.GET) public void createMapping(ModelMap model) { model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/configureServer", method = RequestMethod.GET) public void configureServer(ModelMap model) { String url = Context.getAdministrationService().getGlobalProperty(GLOBAL_PROPERTY_URL); String user = Context.getAdministrationService().getGlobalProperty(GLOBAL_PROPERTY_USER); String pass = Context.getAdministrationService().getGlobalProperty(GLOBAL_PROPERTY_PASS); - + model.addAttribute("url", url); model.addAttribute("user", user); model.addAttribute("pass", pass); model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/configureServer", method = RequestMethod.POST) public void saveConfig(ModelMap model, @RequestParam(value = "url", required = true) String url, - @RequestParam(value = "user", required = true) String user, - @RequestParam(value = "pass", required = true) String pass, WebRequest req) throws ParseException { - + @RequestParam(value = "user", required = true) String user, + @RequestParam(value = "pass", required = true) String pass, WebRequest req) throws ParseException { + AdministrationService as = Context.getAdministrationService(); GlobalProperty urlProperty = as.getGlobalPropertyObject(GLOBAL_PROPERTY_URL); GlobalProperty userProperty = as.getGlobalPropertyObject(GLOBAL_PROPERTY_USER); GlobalProperty passProperty = as.getGlobalPropertyObject(GLOBAL_PROPERTY_PASS); - + if (Context.getService(DHISConnectorService.class).testDHISServerDetails(url, user, pass)) { // Save the properties urlProperty.setPropertyValue(url); userProperty.setPropertyValue(user); passProperty.setPropertyValue(pass); - + as.saveGlobalProperty(urlProperty); as.saveGlobalProperty(userProperty); as.saveGlobalProperty(passProperty); - + req.setAttribute(WebConstants.OPENMRS_MSG_ATTR, - Context.getMessageSourceService().getMessage("dhisconnector.saveSuccess"), - WebRequest.SCOPE_SESSION); - + Context.getMessageSourceService().getMessage("dhisconnector.saveSuccess"), WebRequest.SCOPE_SESSION); + model.addAttribute("url", url); model.addAttribute("user", user); model.addAttribute("pass", pass); } else { req.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, - Context.getMessageSourceService().getMessage("dhisconnector.saveFailure"), - WebRequest.SCOPE_SESSION); - + Context.getMessageSourceService().getMessage("dhisconnector.saveFailure"), WebRequest.SCOPE_SESSION); + model.addAttribute("url", urlProperty.getPropertyValue()); model.addAttribute("user", userProperty.getPropertyValue()); model.addAttribute("pass", passProperty.getPropertyValue()); } } - + @RequestMapping(value = "/module/dhisconnector/runReports", method = RequestMethod.GET) public void showRunReports(ModelMap model) { model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/runReports", method = RequestMethod.POST) public void runReport(ModelMap model, @RequestParam(value = "report", required = true) String reportMappingFilename, - @RequestParam(value = "location", required = true) Date date, - @RequestParam(value = "date", required = true) Integer locationId, WebRequest req) throws ParseException { + @RequestParam(value = "location", required = true) Date date, + @RequestParam(value = "date", required = true) Integer locationId, WebRequest req) throws ParseException { DHISConnectorService dcs = Context.getService(DHISConnectorService.class); - + List reportsWithMappings = dcs.getReportWithMappings(dcs.getMappings()); - + model.addAttribute("reports", reportsWithMappings); } - + @RequestMapping(value = "/module/dhisconnector/uploadMapping", method = RequestMethod.GET) public void showuploadMapping(ModelMap model) { passOnUploadingFeedback(model, "", ""); model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/uploadMapping", method = RequestMethod.POST) - public void uploadMapping(ModelMap model, - @RequestParam(value = "mapping", required = false) MultipartFile mapping) { + public void uploadMapping(ModelMap model, @RequestParam(value = "mapping", required = false) MultipartFile mapping) { String successMessage = ""; String failedMessage = ""; - + if (!mapping.isEmpty()) { String msg = Context.getService(DHISConnectorService.class).uploadMappings(mapping); - + if (msg.startsWith("Successfully")) { successMessage = msg; failedMessage = ""; @@ -168,47 +170,80 @@ public void uploadMapping(ModelMap model, } passOnUploadingFeedback(model, successMessage, failedMessage); } - + + @RequestMapping(value = "/module/dhisconnector/fullMapping", method = RequestMethod.POST) + public void fullMapping(ModelMap model, + @RequestParam(value = "fullMappingValues", required = true) String fullMappingValues, WebRequest request) { + + AdministrationService as = Context.getAdministrationService(); + GlobalProperty fullMappingProperty = as.getGlobalPropertyObject(GLOBAL_PROPERTY_FULL_MAPPING); + + fullMappingProperty.setPropertyValue(fullMappingValues); + as.saveGlobalProperty(fullMappingProperty); + + request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, " -> Save was successful", WebRequest.SCOPE_SESSION); + + renderFullMappingPage(model); + } + + @RequestMapping(value = "/module/dhisconnector/fullMapping", method = RequestMethod.GET) + public void renderFullMappingPage(ModelMap model) { + List orgUnits = Context.getService(DHISConnectorService.class).getDHISOrgUnits(); + + model.addAttribute("locations", Context.getLocationService().getAllLocations(false)); + model.addAttribute("orgUnits", orgUnits); + AdministrationService as = Context.getAdministrationService(); + String fullMappingProperty = as.getGlobalProperty(GLOBAL_PROPERTY_FULL_MAPPING); + + if (StringUtils.isNotBlank(fullMappingProperty) && fullMappingProperty.contains("=")) + model.addAttribute("fullMappingsMap", Splitter.on(",").withKeyValueSeparator("=").split(fullMappingProperty)); + else + model.addAttribute("fullMappingsMap", new HashMap()); + /*model.addAttribute("postResponse", postResponse);*/ + } + private void passOnUploadingFeedback(ModelMap model, String successMessage, String failedMessage) { model.addAttribute("failureWhileUploading", failedMessage); model.addAttribute("successWhileUploading", successMessage); } - + @RequestMapping(value = "/module/dhisconnector/exportMappings", method = RequestMethod.GET) public void exportMapping(ModelMap model) { passOnExportedFeedback(model, "", ""); model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + private void passOnExportedFeedback(ModelMap model, String failureWhileExporting, String successWhileExporting) { model.addAttribute("failureWhileExporting", failureWhileExporting); model.addAttribute("successWhileExporting", successWhileExporting); } - + @RequestMapping(value = "/module/dhisconnector/exportMappings", method = RequestMethod.POST) public void exportMapping(ModelMap model, HttpServletRequest request, HttpServletResponse response) { String[] selectedMappings = request.getParameter("selectedMappings") != null - ? request.getParameter("selectedMappings").split("<:::>") : null; + ? request.getParameter("selectedMappings").split("<:::>") + : null; String msg = ""; - + if (selectedMappings != null) { try { - String[] exported = Context.getService(DHISConnectorService.class) - .exportSelectedMappings(selectedMappings); + String[] exported = Context.getService(DHISConnectorService.class).exportSelectedMappings(selectedMappings); msg = exported[0]; int BUFFER_SIZE = 4096; String fullPath = exported[1];// contains path to - // backedupMappings - + // backedupMappings + if (StringUtils.isNotBlank(msg) && msg.startsWith("Successfully")) { exportZipFile(response, BUFFER_SIZE, fullPath); passOnExportedFeedback(model, "", msg); } else { passOnExportedFeedback(model, msg, ""); } - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { e.printStackTrace(); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } } else { @@ -217,35 +252,36 @@ public void exportMapping(ModelMap model, HttpServletRequest request, HttpServle } try { response.sendRedirect("/module/dhisconnector/exportMappings"); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } } - + /* * fullPath must be a temporally stored file path since it's deleted after * being exported */ private void exportZipFile(HttpServletResponse response, int BUFFER_SIZE, String fullPath) - throws FileNotFoundException, IOException { + throws FileNotFoundException, IOException { if (fullPath != null) { File downloadFile = new File(fullPath); FileInputStream inputStream = new FileInputStream(downloadFile); String mimeType = "application/octet-stream"; - + System.out.println("MIME type: " + mimeType); response.setContentType(mimeType); response.setContentLength((int) downloadFile.length()); - + String headerKey = "Content-Disposition"; String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName()); - + response.setHeader(headerKey, headerValue); - + OutputStream outStream = response.getOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = -1; - + while ((bytesRead = inputStream.read(buffer)) != -1) { outStream.write(buffer, 0, bytesRead); } @@ -254,7 +290,7 @@ private void exportZipFile(HttpServletResponse response, int BUFFER_SIZE, String (new File(fullPath)).delete(); } } - + @RequestMapping(value = "/module/dhisconnector/dhis2BackupExport", method = RequestMethod.GET) public void backupDHIS2APIExport(ModelMap model) { failureOrSuccessFeedback(model, "", ""); @@ -262,36 +298,38 @@ public void backupDHIS2APIExport(ModelMap model) { model.addAttribute("lastSyncedAt", Context.getService(DHISConnectorService.class).getLastSyncedAt()); model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/dhis2BackupImport", method = RequestMethod.GET) public void backupDHIS2(ModelMap model) { failureOrSuccessFeedback(model, "", ""); model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/dhis2BackupExport", method = RequestMethod.POST) public void backupDHIS2APIImport(ModelMap model, HttpServletResponse response) { String path = Context.getService(DHISConnectorService.class).getDHIS2APIBackupPath(); - + if (Context.getService(DHISConnectorService.class).dhis2BackupExists() && StringUtils.isNotBlank(path)) { try { exportZipFile(response, 4096, path); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { e.printStackTrace(); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } } - + } - + @RequestMapping(value = "/module/dhisconnector/dhis2BackupImport", method = RequestMethod.POST) public void backupDHIS2APIImport(ModelMap model, - @RequestParam(value = "dhis2APIbBackup", required = false) MultipartFile dhis2APIbBackup) { + @RequestParam(value = "dhis2APIbBackup", required = false) MultipartFile dhis2APIbBackup) { if (StringUtils.isNotBlank(dhis2APIbBackup.getOriginalFilename()) - && dhis2APIbBackup.getOriginalFilename().endsWith(".zip")) { + && dhis2APIbBackup.getOriginalFilename().endsWith(".zip")) { String msg = Context.getService(DHISConnectorService.class).uploadDHIS2APIBackup(dhis2APIbBackup); - + if (msg.startsWith("Successfully")) { failureOrSuccessFeedback(model, "", msg); } else { @@ -299,20 +337,20 @@ public void backupDHIS2APIImport(ModelMap model, } } else { failureOrSuccessFeedback(model, - Context.getMessageSourceService().getMessage("dhisconnector.dhis2backup.wrongUpload"), ""); + Context.getMessageSourceService().getMessage("dhisconnector.dhis2backup.wrongUpload"), ""); } } - + private void failureOrSuccessFeedback(ModelMap model, String failureEncountered, String successEncountered) { model.addAttribute("failureEncountered", failureEncountered); model.addAttribute("successEncountered", successEncountered); } - + @RequestMapping(value = "/module/dhisconnector/manageMappings", method = RequestMethod.GET) public void manageMappings(ModelMap model) { model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @RequestMapping(value = "/module/dhisconnector/adxGenerator", method = RequestMethod.GET) public @ResponseBody String adxGenerator(@RequestParam(value = "dxfDataValueSet") String dxfDataValueSet) { String adx = null; @@ -321,94 +359,98 @@ public void manageMappings(ModelMap model) { try { if (StringUtils.isNotBlank(dxfDataValueSet)) { dvs = mapper.readValue(dxfDataValueSet, DHISDataValueSet.class); - + return Context.getService(DHISConnectorService.class).getAdxFromDxf(dvs); } - } catch (JsonParseException e) { + } + catch (JsonParseException e) { e.printStackTrace(); - } catch (JsonMappingException e) { + } + catch (JsonMappingException e) { e.printStackTrace(); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } return adx; } - + @RequestMapping(value = "/module/dhisconnector/failedData", method = RequestMethod.GET) public void failedDataRender(ModelMap model) { model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); model.addAttribute("nunmberOfFailedPostAttempts", - Context.getService(DHISConnectorService.class).getNumberOfFailedDataPosts()); + Context.getService(DHISConnectorService.class).getNumberOfFailedDataPosts()); } - + @RequestMapping(value = "/module/dhisconnector/failedData", method = RequestMethod.POST) public void failedData(ModelMap model, HttpServletRequest request) { // TODO be specific which post went well and if any failed which one Context.getService(DHISConnectorService.class).postPreviouslyFailedData(); model.addAttribute("nunmberOfFailedPostAttempts", - Context.getService(DHISConnectorService.class).getNumberOfFailedDataPosts()); + Context.getService(DHISConnectorService.class).getNumberOfFailedDataPosts()); request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Completed successfully!"); } - + @RequestMapping(value = "/module/dhisconnector/automation", method = RequestMethod.GET) public void renderAutomationPage(ModelMap model) { initialiseAutomation(model, new Configurations().automationEnabled(), new ArrayList()); } - + private void initialiseAutomation(ModelMap model, boolean automationEnabled, List postResponse) { List orgUnits = Context.getService(DHISConnectorService.class).getDHISOrgUnits(); - + model.addAttribute("mappings", Context.getService(DHISConnectorService.class).getMappings()); model.addAttribute("locations", Context.getLocationService().getAllLocations(false)); model.addAttribute("orgUnits", orgUnits); model.addAttribute("reportToDataSetMappings", - Context.getService(DHISConnectorService.class).getAllReportToDataSetMappings()); + Context.getService(DHISConnectorService.class).getAllReportToDataSetMappings()); model.addAttribute("orgUnitsByIds", getOrgUnitsByName(orgUnits)); model.addAttribute("automationEnabled", automationEnabled); model.addAttribute("postResponse", postResponse); model.addAttribute("showLogin", (Context.getAuthenticatedUser() == null) ? true : false); } - + @SuppressWarnings("unchecked") private JSONObject getOrgUnitsByName(List orgUnits) { JSONObject json = new JSONObject(); - + if (orgUnits != null) { for (DHISOrganisationUnit o : orgUnits) { json.put(o.getId(), o.getName()); } } - + return json; } - + @RequestMapping(value = "/module/dhisconnector/automation", method = RequestMethod.POST) public void postAutomationPage(ModelMap model, HttpServletRequest request) { String response = ""; String mapping = request.getParameter("mapping"); String orgUnitUId = request.getParameter("orgUnit"); String locationUuid = request.getParameter("location"); + String isFullMapping = request.getParameter("isFullMapping"); Configurations configs = new Configurations(); List postResponse = new ArrayList(); List toBeRan = new ArrayList(); - + if (request.getParameter("toogleAutomation") != null) configs.toogleAutomation(true); else configs.toogleAutomation(false); - + if (request.getParameterValues("mappingIds") != null) { for (String s : request.getParameterValues("mappingIds")) { Context.getService(DHISConnectorService.class).deleteReportToDataSetMapping(Integer.parseInt(s)); } response += " -> Delete was successful"; } - + if (request.getParameterValues("reRuns") != null) { for (String s : request.getParameterValues("reRuns")) { ReportToDataSetMapping r2d = Context.getService(DHISConnectorService.class) - .getReportToDataSetMappingByUuid(s); - + .getReportToDataSetMappingByUuid(s); + if (r2d != null) { toBeRan.add(s); r2d.setLastRun(null); @@ -416,21 +458,21 @@ public void postAutomationPage(ModelMap model, HttpServletRequest request) { } } } - + if (request.getParameterValues("runs") != null) { for (String s : request.getParameterValues("runs")) { if (!toBeRan.contains(s)) toBeRan.add(s); } } - + if (toBeRan.size() > 0) { for (String s : toBeRan) { ReportToDataSetMapping r2d = Context.getService(DHISConnectorService.class) - .getReportToDataSetMappingByUuid(s); - + .getReportToDataSetMappingByUuid(s); + if (r2d != null) { - Object resp = Context.getService(DHISConnectorService.class).runAndPushReportToDHIS(r2d); + Object resp = Context.getService(DHISConnectorService.class).runReportsAndPostToDHIS(Arrays.asList(r2d)); if (resp != null) postResponse.add(resp.toString()); } @@ -438,14 +480,14 @@ public void postAutomationPage(ModelMap model, HttpServletRequest request) { } if (postResponse.size() > 0) response += " -> Run was successful"; - - if (StringUtils.isNotBlank(mapping) && StringUtils.isNotBlank(orgUnitUId) - && StringUtils.isNotBlank(locationUuid)) { - Context.getService(DHISConnectorService.class).saveReportToDataSetMapping(new ReportToDataSetMapping( - mapping, Context.getLocationService().getLocationByUuid(locationUuid), orgUnitUId)); + + if (StringUtils.isNotBlank(mapping) && StringUtils.isNotBlank(orgUnitUId) && StringUtils.isNotBlank(locationUuid)) { + Context.getService(DHISConnectorService.class).saveReportToDataSetMapping( + new ReportToDataSetMapping(mapping, Context.getLocationService().getLocationByUuid(locationUuid), orgUnitUId, + StringUtils.isNotBlank(isFullMapping) ? "Y" : "N")); response += " -> Save was successful"; } - + initialiseAutomation(model, configs.automationEnabled(), postResponse); if (StringUtils.isNotBlank(response)) request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, response); diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorRestController.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorRestController.java index 02cc07b..3e9e505 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorRestController.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/controller/DHISConnectorRestController.java @@ -19,9 +19,9 @@ @Controller @RequestMapping("/rest/" + RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE) public class DHISConnectorRestController extends MainResourceController { - + public static final String DHISCONNECTOR_NAMESPACE = "/dhisconnector"; - + /** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController#getNamespace() */ diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISCategoryCombosResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISCategoryCombosResource.java index e53b663..b10629f 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISCategoryCombosResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISCategoryCombosResource.java @@ -28,7 +28,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/dhiscategorycombos", supportedClass = DHISCategoryCombo.class, supportedOpenmrsVersions = { "1.8.*", - "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" ,"2.1.*"}) public class DHISCategoryCombosResource extends DataDelegatingCrudResource implements Retrievable { public static final String CATEGORYCOMBOS_PATH = "/api/categoryCombos"; diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataElementsResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataElementsResource.java index 4af3f06..951d3fb 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataElementsResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataElementsResource.java @@ -29,7 +29,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/dhisdataelements", supportedClass = DHISDataElement.class, supportedOpenmrsVersions = { "1.8.*", - "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" ,"2.1.*"}) public class DHISDataElementsResource extends DataDelegatingCrudResource implements Retrievable { public static final String DATAELEMENTS_PATH = "/api/dataElements"; diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetElementResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetElementResource.java index b0fdb63..6dadba9 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetElementResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetElementResource.java @@ -18,7 +18,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/dhisdatasetelements", supportedClass = DHISDataSetElement.class, supportedOpenmrsVersions = { "1.8.*", - "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" ,"2.1.*"}) public class DHISDataSetElementResource extends DataDelegatingCrudResource implements Retrievable { public static final String DATASETELEMENTS_PATH = "/api/dataSetElements"; diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetsResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetsResource.java index fa31290..2fef955 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetsResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataSetsResource.java @@ -36,7 +36,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/dhisdatasets", supportedClass = DHISDataSet.class, supportedOpenmrsVersions = { "1.8.*", "1.9.*, 1.10.*, 1.11.*", - "1.12.*", "2.0.*" }) + "1.12.*", "2.0.*" ,"2.1.*"}) public class DHISDataSetsResource extends DataDelegatingCrudResource implements Retrievable { public static final String DATASETS_PATH = "/api/dataSets"; diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataValueSetsResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataValueSetsResource.java index c4caf9b..39903a1 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataValueSetsResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISDataValueSetsResource.java @@ -35,7 +35,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/dhisdatavaluesets", supportedClass = DHISDataValueSet.class, supportedOpenmrsVersions = { "1.8.*", - "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" ,"2.1.*"}) public class DHISDataValueSetsResource extends DataDelegatingCrudResource implements Retrievable { @Override diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISOrganisationUnitResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISOrganisationUnitResource.java index 2e4b252..58eff71 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISOrganisationUnitResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/DHISOrganisationUnitResource.java @@ -30,7 +30,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/orgunits", supportedClass = DHISOrganisationUnit.class, supportedOpenmrsVersions = { "1.8.*", - "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" ,"2.1.*"}) public class DHISOrganisationUnitResource extends DataDelegatingCrudResource implements Retrievable { protected NeedsPaging doGetAll(RequestContext context) { diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/MappingResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/MappingResource.java index 6134831..0c04ff6 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/MappingResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/MappingResource.java @@ -36,7 +36,7 @@ @SuppressWarnings({ "unchecked", "rawtypes" }) @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/mappings", supportedClass = DHISMapping.class, supportedOpenmrsVersions = { "1.8.*", - "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*","2.1.*" }) public class MappingResource extends DataDelegatingCrudResource implements Retrievable { @Override diff --git a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/PeriodIndicatorReportsResource.java b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/PeriodIndicatorReportsResource.java index c930ea8..b15e02c 100644 --- a/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/PeriodIndicatorReportsResource.java +++ b/omod/src/main/java/org/openmrs/module/dhisconnector/web/resource/PeriodIndicatorReportsResource.java @@ -33,7 +33,7 @@ @Resource(name = RestConstants.VERSION_1 + DHISConnectorRestController.DHISCONNECTOR_NAMESPACE + "/periodindicatorreports", supportedClass = PeriodIndicatorReportDefinition.class, supportedOpenmrsVersions = { - "1.8.*", "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" }) + "1.8.*", "1.9.*, 1.10.*, 1.11.*", "1.12.*", "2.0.*" ,"2.1.*" }) public class PeriodIndicatorReportsResource extends DataDelegatingCrudResource implements Retrievable { @Override diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 5cf88d4..75fa039 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -60,6 +60,13 @@ DHIS Password. + + ${project.parent.artifactId}.fullmappingvalues + 1=2 + + key1=value1,key2=value2 mapping between locations and OrgUnits + + dhisconnector.config.dxfToAdxSwitch false diff --git a/omod/src/main/webapp/automation.jsp b/omod/src/main/webapp/automation.jsp index df972a4..30304a7 100644 --- a/omod/src/main/webapp/automation.jsp +++ b/omod/src/main/webapp/automation.jsp @@ -1,6 +1,12 @@ <%@ include file="/WEB-INF/template/include.jsp" %> <%@ include file="/WEB-INF/template/header.jsp" %> + + + + + + <%@ include file="template/localHeader.jsp" %> @@ -21,6 +27,7 @@ Otherwise you may trigger a re-run which is likewise contextual Delete Run Mapping + Use Custom Location Mapping OpenMRS Location DHIS2 Organization Unit Re/Last Run @@ -38,6 +45,7 @@ Otherwise you may trigger a re-run which is likewise contextual + ${fn:substringBefore(mpg.mapping, '.')} - ${mpg.location.name} - ${orgUnitsByIds[mpg.orgUnitUid]} + ${mpg.isFullMapping == 'Y' ? 'Yes' : 'No' } + ${mpg.isFullMapping == 'Y' ? '' : mpg.location.name} + ${mpg.isFullMapping == 'Y' ? '' : orgUnitsByIds[mpg.orgUnitUid]} ${mpg.lastRun} diff --git a/omod/src/main/webapp/fullMapping.jsp b/omod/src/main/webapp/fullMapping.jsp new file mode 100644 index 0000000..2c89032 --- /dev/null +++ b/omod/src/main/webapp/fullMapping.jsp @@ -0,0 +1,84 @@ +<%@ include file="/WEB-INF/template/include.jsp"%> +<%@ include file="/WEB-INF/template/header.jsp"%> + + + + + +<%@ include file="template/localHeader.jsp"%> + + + + + +

+ +

+
+ +
+
+
${failureWhileUploading}
+
+
${successWhileUploading}
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
OpenMRS LocationDHIS2 Organization Unit
+ +
+ +<%@ include file="/WEB-INF/template/footer.jsp"%> +<%@ include file="jembiOpenMRSFooter.jsp"%> \ No newline at end of file diff --git a/omod/src/main/webapp/resources/dhisconnector.js b/omod/src/main/webapp/resources/dhisconnector.js index 54e3b5a..01ca802 100644 --- a/omod/src/main/webapp/resources/dhisconnector.js +++ b/omod/src/main/webapp/resources/dhisconnector.js @@ -79,6 +79,18 @@ function getCategoryComboOptions(dataElementId, requests) { return def; } +function getFullMappingValues(){ + var fullMappingValues = ""; + jQuery("select[name^='location_']").each(function() { + console.log( this.value + ":" + this.checked ); + if(jQuery("[name='orgUnit_"+this.value+"']").val() != "") { + fullMappingValues += this.value + "=" + jQuery("[name='orgUnit_"+this.value+"']").val() + ","; + } + }); + fullMappingValues = fullMappingValues.replace(/,\s*$/, ""); + jQuery("input[name='fullMappingValues']").val( fullMappingValues ); +} + function getDataElementsAndCategoryComboOptions() { var def = jQuery.Deferred(); var requests = []; @@ -530,6 +542,26 @@ function autoScrollWhenDraggingToHeaderOrFooter(currentMouseTopPos) { } jQuery(function () {//self invoked only if the whole page has completely loaded + + jQuery('#idFullMapping').change(function() { + + if( this.checked ) { + var test = jQuery("[name='location'] option:last").val(); + jQuery("[name='location']").val( jQuery("[name='location'] option:last").val() ); + jQuery("[name='orgUnit']").val( jQuery("[name='orgUnit'] option:last").val() ); + jQuery("[name='location']").hide(); + jQuery("[name='orgUnit']").hide(); + } else { + + jQuery("[name='location']").val( '' ); + jQuery("[name='orgUnit']").val( '' ); + jQuery("[name='location']").show(); + jQuery("[name='orgUnit']").show(); + //'unchecked' event code + } + + }); + if (window.location.pathname.indexOf("createMapping.form") !== -1) {//loaded only at createMapping page //TODO this code block takes long time while loading, speed it up @@ -593,3 +625,5 @@ jQuery(function () {//self invoked only if the whole page has completely loaded } }); + + diff --git a/omod/src/main/webapp/template/localHeader.jsp b/omod/src/main/webapp/template/localHeader.jsp index 91919e2..ec8dd83 100644 --- a/omod/src/main/webapp/template/localHeader.jsp +++ b/omod/src/main/webapp/template/localHeader.jsp @@ -38,6 +38,12 @@ href="${pageContext.request.contextPath}/module/dhisconnector/uploadMapping.form"> +
  • class="active"> + +
  • class="active">