from fhir.resources.
patient import Patient
import json
from datetime import datetime, date
class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, date):
return obj.isoformat()
return super().default(obj)
def get_patient_details():
"""
This function collects the details of the patient where the user can
enter the name, gender, birthdate, and telephone number.
And afterwards the return value for the funtion is the patient record.
The function gets invoked using the entry point if __name__ where the
main function is called.
Returns:
_type_: patient record
"""
patient = Patient()
patient_name = input("Enter the patient name : ")
if patient_name:
patient.name = [{"text": patient_name}]
patient_gender = input("Enter patient gender (Male, Female, Other,
Unknown): ")
if patient_gender:
patient.gender = patient_gender
patient_birthdate = input("Enter patient birthdate in the format YYYY-MM-
DD: ")
if patient_birthdate:
try:
birthdate_obj = datetime.strptime(patient_birthdate, "%Y-%m-%d")
patient.birthDate = birthdate_obj.date()
except ValueError:
print(
"Invalid date format. Kindly use YYYY-MM-DD format for
birthdate as requested previously."
)
patient.telecom = []
add_tele_info = True
while add_tele_info:
telecom_system = input(
"Enter telecom system (e.g., phone number system, email system): "
)
telecom_value = input("Enter telecom value of the telecon system
above: ")
patient.telecom.append({"system": telecom_system, "value":
telecom_value})
add_more = input(
"Add another telecom? Enter Y for yes, N for no (y/n): "
).lower()
if add_more != "y":
add_tele_info = False
patient_address = {
"use": "home",
"line": [input("Enter address line: ")],
"city": input("Enter city: "),
"state": input("Enter state: "),
"postalCode": input("Enter postal code: "),
"country": input("Enter country: "),
}
patient.address = [patient_address]
return patient
def main():
patient_record = get_patient_details()
patient_dict = patient_record.dict()
with open("patient_record.json", "a") as json_file:
json.dump(patient_dict, json_file, indent=4, cls=CustomJSONEncoder)
json_file.write(",\n")
if __name__ == "__main__":
main()
from fhir.resources.patient import Patient
import json
from datetime import datetime, date
class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, date):
return obj.isoformat()
return super().default(obj)
def get_patient_details():
"""
This function collects the details of the patient where the user can
enter the name, gender, birthdate, and telephone number.
And afterwards the return value for the funtion is the patient record.
The function gets invoked using the entry point if __name__ where the
main function is called.
Returns:
_type_: patient record
"""
patient = Patient()
patient_name = input("Enter the patient name : ")
if patient_name:
patient.name = [{"text": patient_name}]
patient_gender = input("Enter patient gender (Male, Female, Other,
Unknown): ")
if patient_gender:
patient.gender = patient_gender
patient_birthdate = input("Enter patient birthdate in the format YYYY-MM-
DD: ")
if patient_birthdate:
try:
birthdate_obj = datetime.strptime(patient_birthdate, "%Y-%m-%d")
patient.birthDate = birthdate_obj.date()
except ValueError:
print(
"Invalid date format. Kindly use YYYY-MM-DD format for
birthdate as requested previously."
)
patient.telecom = []
add_tele_info = True
while add_tele_info:
telecom_system = input(
"Enter telecom system (e.g., phone number system, email system): "
)
telecom_value = input("Enter telecom value of the telecon system
above: ")
patient.telecom.append({"system": telecom_system, "value":
telecom_value})
add_more = input(
"Add another telecom? Enter Y for yes, N for no (y/n): "
).lower()
if add_more != "y":
add_tele_info = False
patient_address = {
"use": "home",
"line": [input("Enter address line: ")],
"city": input("Enter city: "),
"state": input("Enter state: "),
"postalCode": input("Enter postal code: "),
"country": input("Enter country: "),
}
patient.address = [patient_address]
return patient
def main():
patient_record = get_patient_details()
patient_dict = patient_record.dict()
with open("patient_record.json", "a") as json_file:
json.dump(patient_dict, json_file, indent=4, cls=CustomJSONEncoder)
json_file.write(",\n")
if __name__ == "__main__":
main()
from fhir.resources.patient import Patient
import json
from datetime import datetime, date
class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, date):
return obj.isoformat()
return super().default(obj)
def get_patient_details():
"""
This function collects the details of the patient where the user can
enter the name, gender, birthdate, and telephone number.
And afterwards the return value for the funtion is the patient record.
The function gets invoked using the entry point if __name__ where the
main function is called.
Returns:
_type_: patient record
"""
patient = Patient()
patient_name = input("Enter the patient name : ")
if patient_name:
patient.name = [{"text": patient_name}]
patient_gender = input("Enter patient gender (Male, Female, Other,
Unknown): ")
if patient_gender:
patient.gender = patient_gender
patient_birthdate = input("Enter patient birthdate in the format YYYY-MM-
DD: ")
if patient_birthdate:
try:
birthdate_obj = datetime.strptime(patient_birthdate, "%Y-%m-%d")
patient.birthDate = birthdate_obj.date()
except ValueError:
print(
"Invalid date format. Kindly use YYYY-MM-DD format for
birthdate as requested previously."
)
patient.telecom = []
add_tele_info = True
while add_tele_info:
telecom_system = input(
"Enter telecom system (e.g., phone number system, email system): "
)
telecom_value = input("Enter telecom value of the telecon system
above: ")
patient.telecom.append({"system": telecom_system, "value":
telecom_value})
add_more = input(
"Add another telecom? Enter Y for yes, N for no (y/n): "
).lower()
if add_more != "y":
add_tele_info = False
patient_address = {
"use": "home",
"line": [input("Enter address line: ")],
"city": input("Enter city: "),
"state": input("Enter state: "),
"postalCode": input("Enter postal code: "),
"country": input("Enter country: "),
}
patient.address = [patient_address]
return patient
def main():
patient_record = get_patient_details()
patient_dict = patient_record.dict()
with open("patient_record.json", "a") as json_file:
json.dump(patient_dict, json_file, indent=4, cls=CustomJSONEncoder)
json_file.write(",\n")
if __name__ == "__main__":
main()