Skip to content

Instantly share code, notes, and snippets.

@sgithens
Created January 10, 2014 18:57
Show Gist options
  • Save sgithens/8360367 to your computer and use it in GitHub Desktop.
Save sgithens/8360367 to your computer and use it in GitHub Desktop.
import java
from org.openmrs.util import OpenmrsUtil
from org.openmrs.api.context import Context
props = java.util.Properties()
OpenmrsUtil.loadProperties(props,java.io.File('/home/sgithens/.OpenMRS/openmrs-runtime.properties'))
Context.startup('jdbc:mysql://localhost:3306/openmrs_hl7?autoReconnect=true&sessionVariables=storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8','openmrs_hl7_user','***********',props)
sgithens@sgithens-ThinkPad-X230:~/code/iedea$
: jython27b1/jython -J-cp 'openmrs-core/webapp/target/openmrs/WEB-INF/lib/*:/home/sgithens/.m2/repository/org/apache/tomcat/servlet-api/6.0.32/*:/home/sgithens/.m2/repository/org/mortbay/jetty/jsp-api-2.1/6.1.10/*:/home/sgithens/.m2/repository/org/mortbay/jetty/jsp-2.1/6.1.10/*' -i openmrs-repl.py
>>> Context.openSession()
>>> Context.authenticate("admin","*******")
>>> p = Context.getPatientService().getAllPatients()
>>> p
[Patient#2, Patient#3]
>>> [i.gender for i in p]
[u'M', u'M']
>>> [i.givenName for i in p if i.gender == 'M']
[u'Horatio', u'John']
>>> [i.givenName for i in p if i.gender == 'F']
[]
>>> dir(p[0])
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'activeAttributes', 'activeIdentifiers', 'addAddress', 'addAttribute', 'addIdentifier', 'addIdentifiers', 'addName', 'addresses', 'age', 'attributeMap', 'attributes', 'birthdate', 'birthdateEstimated', 'causeOfDeath', 'changedBy', 'class', 'creator', 'dateChanged', 'dateCreated', 'dateVoided', 'dead', 'deathDate', 'equals', 'familyName', 'gender', 'getActiveAttributes', 'getActiveIdentifiers', 'getAddresses', 'getAge', 'getAttribute', 'getAttributeMap', 'getAttributes', 'getBirthdate', 'getBirthdateEstimated', 'getCauseOfDeath', 'getChangedBy', 'getClass', 'getCreator', 'getDateChanged', 'getDateCreated', 'getDateVoided', 'getDead', 'getDeathDate', 'getFamilyName', 'getGender', 'getGivenName', 'getId', 'getIdentifiers', 'getMiddleName', 'getNames', 'getPatientId', 'getPatientIdentifier', 'getPatientIdentifiers', 'getPersonAddress', 'getPersonChangedBy', 'getPersonCreator', 'getPersonDateChanged', 'getPersonDateCreated', 'getPersonDateVoided', 'getPersonId', 'getPersonName', 'getPersonVoidReason', 'getPersonVoided', 'getPersonVoidedBy', 'getTribe', 'getUuid', 'getVoidReason', 'getVoided', 'getVoidedBy', 'givenName', 'hashCode', 'id', 'identifiers', 'isBirthdateEstimated', 'isDead', 'isPatient', 'isPersonVoided', 'isUser', 'isVoided', 'middleName', 'names', 'notify', 'notifyAll', 'patient', 'patientId', 'patientIdentifier', 'personAddress', 'personChangedBy', 'personCreator', 'personDateChanged', 'personDateCreated', 'personDateVoided', 'personId', 'personName', 'personVoidReason', 'personVoided', 'personVoidedBy', 'printAttributes', 'removeAddress', 'removeAttribute', 'removeIdentifier', 'removeName', 'replaceSerialization', 'serialVersionUID', 'setAddresses', 'setAttributes', 'setBirthdate', 'setBirthdateEstimated', 'setBirthdateFromAge', 'setCauseOfDeath', 'setChangedBy', 'setCreator', 'setDateChanged', 'setDateCreated', 'setDateVoided', 'setDead', 'setDeathDate', 'setGender', 'setId', 'setIdentifiers', 'setNames', 'setPatientId', 'setPersonChangedBy', 'setPersonCreator', 'setPersonDateChanged', 'setPersonDateCreated', 'setPersonDateVoided', 'setPersonId', 'setPersonVoidReason', 'setPersonVoided', 'setPersonVoidedBy', 'setTribe', 'setUuid', 'setVoidReason', 'setVoided', 'setVoidedBy', 'toString', 'tribe', 'user', 'uuid', 'voidReason', 'voided', 'voidedBy', 'wait']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment