|
49 | 49 | dd_df = [] |
50 | 50 | structure_def_names_descriptions = {} |
51 | 51 |
|
| 52 | + |
| 53 | +def run_subprocess(args: list[str]) -> subprocess.CompletedProcess[bytes]: |
| 54 | + return subprocess.run( |
| 55 | + args, |
| 56 | + cwd=Path().parent, |
| 57 | + check=True, |
| 58 | + stdout=subprocess.PIPE, |
| 59 | + ) |
| 60 | + |
| 61 | + |
| 62 | +if not Path("./sushi/fsh-generated/resources").exists(): |
| 63 | + print("Generating sushi files") |
| 64 | + run_subprocess(["npm", "install"]) |
| 65 | + run_subprocess(["npm", "run", "sushi-build"]) |
| 66 | + |
52 | 67 | for resource_type in sample_sources_by_profile: |
53 | 68 | with Path(sample_sources_by_profile[resource_type]).open() as file: |
54 | 69 | sample_resources_by_profile[resource_type] = json.load(file) |
|
84 | 99 | "Pharmacy", |
85 | 100 | "PriorAuth", |
86 | 101 | ] |
| 102 | + |
| 103 | + |
87 | 104 | for walk_info in os.walk(dd_support_folder): |
88 | 105 | files = list(filter(lambda file: ".yaml" in file, walk_info[2])) |
89 | 106 | for file_name in files: |
90 | 107 | with Path(str(dd_support_folder) + "/" + str(file_name)).open() as file: |
| 108 | + print("Generating", file_name) |
91 | 109 | data = yaml.safe_load(file) |
92 | 110 | current_resource_type = file_name[0 : len(file_name) - 5] |
93 | 111 | for entry in data: |
|
110 | 128 | entry["FHIR Resource"] = "AuditEvent" |
111 | 129 |
|
112 | 130 | # This opportunistically populates examples based upon the samples created from executing FML |
113 | | - result = subprocess.run( |
| 131 | + result = run_subprocess( |
114 | 132 | [ |
115 | 133 | "node", |
116 | 134 | "eval_fhirpath.js", |
117 | 135 | json.dumps(sample_resources_by_profile[entry["appliesTo"][0]]), |
118 | 136 | entry["fhirPath"], |
119 | | - ], |
120 | | - cwd=os.path.dirname(__file__), |
121 | | - check=True, |
122 | | - stdout=subprocess.PIPE, |
| 137 | + ] |
123 | 138 | ) |
124 | 139 | entry["example"] = json.loads(result.stdout) |
125 | 140 | if "iif" in entry["fhirPath"] or "union" in entry["fhirPath"]: |
|
134 | 149 |
|
135 | 150 | # Populate the element names + missing descriptions |
136 | 151 | if entry["inputPath"] in structure_def_names_descriptions: |
137 | | - entry["Field Name"] = structure_def_names_descriptions[ |
138 | | - entry["inputPath"] |
139 | | - ]["name"] |
| 152 | + entry["Field Name"] = structure_def_names_descriptions[entry["inputPath"]][ |
| 153 | + "name" |
| 154 | + ] |
140 | 155 | if "definition" in structure_def_names_descriptions[entry["inputPath"]]: |
141 | 156 | entry["Description"] = structure_def_names_descriptions[ |
142 | 157 | entry["inputPath"] |
143 | | - ]["definition"] |
144 | | - #nameOverride and definitionOverride only exist when a field is derived IN fml. |
| 158 | + ]["definition"] |
| 159 | + # nameOverride and definitionOverride only exist when a field is derived IN fml. |
145 | 160 | if "nameOverride" in entry: |
146 | 161 | entry["Field Name"] = entry["nameOverride"] |
147 | 162 | entry["Description"] = entry["definitionOverride"] |
148 | 163 | elif "Description" not in entry or not entry["Description"]: |
149 | 164 | raise ValueError( |
150 | | - f"Entry {entry.get("inputPath", 'Unknown')} has no definition. " |
| 165 | + f"Entry {entry.get('inputPath', 'Unknown')} has no definition. " |
151 | 166 | ) |
152 | 167 | entry.pop("inputPath") |
153 | 168 | dd_df.append(entry) |
|
156 | 171 |
|
157 | 172 |
|
158 | 173 | def replace_str(input_str): |
159 | | - # Yes, the below is intentional. |
160 | | - if input_str == input_str and len(str(input_str)) > 0: |
| 174 | + if isinstance(input_str, str) and len(str(input_str)) > 0: |
161 | 175 | return "https://bluebutton.cms.gov/fhir/CodeSystem/" + str(input_str).replace("_", "-") |
162 | 176 | return "" |
163 | 177 |
|
|
0 commit comments