<s> from . import fhirabstractbase <EOL> class FHIRAbstractResource ( fhirabstractbase . FHIRAbstractBase ) : <EOL> """<STR_LIT>""" <EOL> resource_name = '<STR_LIT>' <EOL> def __init__ ( self , jsondict = None ) : <EOL> self . _server = None <EOL> """<STR_LIT>""" <EOL> super ( FHIRAbstractResource , self ) . __init__ ( jsondict ) <EOL> @ classmethod <EOL> def _with_json_dict ( cls , jsondict ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( jsondict , dict ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> . format ( jsondict ) ) <EOL> res_type = jsondict . get ( '<STR_LIT>' ) <EOL> if res_type and res_type != cls . resource_name : <EOL> return fhirelementfactory . FHIRElementFactory . instantiate ( res_type , jsondict ) <EOL> return super ( FHIRAbstractResource , cls ) . _with_json_dict ( jsondict ) <EOL> def as_json ( self ) : <EOL> js = super ( FHIRAbstractResource , self ) . as_json ( ) <EOL> js [ '<STR_LIT>' ] = self . resource_name <EOL> return js <EOL> def relativeBase ( self ) : <EOL> return self . __class__ . resource_name <EOL> def relativePath ( self ) : <EOL> return "<STR_LIT>" . format ( self . relativeBase ( ) , self . id ) <EOL> @ property <EOL> def server ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _server is None : <EOL> owningRes = self . owningResource ( ) <EOL> self . _server = owningRes . server if owningRes is not None else None <EOL> return self . _server <EOL> @ classmethod <EOL> def read ( cls , rem_id , server ) : <EOL> """<STR_LIT>""" <EOL> if not rem_id : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> path = '<STR_LIT>' . format ( cls . resource_name , rem_id ) <EOL> instance = cls . read_from ( path , server ) <EOL> instance . _local_id = rem_id <EOL> return instance <EOL> @ classmethod <EOL> def read_from ( cls , path , server ) : <EOL> """<STR_LIT>""" <EOL> if not path : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if server is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ret = server . request_json ( path ) <EOL> instance = cls ( jsondict = ret ) <EOL> instance . _server = server <EOL> return instance <EOL> def create ( self , server ) : <EOL> """<STR_LIT>""" <EOL> srv = server or self . server <EOL> if srv is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . id : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ret = srv . post_json ( self . relativePath ( ) , self . as_json ( ) ) <EOL> if len ( ret . text ) > <NUM_LIT:0> : <EOL> return ret . json ( ) <EOL> return None <EOL> def update ( self , server = None ) : <EOL> """<STR_LIT>""" <EOL> srv = server or self . server <EOL> if srv is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if not self . id : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ret = srv . put_json ( self . relativePath ( ) , self . as_json ( ) ) <EOL> if len ( ret . text ) > <NUM_LIT:0> : <EOL> return ret . json ( ) <EOL> return None <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . server is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if not self . id : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ret = self . server . delete_json ( self . relativePath ( ) ) <EOL> if len ( ret . text ) > <NUM_LIT:0> : <EOL> return ret . json ( ) <EOL> return None <EOL> def search ( self , struct = None ) : <EOL> """<STR_LIT>""" <EOL> if struct is None : <EOL> struct = { '<STR_LIT>' : self . __class__ . resource_name } <EOL> if self . _local_id is not None or self . id is not None : <EOL> struct [ '<STR_LIT:id>' ] = self . _local_id or self . id <EOL> return self . __class__ . where ( struct ) <EOL> @ classmethod <EOL> def where ( cls , struct ) : <EOL> """<STR_LIT>""" <EOL> return fhirsearch . FHIRSearch ( cls , struct ) <EOL> from . import fhirdate <EOL> from . import fhirsearch <EOL> from . import fhirelementfactory </s>
