Guest User

Untitled

a guest
May 4th, 2013
69
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. /**********
  7. This script is to set the boolean DM2
  8. 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.
  9. ********/
  10.  
  11. import org.openmrs.api.context.Context
  12. import org.openmrs.api.EncounterService;
  13. import org.openmrs.module.groovy.GroovyUtil
  14. import org.openmrs.Encounter;
  15. import org.openmrs.EncounterType;
  16. import org.openmrs.Person;
  17. import org.openmrs.Obs;
  18. import org.openmrs.Concept;
  19. import org.hibernate.SessionFactory;
  20. import org.openmrs.api.FormService;
  21. import org.openmrs.api.ObsService;
  22.  
  23. //import groovy.sql.Sql;
  24. sf = Context.serviceContext.applicationContext.getBean(SessionFactory.class)
  25.  
  26. // Easy SQL calls
  27. def sql(s) { admin.executeSQL(s,false) }
  28.  
  29. EncounterService es = Context.getEncounterService()
  30. FormService fs = Context.getFormService()
  31. ObsService os = Context.getObsService()
  32.  
  33. def c = new Concept(1272) //diagnostico DM2
  34. def trueCon = new Concept(1) //diagnostico DM2
  35.  
  36.  
  37. //get patient_id and encounter_id for patients with diagnostico not null and DM2 null
  38. rs = sql("""
  39. select distinct(e.patient_id), e.encounter_id from encounter e, obs diag, obs dm2
  40. where e.voided = 0
  41. and diag.person_id = e.patient_id and diag.concept_id = 1272 and diag.voided = 0 limit 5
  42. """)
  43.  
  44. rs.each { row ->
  45. (pid,enc_id) = row
  46. person = new Person(pid)
  47. def today = Calendar.instance.getTime()
  48. // def e = new Encounter(enc_id)
  49. def obs1 = new Obs()
  50. obs1.setPerson(person);
  51. obs1.setConcept(c);
  52. obs1.setObsDatetime(today);
  53. // obs1.setEncounter(e);
  54. // obs1.setValueCoded(trueCon);
  55. obs1.setValueText("test");
  56. os.saveObs(obs1,null);
  57. print obs1
  58. }
  59.  
  60. ​
Advertisement
Add Comment
Please, Sign In to add comment