|
1 | | -import copy |
2 | | -from jsonpath_ng.ext import parse as ext_parse |
3 | 1 | from rest_framework import (permissions) |
4 | 2 | from rest_framework.response import Response |
5 | 3 | from voluptuous import ( |
|
18 | 16 | from apps.authorization.permissions import DataAccessGrantPermission |
19 | 17 | from apps.capabilities.permissions import TokenHasProtectedCapability |
20 | 18 | from ..permissions import (SearchCrosswalkPermission, ResourcePermission, ApplicationActivePermission) |
21 | | -from apps.fhir.bluebutton.views.b64card import B64_BLU_CARD, B64_RED_BLU_CARD, B64_BLU_CARD_BG, B64_HUMANA_PTD |
22 | | - |
23 | | - |
24 | | -# image mapping to part A, B, C, D |
25 | | -# A: B64_BLU_CARD_BG large vertical figma card as background |
26 | | -# B: B64_RED_BLU_CARD classic medicare card image |
27 | | -# C: B64_BLU_CARD horizontal figma card |
28 | | -# D: B64_HUMANA_PTD medicare RX humana part D card |
29 | | -INS_TYPE2CARD = { |
30 | | - "Part A": ''.join(B64_BLU_CARD_BG.splitlines()), |
31 | | - "Part B": ''.join(B64_RED_BLU_CARD.splitlines()), |
32 | | - "Part C": ''.join(B64_BLU_CARD.splitlines()), |
33 | | - "Part D": ''.join(B64_HUMANA_PTD.splitlines()) |
34 | | -} |
35 | 19 |
|
36 | 20 | C4BB_COVERAGE_PROFILE_URL = "http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-Coverage" |
37 | 21 |
|
38 | 22 | C4DIC_COVERAGE_PROFILE_URL = "http://hl7.org/fhir/us/insurance-card/StructureDefinition/C4DIC-Coverage" |
39 | 23 |
|
40 | | -C4DIC_SUPPORTING_IMAGE_EXT = { |
41 | | - "extension": [ |
42 | | - { |
43 | | - "url": "description", |
44 | | - "valueString": "Beneficiary's proof of insurance" |
45 | | - }, |
46 | | - { |
47 | | - "url": "image", |
48 | | - "valueAttachment": { |
49 | | - "contentType": "image/png", |
50 | | - "data": "<replace with base64 encoded image png here>" |
51 | | - } |
52 | | - }, |
53 | | - { |
54 | | - "url": "label", |
55 | | - "valueString": "CMS Insurance card" |
56 | | - } |
57 | | - ], |
58 | | - "url": "http://hl7.org/fhir/us/insurance-card/StructureDefinition/C4DIC-SupportingImage-extension" |
59 | | -} |
60 | | - |
61 | | - |
62 | | -# POC helper |
63 | | -def lookup_by_path(expr, json_obj): |
64 | | - jsonpath_expr = ext_parse(expr) |
65 | | - return jsonpath_expr.find(json_obj) |
66 | | - |
67 | | - |
68 | | -# POC helper |
69 | | -def lookup_1_and_get(expr, attribute, json_obj): |
70 | | - r = lookup_by_path(expr, json_obj) |
71 | | - if r and isinstance(r, list): |
72 | | - return r[0].value[attribute] |
73 | | - |
74 | | - |
75 | | -# POC helper: generate supporting image extension per coverage class type |
76 | | -def get_supporting_image_extension(b64encoded: str): |
77 | | - ext = copy.deepcopy(C4DIC_SUPPORTING_IMAGE_EXT) |
78 | | - for e in ext['extension']: |
79 | | - if e['url'] == 'image': |
80 | | - e['valueAttachment']['data'] = b64encoded |
81 | | - break |
82 | | - return ext |
83 | | - |
84 | | - |
85 | | -# POC helper |
86 | | -def enrich_supporting_image(resp: Response): |
87 | | - for e in resp.data['entry']: |
88 | | - extensions = e['resource']['extension'] |
89 | | - class_type = lookup_1_and_get("$.resource.class[?(@.type.coding[0].code=='plan')]", "value", e) |
90 | | - class_type = "Part A" if class_type is None else class_type |
91 | | - extensions.append(get_supporting_image_extension(INS_TYPE2CARD[class_type])) |
92 | | - |
93 | | - return resp |
94 | | - |
95 | 24 |
|
96 | 25 | class SearchView(FhirDataView): |
97 | 26 | # Base class for FHIR resource search views |
@@ -179,9 +108,7 @@ def get(self, request, *args, **kwargs): |
179 | 108 | if return_c4dic and profile == C4DIC_COVERAGE_PROFILE_URL: |
180 | 109 | return Response(get_response_json("bfd-c4dic-coverage-search")) |
181 | 110 | else: |
182 | | - resp = super().get(request, *args, **kwargs) |
183 | | - # C4DIC POC: inject c4dic supportingImage extension if the _profile indicate C4DIC Coverage search |
184 | | - return enrich_supporting_image(resp) if profile == C4DIC_COVERAGE_PROFILE_URL else resp |
| 111 | + return super().get(request, *args, **kwargs) |
185 | 112 |
|
186 | 113 |
|
187 | 114 | class SearchViewExplanationOfBenefit(SearchView): |
|
0 commit comments