def parse_last_modified(cls, value: Any) -> Optional[datetime]: """Parse last_modified value.""" if value is None: return None if not isinstance(value, str): raise ValueError("must be a string") if value.strip() == "-": return None try: parsed_datetime = parse_datetime(value) if parsed_datetime.tzinfo is None: parsed_datetime = parsed_datetime.replace(tzinfo=timezone.utc) return parsed_datetime except DateTimeError: # Ignore pass try: date_value = parse_date(value) return datetime.combine(date_value, datetime.min.time(), tzinfo=timezone.utc) except DateError: log.error("Unable to parse last_modified value: %s", value) return None
def impl_Coverage_1(inst): assert inst.dependent == 1 assert inst.id == "7546D" assert inst.identifier[0].system == "http://xyz.com/codes/identifier" assert inst.identifier[0].value == "AB9876" assert inst.issuer.reference == "Organization/2" assert inst.period.end == parse_date("2012-03-17") assert inst.period.start == parse_date("2011-03-17") assert inst.plan == "11024" assert inst.subPlan == "D15C9" assert inst.subscriber.reference == "Patient/5" assert inst.text.div == "<div>A human-readable rendering of the coverage</div>" assert inst.text.status == "generated" assert inst.type.code == "EHCPOL" assert inst.type.display == "extended healthcare" assert inst.type.system == "http://hl7.org/fhir/v3/ActCode"
def impl_DetectedIssue_2(inst): assert inst.author.reference == "Device/dsp" assert inst.category.coding[0].code == "DUPTHPY" assert inst.category.coding[0].display == "Duplicate Therapy Alert" assert inst.category.coding[0].system == "http://hl7.org/fhir/v3/ActCode" assert inst.date == parse_date("2013-05-08") assert inst.detail == "Similar test was performed within the past 14 days" assert inst.id == "duplicate" assert (inst.implicated[0].display == "Chest CT - ordered May 8, 2013 by Dr. Adam Careful") assert inst.implicated[0].reference == "DiagnosticOrder/di" assert ( inst.implicated[1].display == "Image 1 from Series 3: CT Images on Patient MINT (MINT1234) taken at 1-Jan 2011 01:20 AM" ) assert inst.implicated[1].reference == "ImagingStudy/example" assert (inst.text.div == """<div> <p>Similar test was performed within the past 14 days</p> <ul> <li> <a href=\"DiagnosticOrder/id\">Chest CT - ordered May 8, 2013 by Dr. Adam Careful</a> </li> <li> <a href=\"ImagingStudy/example\">Image 1 from Series 3: CT Images on Patient MINT (MINT1234) taken at 1-Jan 2011 01:20 AM</a> </li> </ul> </div>""") assert inst.text.status == "generated"
def impl_Coverage_2(inst): assert inst.dependent == 1 assert inst.id == "9876B1" assert inst.identifier[0].system == "http://benefitsinc.com/certificate" assert inst.identifier[0].value == "12345" assert inst.issuer.reference == "Organization/2" assert inst.period.end == parse_date("2012-05-23") assert inst.period.start == parse_date("2011-05-23") assert inst.plan == "CBI35" assert inst.sequence == 1 assert inst.subPlan == "123" assert inst.subscriber.reference == "Patient/4" assert inst.text.div == "<div>A human-readable rendering of the coverage</div>" assert inst.text.status == "generated" assert inst.type.code == "EHCPOL" assert inst.type.display == "extended healthcare" assert inst.type.system == "http://hl7.org/fhir/v3/ActCode"
def impl_Device_1(inst): assert inst.expiry == parse_date("2020-08-08") assert inst.id == "f001" assert inst.identifier[ 0].system == "http:/goodhealthhospital/identifier/devices" assert inst.identifier[0].value == "12345" assert inst.location.display == "Central Supply" assert inst.manufactureDate == parse_date("2015-08-08") assert inst.owner.reference == "Organization/2.16.840.1.113883.19.5" assert inst.status == "available" assert ( inst.text.div == "<div><p><b>Generated Narrative with Details</b></p><p><b>id</b>: f001</p><p><b>identifier</b>: 12345</p><p><b>type</b>: Feeding tube, device <span>(Details : {SNOMED CT code '25062003' = '25062003', given as 'Feeding tube, device'})</span></p><p><b>status</b>: available</p><p><b>manufactureDate</b>: 08/08/2015</p><p><b>expiry</b>: 08/08/2020</p><p><b>udi</b>: (01)00000123000017(10)ABC123(17)120415</p><p><b>owner</b>: <a>Organization/2.16.840.1.113883.19.5</a></p><p><b>location</b>: Central Supply</p></div>" ) assert inst.text.status == "generated" assert inst.type.coding[0].code == "25062003" assert inst.type.coding[0].display == "Feeding tube, device" assert inst.type.coding[0].system == "http://snomed.info/sct" assert inst.udi == "(01)00000123000017(10)ABC123(17)120415"
def impl_EligibilityRequest_1(inst): assert inst.created == parse_date("2014-08-16") assert inst.id == "52345" assert inst.identifier[ 0].system == "http://happyvalley.com/elegibilityrequest" assert inst.identifier[0].value == "52345" assert inst.organization.reference == "Organization/2" assert (inst.text.div == "<div>A human-readable rendering of the EligibilityRequest</div>") assert inst.text.status == "generated"
def impl_DetectedIssue_4(inst): assert inst.author.reference == "Device/dsp" assert inst.category.coding[0].code == "DRG" assert inst.category.coding[0].display == "Drug Interaction Alert" assert inst.category.coding[0].system == "http://hl7.org/fhir/v3/ActCode" assert inst.date == parse_date("2014-01-05") assert ( inst.detail == "Risk of internal bleeding. Those who take acetaminophen along with the widely used blood-thinning drug warfarin may face the risk of serious internal bleeding. People on warfarin who take acetaminophen for at least seven days in a row should be closely watched for bleeding." ) assert inst.id == "ddi" assert (inst.implicated[0].display == "500 mg Acetaminophen tablet 1/day, PRN since 2010") assert inst.implicated[0].reference == "MedicationStatement/tylenol" assert inst.implicated[ 1].display == "Warfarin 1 MG TAB prescribed Jan. 5, 2014" assert inst.implicated[1].reference == "MedicationOrder/warfarin" assert inst.mitigation[0].action.coding[0].code == "13" assert inst.mitigation[0].action.coding[ 0].display == "Stopped Concurrent Therapy" assert (inst.mitigation[0].action.coding[0].system == "http://hl7.org/fhir/v3/ActCode") assert ( inst.mitigation[0].action.text == "Asked patient to discontinue regular use of Tylenol and to consult with clinician if they need to resume to allow appropriate INR monitoring" ) assert inst.mitigation[0].author.display == "Dr. Adam Careful" assert inst.mitigation[0].author.reference == "Practitioner/example" assert inst.mitigation[0].date == parse_date("2014-01-05") assert inst.severity == "high" assert (inst.text.div == """<div> <p><b>Severity: High</b> - Risk of internal bleeding</p> <p>Those who take acetaminophen along with the widely used blood-thinning drug warfarin may face the risk of serious internal bleeding. People on warfarin who take acetaminophen for at least seven days in a row should be closely watched for bleeding.</p> <ul> <li><a href=\"MedicationStatement/tylenol\">500 mg Acetaminophen tablet 1/day, PRN since 2010</a></li> <li><a href=\"MedicationOrder/warfarin\">Warfarin 1 MG TAB prescribed Jan. 5, 2014</a></li> </ul> <p>Mitigation: Jan 5, 2014 by Dr. Adam Careful: </p> <p>Asked patient to discontinue regular use of Tylenol and to consult with clinician if they need to resume to allow appropriate INR monitoring</p> </div>""") assert inst.text.status == "generated"
def impl_EnrollmentRequest_1(inst): assert inst.coverage.reference == "Coverage/9876B1" assert inst.created == parse_date("2014-08-16") assert inst.id == "22345" assert inst.identifier[0].system == "http://happyvalley.com/enrollmentrequest" assert inst.identifier[0].value == "EN22345" assert inst.organization.reference == "Organization/1" assert inst.relationship.code == "spouse" assert inst.subject.reference == "Patient/1" assert ( inst.text.div == "<div>A human-readable rendering of the EnrollmentRequest.</div>" ) assert inst.text.status == "generated"
def impl_EnrollmentResponse_1(inst): assert inst.created == parse_date("2014-08-16") assert inst.disposition == "Dependant added to policy." assert inst.id == "ER2500" assert (inst.identifier[0].system == "http://www.BenefitsInc.com/fhir/enrollmentresponse") assert inst.identifier[0].value == "781234" assert inst.organization.reference == "Organization/2" assert inst.outcome == "complete" assert (inst.request.reference == "http://www.BenefitsInc.com/fhir/eligibility/225476332402") assert inst.requestOrganization.reference == "Organization/1" assert (inst.text.div == "<div>A human-readable rendering of the EnrollmentResponse</div>") assert inst.text.status == "generated"
def impl_EligibilityResponse_1(inst): assert inst.created == parse_date("2014-08-16") assert inst.disposition == "Policy is currently in-force." assert inst.id == "E2500" assert (inst.identifier[0].system == "http://www.BenefitsInc.com/fhir/eligibilityresponse") assert inst.identifier[0].value == "881234" assert inst.organization.reference == "Organization/2" assert inst.outcome == "complete" assert (inst.request.reference == "http://www.BenefitsInc.com/fhir/eligibility/225476332402") assert inst.requestOrganization.reference == "Organization/1" assert ( inst.text.div == "<div>A human-readable rendering of the EligibilityResponse.</div>") assert inst.text.status == "generated"
def impl_AllergyIntolerance_2(inst): assert inst.category == "food" assert inst.criticality == "CRITH" assert inst.id == "allergyintolerance-example" assert inst.identifier[0].system == "http://acme.com/ids/patients/risks" assert inst.identifier[0].value == "49476534" assert inst.lastOccurence == "2012-06" assert inst.patient.reference == "Patient/example" assert inst.reaction[0].certainty == "confirmed" assert ( inst.reaction[0].description == "Challenge Protocol. Severe Reaction to 1/8 cashew. Epinephrine administered" ) assert inst.reaction[0].manifestation[0].coding[0].code == "39579001" assert (inst.reaction[0].manifestation[0].coding[0].display == "Anaphylactic reaction") assert (inst.reaction[0].manifestation[0].coding[0].system == "http://snomed.info/sct") assert inst.reaction[0].onset == parse_date("2012-06-12") assert inst.reaction[0].severity == "severe" assert inst.reaction[0].substance.coding[0].code == "C3214954" assert (inst.reaction[0].substance.coding[0].display == "cashew nut allergenic extract Injectable Product") assert (inst.reaction[0].substance.coding[0].system == "http://www.nlm.nih.gov/research/umls/rxnorm") assert inst.reaction[1].certainty == "likely" assert inst.reaction[1].manifestation[0].coding[0].code == "64305001" assert inst.reaction[1].manifestation[0].coding[0].display == "Urticaria" assert (inst.reaction[1].manifestation[0].coding[0].system == "http://snomed.info/sct") assert inst.reaction[1].onset == "2004" assert inst.reaction[1].severity == "moderate" assert inst.recordedDate == parse_datetime("2014-10-09T14:58:00+11:00") assert inst.recorder.reference == "Practitioner/example" assert inst.status == "confirmed" assert inst.substance.coding[0].code == "227493005" assert inst.substance.coding[0].display == "Cashew nuts" assert inst.substance.coding[0].system == "http://snomed.info/sct" assert ( inst.text.div == "<div><p><b>Generated Narrative with Details</b></p><p><b>id</b>: allergyintolerance-example</p><p><b>identifier</b>: 49476534</p><p><b>recordedDate</b>: 09/10/2014 2:58:00 PM</p><p><b>recorder</b>: <a>Practitioner/example</a></p><p><b>patient</b>: <a>Patient/example</a></p><p><b>substance</b>: Cashew nuts <span>(Details : {SNOMED CT code '227493005' = '227493005', given as 'Cashew nuts'})</span></p><p><b>status</b>: confirmed</p><p><b>criticality</b>: CRITH</p><p><b>type</b>: allergy</p><p><b>category</b>: food</p><p><b>lastOccurence</b>: 01/06/2012</p><blockquote><p><b>reaction</b></p><p><b>substance</b>: cashew nut allergenic extract Injectable Product <span>(Details : {RxNorm code 'C3214954' = '??', given as 'cashew nut allergenic extract Injectable Product'})</span></p><p><b>certainty</b>: confirmed</p><p><b>manifestation</b>: Anaphylactic reaction <span>(Details : {SNOMED CT code '39579001' = '39579001', given as 'Anaphylactic reaction'})</span></p><p><b>description</b>: Challenge Protocol. Severe Reaction to 1/8 cashew. Epinephrine administered</p><p><b>onset</b>: 12/06/2012</p><p><b>severity</b>: severe</p></blockquote><blockquote><p><b>reaction</b></p><p><b>certainty</b>: likely</p><p><b>manifestation</b>: Urticaria <span>(Details : {SNOMED CT code '64305001' = '64305001', given as 'Urticaria'})</span></p><p><b>onset</b>: 01/01/2004</p><p><b>severity</b>: moderate</p></blockquote></div>" ) assert inst.text.status == "generated" assert inst.type == "allergy"
def impl_AllergyIntolerance_4(inst): assert inst.category == "medication" assert inst.criticality == "CRITH" assert inst.id == "medication" assert inst.patient.reference == "Patient/example" assert inst.reaction[0].manifestation[0].coding[0].code == "247472004" assert inst.reaction[0].manifestation[0].coding[0].display == "Hives" assert (inst.reaction[0].manifestation[0].coding[0].system == "http://snomed.info/sct") assert inst.recordedDate == parse_date("2010-03-01") assert inst.recorder.reference == "Practitioner/13" assert inst.status == "unconfirmed" assert inst.substance.coding[0].code == "314422" assert inst.substance.coding[0].display == "ALLERGENIC EXTRACT, PENICILLIN" assert (inst.substance.coding[0].system == "http://www.nlm.nih.gov/research/umls/rxnorm") assert ( inst.text.div == "<div><p><b>Generated Narrative with Details</b></p><p><b>id</b>: medication</p><p><b>recordedDate</b>: 01/03/2010</p><p><b>recorder</b>: <a>Practitioner/13</a></p><p><b>patient</b>: <a>Patient/example</a></p><p><b>substance</b>: ALLERGENIC EXTRACT, PENICILLIN <span>(Details : {RxNorm code '314422' = '??', given as 'ALLERGENIC EXTRACT, PENICILLIN'})</span></p><p><b>status</b>: unconfirmed</p><p><b>criticality</b>: CRITH</p><p><b>category</b>: medication</p><h3>Reactions</h3><table><tr><td>-</td><td><b>Manifestation</b></td></tr><tr><td>*</td><td>Hives <span>(Details : {SNOMED CT code '247472004' = '247472004', given as 'Hives'})</span></td></tr></table></div>" ) assert inst.text.status == "generated"
async def update_user( user_data: DotDict, update_data: Dict[str, Any], is_new: bool = False, is_registering: bool = False, is_admin: bool = False, is_self: bool = False, no_registration: bool = False, ): if 'sub' in update_data or '_id' in update_data or 'picture' in update_data: raise HTTPException(400, f"Cannot modify 'sub', '_id' or 'picture'") was_active = user_data.get('active', False) reset_user_cache = False if is_new: assert '_id' not in user_data user_data['_id'] = generate_token(48) if 'password' in update_data: if not isinstance(update_data['password'], str): raise HTTPException(400, "'password' must be a string") _validate_property_write('password', is_self, is_admin) if is_self and not is_registering and user_data.get( 'password') is not None: if 'old_password' not in update_data: raise HTTPException( 400, f"Need {repr('old_password')} for setting password") if not isinstance(update_data['old_password'], str): raise HTTPException(400, f"{repr('old_password')} is not a string") is_valid, _ = verify_and_update(update_data['old_password'], user_data['password']) if not is_valid: raise HTTPException(401, "Old password does not match") try: user_data['password'] = create_password(update_data['password']) del update_data['password'] except PasswordLeakedException: raise HTTPException( 400, "Password is leaked and cannot be used. See https://haveibeenpwned.com/" ) async def send_mail(): pass if is_registering and update_data.get( 'email', user_data['email']) == user_data['email']: user_data['email_verified'] = True elif 'email' in update_data: if not isinstance(update_data['email'], str): raise HTTPException(400, "'email' must be a string") _validate_property_write('email', is_self, is_admin) if not is_email(update_data['email'], check_dns=True): raise HTTPException(400, "E-Mail address not accepted") if await async_user_collection.count_documents( {'email': update_data['email']}, limit=1) != 0: raise HTTPException( 400, "E-Mail address already in use, please use existing account") new_mail = update_data['email'] locale = update_data.get( 'locale', user_data.get('locale', config.oauth2.user.properties['locale'].default)) if locale is None: locale = 'en_us' tz = _get_tz(update_data.get('zoneinfo', user_data.get('zoneinfo'))) del update_data['email'] if is_new and not no_registration: user_data['email'] = new_mail user_data['email_verified'] = False token_valid_until = int(time.time() + config.manager.token_valid.registration) user_data['registration_token'] = create_token( user_data['_id'], token_valid_until) async def send_mail(): await async_send_mail_register(user_data, token_valid_until, locale, tz) elif not is_admin: token_valid_until = int(time.time() + config.manager.token_valid.email_set) user_data['email_verification_token'] = create_token( new_mail, token_valid_until) if is_registering: user_data['email'] = new_mail user_data['email_verified'] = False async def send_mail(): await async_send_mail_verify(locale, new_mail, user_data, token_valid_until, tz) else: user_data['email'] = new_mail user_data['email_verified'] = False if 'access_tokens' in update_data: if not isinstance(update_data['access_tokens'], list): raise HTTPException(400, "'access_tokens' must be a list") try: access_tokens = [ ValidateAccessToken.validate(val) for val in update_data['access_tokens'] ] except ValueError as err: raise HTTPException(400, str(err)) _validate_property_write('access_tokens', is_self, is_admin) existing_access_tokens = [ UserPasswordAccessToken.validate(access_token) for access_token in user_data.get('access_tokens', []) ] existing_access_tokens_by_id = { existing_access_token.id: existing_access_token for existing_access_token in existing_access_tokens } new_access_tokens = [] for access_token in access_tokens: if access_token.id is not None: store_token = existing_access_tokens_by_id.get(access_token.id) if store_token is None: raise HTTPException(400, f"Invalid token ID {access_token.id}") store_token.description = access_token.description if access_token.token is not None: store_token.token = access_token.token else: store_token = UserPasswordAccessToken( id=generate_token(24), description=access_token.description, token=access_token.token, ) new_access_tokens.append(store_token) del update_data['access_tokens'] user_data['access_tokens'] = [ access_token.dict() for access_token in new_access_tokens ] if 'groups' in update_data: if await _update_groups( user_data, update_data, property='groups', is_self=is_self, is_admin=is_admin, existence_check_property=None, groups_add_property='members', groups_pull_properties=( 'members', 'email_allowed_forward_members', 'email_forward_members', 'email_postbox_access_members', ), members_pull_properties=( 'email_allowed_forward_members', 'email_forward_members', 'email_postbox_access_members', ), ): reset_user_cache = True if 'email_allowed_forward_groups' in update_data: await _update_groups( user_data, update_data, property='email_allowed_forward_groups', is_self=is_self, is_admin=is_admin, existence_check_property='groups', groups_add_property='email_allowed_forward_members', groups_pull_properties=('email_allowed_forward_members', 'email_forward_members'), members_pull_properties=('email_forward_members', )) if 'email_forward_groups' in update_data: await _update_groups( user_data, update_data, property='email_forward_groups', is_self=is_self, is_admin=is_admin, existence_check_property='email_allowed_forward_groups', groups_add_property='email_forward_members', groups_pull_properties=('email_forward_members', ), ) if 'email_postbox_access_groups' in update_data: await _update_groups( user_data, update_data, property='email_postbox_access_groups', is_self=is_self, is_admin=is_admin, existence_check_property='groups', groups_add_property='email_postbox_access_members', groups_pull_properties=('email_postbox_access_members', ), ) for key, value in update_data.items(): _validate_property_write(key, is_self, is_admin) prop = config.oauth2.user.properties[key] if prop.write_once and user_data.get(key) is not None: raise HTTPException(400, f"{repr(key)} can only be set once") if not value and not prop.required and key in user_data: del user_data[key] if prop.type in (UserPropertyType.str, UserPropertyType.multistr, UserPropertyType.token): if not isinstance(value, str): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a string") if prop.template is not None: raise HTTPException(400, f"{repr(key)}={repr(value)} is generated") if prop.format is not None: regex = get_regex(prop.format) if not regex.fullmatch(value): raise HTTPException( 400, f"{repr(key)}={repr(value)} does not match pattern {repr(regex.pattern)}" ) user_data[key] = value elif prop.type == UserPropertyType.int: if isinstance(value, float): if not value.is_integer(): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not an integer") value = int(value) if not isinstance(value, int): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not an integer") user_data[key] = value elif prop.type == UserPropertyType.bool: if not isinstance(value, bool): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a boolean") user_data[key] = value elif prop.type == UserPropertyType.datetime: if not isinstance(value, str): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a datetime string") try: parse_datetime(value) user_data[key] = value except ValueError: raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a datetime string") elif prop.type == UserPropertyType.date: if not isinstance(value, str): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a date string") try: parse_date(value) user_data[key] = value except ValueError: raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a datetime string") elif prop.type == UserPropertyType.enum: if not isinstance(value, str): raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a string") assert prop.values is not None values = [enum_value.value for enum_value in prop.values] if value not in values: raise HTTPException( 400, f"{repr(key)}={repr(value)} is not a valid enum value") user_data[key] = value else: raise NotImplementedError(f"{repr(prop.type)}") # Set others to default if is_new or is_registering: for key, value in config.oauth2.user.properties.items(): if value.default is not None and key not in user_data: user_data[key] = value.default # Activate the user after registration if is_registering: user_data['active'] = True # Apply all templates and validate required, when not active if user_data.get('active', False): # Validate that all required variables are present for key, value in config.oauth2.user.properties.items(): if value.required and user_data.get(key) is None: raise HTTPException(400, f"Missing {repr(key)}") # Apply templates (they should not be required) for key, value in config.oauth2.user.properties.items(): if (value.type == UserPropertyType.str and value.template is not None and (not value.write_once or not user_data.get(key))): assert "'''" not in value.template, f"Invalid ''' in template: {value.template}" user_data[key] = eval( f"f'''{value.template}'''", { 'make_username': make_username, 'config': config }, user_data, ) user_data['updated_at'] = int(time.time()) User.validate(user_data) if is_new: await async_user_collection.insert_one(user_data) else: await async_user_collection.replace_one({'_id': user_data['_id']}, user_data) if user_data.get('active', False): if reset_user_cache: await async_client_user_cache_collection.delete_many( {'user_id': user_data['_id']}) else: await async_client_user_cache_collection.update_many( {'user_id': user_data['_id']}, {'$set': { 'last_modified': user_data['updated_at'] }}, ) elif was_active: await async_client_user_cache_collection.delete_many( {'user_id': user_data['_id']}) await async_token_collection.delete_many({'user_id': user_data['_id']}) await async_session_collection.delete_many( {'user_id': user_data['_id']}) await async_authorization_code_collection.delete_many( {'user_id': user_data['_id']}) elif reset_user_cache: await async_client_user_cache_collection.delete_many( {'user_id': user_data['_id']}) # Last: Send the email if there is one await send_mail()
def test_date_parsing(value, result): if type(result) == type and issubclass(result, Exception): with pytest.raises(result): parse_date(value) else: assert parse_date(value) == result
def is_date(value: Union[date, StrBytesIntFloat]) -> bool: try: parse_date(value) return isinstance(value, (str, date)) except: return False
def test_date_parsing(value, result): if result == errors.DateError: with pytest.raises(errors.DateError): parse_date(value) else: assert parse_date(value) == result
def impl_Composition_1(inst): assert inst.attester[0].mode[0] == "legal" assert inst.attester[0].party.display == "Harold Hippocrates, MD" assert inst.attester[0].party.reference == "Practitioner/xcda-author" assert inst.attester[0].time == datetime(2012, 1, 4, 9, 10, 14, tzinfo=timezone.utc) assert inst.author[0].display == "Harold Hippocrates, MD" assert inst.author[0].reference == "Practitioner/xcda-author" assert inst.confidentiality == "N" assert inst.custodian.display == "Good Health Clinic" assert inst.custodian.reference == "Organization/2.16.840.1.113883.19.5" assert inst.date == datetime(2012, 1, 4, 9, 10, 14, tzinfo=timezone.utc) assert inst.encounter.reference == "Encounter/xcda" assert inst.event[0].code[0].coding[0].code == "HEALTHREC" assert inst.event[0].code[0].coding[0].display == "health record" assert inst.event[0].code[0].coding[ 0].system == "http://hl7.org/fhir/v3/ActCode" assert inst.event[0].detail[0].reference == "Observation/example" assert inst.event[0].period.end == parse_date("2012-11-12") assert inst.event[0].period.start == parse_date("2010-07-18") assert inst.id == "example" assert inst.identifier.system == "http://healthintersections.com.au/test" assert inst.identifier.value == "1" assert inst.section[0].code.coding[0].code == "11348-0" assert inst.section[0].code.coding[ 0].display == "History of past illness Narrative" assert inst.section[0].code.coding[0].system == "http://loinc.org" assert inst.section[0].entry[0].reference == "Condition/stroke" assert inst.section[0].entry[1].reference == "Condition/example" assert inst.section[0].entry[2].reference == "Condition/example2" assert inst.section[0].mode == "snapshot" assert inst.section[0].orderedBy.coding[0].code == "event-date" assert inst.section[0].orderedBy.coding[ 0].display == "Sorted by Event Date" assert (inst.section[0].orderedBy.coding[0].system == "http://hl7.org/fhir/list-order") assert (inst.section[0].text.div == """<div> <table> <tr> <td> <b>Code</b> </td> <td> <b>Date</b> </td> <td> <b>Type</b> </td> <td> <b>BodySite</b> </td> <td> <b>Severity</b> </td> </tr> <tr> <td>Stroke</td> <td>2010-07-18</td> <td>Diagnosis</td> <td/> <td/> </tr> <tr> <td>Burnt Ear</td> <td>2012-05-24</td> <td>Diagnosis</td> <td>Left Ear</td> <td/> </tr> <tr> <td>Asthma</td> <td>2012-11-12</td> <td>Finding</td> <td/> <td>Mild</td> </tr> </table> </div>""") assert inst.section[0].text.status == "generated" assert inst.section[0].title == "History of present illness" assert inst.section[1].code.coding[0].code == "10157-6" assert (inst.section[1].code.coding[0].display == "History of family member diseases Narrative") assert inst.section[1].code.coding[0].system == "http://loinc.org" assert inst.section[1].emptyReason.coding[0].code == "withheld" assert inst.section[1].emptyReason.coding[ 0].display == "Information Withheld" assert (inst.section[1].emptyReason.coding[0].system == "http://hl7.org/fhir/list-empty-reason") assert inst.section[1].mode == "snapshot" assert (inst.section[1].text.div == """<div> <p>History of family member diseases - not available</p> </div>""") assert inst.section[1].text.status == "generated" assert inst.section[1].title == "History of family member diseases" assert inst.status == "final" assert inst.subject.display == "Henry Levin the 7th" assert inst.subject.reference == "Patient/xcda" assert (inst.text.div == """<div> <p>Consultation note for Henry Levin the 7th</p> <p>Managed by Good Health Clinic</p> </div>""") assert inst.text.status == "generated" assert inst.title == "Consultation Note" assert inst.type.coding[0].code == "11488-4" assert inst.type.coding[0].display == "Consult note" assert inst.type.coding[0].system == "http://loinc.org"
def date_to_datetime(cls, v: date) -> datetime: v = datetime_parse.parse_date(v) v = datetime.combine(v, datetime.min.time()) return v