Guest User

Untitled

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