Advertisement
Guest User

Untitled

a guest
Dec 14th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. package org.openmrs.module.amrsreport.rule.collection;
  2.  
  3. import org.apache.commons.logging.Log;
  4. import org.apache.commons.logging.LogFactory;
  5. import org.openmrs.Patient;
  6. import org.openmrs.PatientIdentifier;
  7. import org.openmrs.PatientIdentifierType;
  8. import org.openmrs.api.context.Context;
  9. import org.openmrs.logic.LogicContext;
  10. import org.openmrs.logic.LogicException;
  11. import org.openmrs.logic.result.Result;
  12. import org.openmrs.logic.result.Result.Datatype;
  13. import org.openmrs.logic.rule.RuleParameterInfo;
  14. import org.openmrs.module.amrsreport.cache.MohCacheUtils;
  15. import org.openmrs.module.amrsreport.rule.MohEvaluableRule;
  16. import org.openmrs.util.OpenmrsUtil;
  17.  
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Set;
  21.  
  22.  
  23. /**
  24. * MohUniquePatientNumberRule class checks and returns CCC Number for a patient
  25. */
  26. public class MohUniquePatientNumberRule extends MohEvaluableRule {
  27.  
  28. private static final Log log = LogFactory.getLog(MohUniquePatientNumberRule.class);
  29.  
  30. public static final String TOKEN = "MOH Unique Patient Number";
  31.  
  32. public static final PatientIdentifierType cccPatientIdentifierType = MohCacheUtils.getPatientIdentifierType(Context.getAdministrationService().getGlobalProperty("cccgenerator.CCC"));
  33.  
  34. /**
  35. * @should return a Unique Patient Number
  36. * @see org.openmrs.logic.Rule#eval(org.openmrs.logic.LogicContext, org.openmrs.Patient,
  37. * java.util.Map)
  38. */
  39. public Result evaluate(LogicContext context, Integer patientId, Map<String, Object> parameters) throws LogicException {
  40. Patient patient = Context.getPatientService().getPatient(patientId);
  41. List<PatientIdentifier> mflIdentifiers = patient.getPatientIdentifiers(cccPatientIdentifierType);
  42. PatientIdentifier mflIdentifier = patient.getPatientIdentifier(cccPatientIdentifierType);
  43.  
  44. PatientIdentifierType pit = MohCacheUtils.getPatientIdentifierType(Context.getAdministrationService().getGlobalProperty("cccgenerator.CCC"));
  45.  
  46. List<PatientIdentifier> mflId = patient.getActiveIdentifiers();
  47.  
  48. String res="";
  49.  
  50. for (PatientIdentifier pid : mflId) {
  51. res+=pid.toString();
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. //Integer sizeofId = mflIdentifiers.size();
  60. /*if (mflIdentifiers.isEmpty()) {
  61. log.error("CCC Number not found for patient " + patientId);
  62. return new Result("not found");
  63. }
  64.  
  65. if (mflIdentifiers.size() > 1) {
  66. log.error("Multiple CCC Numbers found for patient " + patientId);
  67. return new Result("More than one CCC Number exist for the patient");
  68. }
  69.  
  70.  
  71. Result result = new Result();
  72. for (PatientIdentifier identifier : mflIdentifiers) {
  73. result.add(new Result(identifier.getIdentifier()));
  74. }
  75. return new Result();*/
  76. return new Result(cccPatientIdentifierType.toString());
  77. }
  78.  
  79. protected String getEvaluableToken() {
  80. return TOKEN;
  81. }
  82.  
  83. /**
  84. * @see org.openmrs.logic.Rule#getDependencies()
  85. */
  86. @Override
  87. public String[] getDependencies() {
  88. return new String[]{};
  89. }
  90.  
  91. /**
  92. * Get the definition of each parameter that should be passed to this rule execution
  93. *
  94. * @return all parameter that applicable for each rule execution
  95. */
  96.  
  97. @Override
  98. public Datatype getDefaultDatatype() {
  99. return Datatype.TEXT;
  100. }
  101.  
  102. public Set<RuleParameterInfo> getParameterList() {
  103. return null;
  104. }
  105.  
  106. @Override
  107. public int getTTL() {
  108. return 0;
  109. }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement