1

Good day everyone. I'm building a RESTful API which returns content of some text files (.pdd). The files are organized as follows:

|-- 10200                          # some patient's id
|   |-- Cardio
|   |   |-- 3002                    # some event id
|   |   |   |-- some_data.pdd
|   |-- Encounter
|   |   |-- 5222                    # some event id
|   |   |   |-- CPS.pdd
|   |   |   |-- S_ASSESSMENT.pdd
|   |   |   |-- S_CCHPI.pdd
|   |   |   |-- S_PLAN.pdd
|   |   |   |-- S_ROS.pdd
|   |   |   |-- S_VITALS.pdd
|   |   |-- 5223
|   |   |   |-- CPS.pdd
|   |   |   |-- S_ASSESSMENT.pdd
|   |   |   |-- S_PLAN.pdd
|   |   |   |-- S_VITALS.pdd
|   |   |-- 5224

What I need to do (and already have done) is to parse .pdd files (it's just text) based on patient and/or event_id. For that I've implemented "all-customizable" (as I thought) class. It works fine:

class PddParser:
    def __init__(self, pdd_type,
                 pdd_name=None, pat_code=None, event_id=None)

where pdd_type is Encounter/Cardio/etc., pdd_name is optional, specific .pdd filename.

The workflow is (each step is split in class' methods):

1) get the filepaths based on params using glob (wildcards allowed: for all or specific .pdd (and/or) patient (and/or) event).

2) read every file content

3) aggregate everything into a dict of dicts (outer dict's key is just filename and value is file content, inner happens to be dict only because .pdd has key-values as content) and return.

This is called as:

parser = PddParser(pdd_type, pdd_name, pat_code, id)
data = pdd_parser.get_pdd_contents() # method from third step
# return data to endpoint

and allows plenty of different endpoints to return all/specific .pdds for all/specific patient and/or visits.

But turns out some files have specific fields which needs specific aggregation (third method). The way I've implemented it I see no convenient way of changing aggregation using decomposition (or inheritance) but only writing more code inside of the method (maybe just with splitting it a bit more into methods but still inside one PddParser). Is the reason for that is that I instantiate the class in one place for all endpoints? If so, I don't understand how to redo my code to make it convenient to add special cases.

Initially, I wanted to subclass PddParser for every type of file which needs that (say, create ROSPddParser and so on) but I don't see how to do that in that case and not sure if it is right. Is it good enough (from architect point of view) to just create more methods inside of a base PddParser class or how should I approach the problem to make it right?

Larleyt
  • 83
  • 1
  • 1
  • 5

0 Answers0