Example #1
0
def ObservationRead(client, ObsId):
    print("read")
    struct = {
        '_id':ObsId
        }
    search = S.FHIRSearch(O.Observation, struct)
    return search.perform(client.server).entry[0].resource
Example #2
0
def PatientSearch(client, struct=None):
    search = S.FHIRSearch(P.Patient, struct)
    patient = search.perform_resources(client.server)
    #print(len(patient))
    if len(patient) != 1:
        print(False)
        return False
    return patient[0].id
    def find(self,
             search_params=None,
             first=False,
             batch_size=20,
             page=1,
             debug=False):
        """ Perform search for specific resource.

        search_params dict: searh parameters other than _count and _offset in dictionary
        first bool: returns one resource or a list of resrouces
        batch_size int: number of resources in the list
        page int: number of page of the result if there are more than one page
        """
        struct = {
            "_count": str(batch_size),
            "_offset": str(batch_size * (page - 1))
        }
        if search_params:
            for key, val in search_params.items():
                struct[key] = val

        search = fhirsearch.FHIRSearch(self, struct)
        if debug:
            print("{} has resource type '{}', search query: {} ".format(
                self.__class__, self.resource_type, search.construct()))

        if self._server is None:
            raise Exception("Cannot read resource without server instance")

        bundle = search.perform(self._server)

        if first:
            try:
                resource = bundle.entry[0].resource
                resource._server = self._server
            except:
                resource = None
            return resource
        else:
            result = SearchResult(bundle.as_json())
            struct.pop("_offset")
            result.total = fhirsearch.FHIRSearch(self, struct).perform(
                self._server).total
            result._server = self._server
            return result
Example #4
0
def PatientSearch(struct=None):
    servers = getListBucket("servers.txt")
##    'http://test.fhir.org/r4',
##    'https://r4.test.pyrohealth.net/fhir',
##    'http://hapi.fhir.org/baseR4',
##    
##    'http://wildfhir4.aegis.net/fhir4-0-0',
##    'http://www.pknapp.com:8081/con19',
##    'http://fhir.tukan.online/',
##    'http://sandbox.bluebutton.cms.gov',
##    'http://elsevier.demo.elsevierfhir.com/fhir/metadata',
##
##        #below have val errors but type:AuditEvent in their capability statements
##
##    'https://fhir.careevolution.com/Master.Adapter1.WebClient/api/fhir-r4', 
##    'http://sqlonfhir-r4.azurewebsites.net/fhir', 
##    'https://vhdir-demo.fhir.org/fhir', 
##        ]
    returnJson = {}
    for server in servers:
        returnJson[server] = {}
        try:
            smart = client.FHIRClient(settings={'app_id':'audit_app','api_base':server})
            if CheckServer(smart):
                
                search = S.FHIRSearch(P.Patient, struct)
                patList = search.perform_resources(smart.server)
                #I acknowledge that if the search comes back with more than one bundle of patients this won't catch them all, but I hope that never happens
                for pat in patList:
                    returnJson[server][pat.id] = {}
            else:
                returnJson[server] = "Does not implement AuditEvents"
        except HTTPError as e:
            returnJson[server]["http error"] = str(e.response.status_code)
        except FHIRValidationError as e:
            returnJson[server]["Validation error"] = e.errors
##        except FHIRServer.FHIRUnauthorizedException as e:
##            returnJson[server]["http error"] = e.response.status_code
##        except FHIRServer.FHIRPermissionDeniedException:
##            returnJson[server]["http error"] = e.response.status_code
##        except FHIRServer.FHIRNotFoundException:
##            returnJson[server]["http error"] = str(e.response.status_code)
        
    return returnJson   #dict form of {server:{patient:{}}}
Example #5
0
def ObservationsSearch(client, struct=None):
    search = S.FHIRSearch(O.Observation, struct)
    return search.perform(client.server)
Example #6
0
def AuditSearch(client, struct=None):
    audit = AE.AuditEvent()
    search = S.FHIRSearch(audit, struct)
    bundle = search.perform(client.server)
    return bundle
Example #7
0
def AuditSearch(pat, server):
    smart = client.FHIRClient(settings={'app_id':'audit_app','api_base':server})
    search = S.FHIRSearch(AE.AuditEvent, {'patient':pat}) #?
    bundle = search.perform(smart.server)
    return bundle