Guest User

Untitled

a guest
May 4th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. /**********
  6. This script is to set the boolean DM2
  7. It should check to see if the patient has a diagnostico DM2 and if not null put DM2 to be true. I didn't do just those with an hour preference because we should have all of them.
  8. ********/
  9.  
  10. import org.openmrs.api.context.Context
  11. import org.openmrs.api.EncounterService;
  12. import org.openmrs.module.groovy.GroovyUtil
  13. import org.openmrs.Encounter;
  14. import org.openmrs.EncounterType;
  15. import org.openmrs.Person;
  16. import org.openmrs.Obs;
  17. import org.openmrs.Concept;
  18. import org.hibernate.SessionFactory;
  19. import org.openmrs.api.FormService;
  20. import org.openmrs.api.ObsService;
  21.  
  22. //import groovy.sql.Sql;
  23. sf = Context.serviceContext.applicationContext.getBean(SessionFactory.class)
  24.  
  25. // Easy SQL calls
  26. def sql(s) { admin.executeSQL(s,false) }
  27.  
  28. EncounterService es = Context.getEncounterService()
  29. FormService fs = Context.getFormService()
  30. ObsService os = Context.getObsService()
  31.  
  32. def c = new Concept(1272) //diagnostico DM2
  33. def trueCon = new Concept(1) //diagnostico DM2
  34.  
  35.  
  36. //get patient_id and encounter_id for patients with diagnostico not null and DM2 null
  37. rs = sql("""
  38. select distinct(e.patient_id), e.encounter_id from encounter e, obs diag, obs dm2
  39. where e.voided = 0
  40. and diag.person_id = e.patient_id and diag.concept_id = 1272 and diag.voided = 0 limit 5
  41. """)
  42.  
  43. rs.each { row ->
  44. (pid,enc_id) = row
  45. person = new Person(pid)
  46. def today = Calendar.instance.getTime()
  47. // def e = new Encounter(enc_id)
  48. def obs1 = new Obs()
  49. obs1.setPerson(person);
  50. obs1.setConcept(c);
  51. obs1.setObsDatetime(today);
  52. // obs1.setEncounter(e);
  53. // obs1.setValueCoded(trueCon);
  54. obs1.setValueText("test");
  55. os.saveObs(obs1,null);
  56. print obs1
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment