0

I have a to use a class attribute that sets the default key:value pairs as shown:

class ElectronicMedicalRecord():
    def __init__(self, default_emr_config = {"language": 'english', "hospital_campus": 'PSOM', "emr_vendor": 'Epic'}):
        self.default_emr_config = default_emr_config

However, I have to now define a new method called "set_default_emr_config" to prompt a user to update the values of the key:value pairs to something new. I tried to do this:

class ElectronicMedicalRecord():
    def __init__(self, default_emr_config = {"language": 'english', "hospital_campus": 'PSOM', "emr_vendor": 'Epic'}):
        self.default_emr_config = default_emr_config
        
    def set_default_emr_config(self, default_emr_config):
        self.default_emr_config = default_emr_config
        
EMR = ElectronicMedicalRecord()
print(EMR.default_emr_config)

EMR.set_default_emr_config({"language": 'spanish', "hospital_campus": 'Drexel', "emr_vendor": 'Not Epic'})
print(EMR.default_emr_config)

But this is obviously not done using user input.

1 Answer 1

1

You can loop through the dictionary and give the user the option to keep the current value or update it.

Try this code:

class ElectronicMedicalRecord():
    def __init__(self, default_emr_config = {"language": 'english', "hospital_campus": 'PSOM', "emr_vendor": 'Epic'}):
        self.default_emr_config = default_emr_config
        
    def set_default_emr_config(self, default_emr_config):
        self.default_emr_config = default_emr_config
        
EMR = ElectronicMedicalRecord()
print(EMR.default_emr_config)

newdict = {}
for k in EMR.default_emr_config:
   v = input(f'Value for {k} [{EMR.default_emr_config[k]}]: ').strip()
   if v == "":
       newdict[k] = EMR.default_emr_config[k]  # keep current value
   else:
       newdict[k] = v  # new value

EMR.set_default_emr_config(newdict)
print(EMR.default_emr_config)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.