Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********
- This script is to set the boolean DM2
- 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.
- ********/
- import org.openmrs.api.context.Context
- import org.openmrs.api.EncounterService;
- import org.openmrs.module.groovy.GroovyUtil
- import org.openmrs.Encounter;
- import org.openmrs.EncounterType;
- import org.openmrs.EncounterRole;
- import org.openmrs.Provider;
- import org.openmrs.Person;
- import org.openmrs.Obs;
- import org.openmrs.Concept;
- import org.hibernate.SessionFactory;
- import org.openmrs.api.FormService;
- import org.openmrs.api.ObsService;
- //import groovy.sql.Sql;
- sf = Context.serviceContext.applicationContext.getBean(SessionFactory.class)
- // Easy SQL calls
- def sql(s) { admin.executeSQL(s,false) }
- EncounterService es = Context.getEncounterService()
- FormService fs = Context.getFormService()
- ObsService os = Context.getObsService()
- def c = new Concept(46) //diagnostico DM2
- def trueCon = new Concept(1) //diagnostico DM2
- //get patient_id and encounter_id for patients with diagnostico not null and DM2 null
- rs = sql("""
- select distinct(e.patient_id), e.encounter_id from encounter e, obs diag, obs dm2
- where e.form_id = 1 and e.voided = 0
- and diag.person_id = e.patient_id and diag.concept_id = 155 and diag.value_text is not null and diag.voided = 0
- and e.patient_id not in (select person_id from obs where concept_id = 46 and voided = 0)
- """)
- rs.each { row ->
- (pid,enc_id) = row
- person = new Person(pid)
- def today = Calendar.instance.getTime()
- // def e = new Encounter(enc_id)
- def obs1 = new Obs()
- obs1.setPerson(person);
- obs1.setConcept(c);
- // obs1.setEncounter(e);
- // obs1.setValueCoded(trueCon);
- obs1.setValueText("test");
- os.saveObs(obs1,null);
- print obs
- }
Advertisement
Add Comment
Please, Sign In to add comment