Skip to content
Snippets Groups Projects
Select Git revision
  • issue-703
  • master default
  • issue-752
  • develop
  • issue-677
  • issue-677-original-with-migrate
  • issue-716
  • issue-654
  • issue-732
  • issue-737
  • issue-735
  • issue-707
  • issue-706
  • issue-705
  • issue-696
  • issue-690
  • issue-675
  • issue-670
  • issue-635
  • issue-404
  • 7.19
  • 2012-04-18
  • 2012-04-03
  • 2012-04-02
  • 2012-03-01
  • 2012-02-07
  • 20120207
  • 2012-01-13
  • 2012-01-12
  • 2011-12-16
  • 2011-12-05
  • 2011-11-17
  • 2011-11-14
  • 2011-11-08.2
  • 2011-11-08
  • 2011-11-01
  • 2011-10-27
  • 2011-10-06
  • 2011-10-03
  • 2011-09-19
40 results

menu.inc

Blame
  • Forked from UNL Information Services / UNL-CMS
    Source project has a limited visibility.
    main.py 2.58 KiB
    from kivy.app import App
    from kivy.logger import Logger
    
    from openmrs import RESTConnection, RESTCommunication
    
    
    class RestApp(App):
        def __init__(self, **kwargs):
            super(RestApp, self).__init__(**kwargs)
            self.openmrs_connection = RESTConnection('localhost', 8080, 'admin', 'Admin123')
    
        def create_lincoln_hospital(self):
            self.openmrs_connection.send_request('location', {
                'q': 'Lincoln Hospital',
            }, None, self.on_lincoln_hospital_queried, self.on_failure, self.on_failure)
    
        def on_lincoln_hospital_queried(self, _, response):
            matches = [result for result in response['results'] if result['display'] == 'Lincoln Hospital']
            if len(matches) > 0:
                print(f'Location "Lincoln Hospital" already exists: {matches[0]["uuid"]}')
            else:
                self.openmrs_connection.send_request('location', None, {
                    'name': 'Lincoln Hospital'
                }, self.on_lincoln_hospital_created, self.on_failure, self.on_failure)
    
        # noinspection PyMethodMayBeStatic
        def on_lincoln_hospital_created(self, _, response):  # pylint: disable=no-self-use
            print(f'Location "Lincoln Hospital" created: {response["uuid"]}')
    
        def create_health_concept(self):
            def coroutine(communication):
                datatypes = yield from communication.get_uuids('conceptdatatype')
                classes = yield from communication.get_uuids('conceptclass')
                concepts = yield from communication.get_uuids('concept')
                try:
                    numeric = datatypes['Numeric']
                    finding = classes['Finding']
                except KeyError as exception:
                    communication.on_failure(None, exception)
                    return
                health_concept_uuid = concepts.get('Health')
                if health_concept_uuid is None:
                    health_concept = yield from communication.send_request('concept', post_parameters={
                        'names': [{'name': 'Health', 'locale': 'en'}],
                        'datatype': numeric,
                        'conceptClass': finding,
                    })
                    health_concept_uuid = health_concept['uuid']
                    print(f'Concept "Health" created: {health_concept_uuid}')
                else:
                    print(f'Concept "Health" already exists: {health_concept_uuid}')
            RESTCommunication(coroutine, self.openmrs_connection, self.on_failure).run()
    
        # noinspection PyMethodMayBeStatic
        def on_failure(self, _, error):  # pylint: disable=no-self-use
            Logger.error(f'RestApp: {error}')
    
    
    if __name__ == '__main__':
        app = RestApp()
        app.run()