Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jimfuqian/BB2-3280-C4DIC POC: Enrich c4dic coverage w supporting image #1241

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ ENV PATH="/tmp/venv/bin:${PATH}"
RUN pip install --upgrade pip
RUN pip install --upgrade pip-tools
RUN pip install --upgrade setuptools
RUN pip install jsonpath-ng
RUN pip install -r requirements/requirements.dev.txt --no-index --find-links ./vendor/
2 changes: 1 addition & 1 deletion Dockerfiles/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build, Tag, and Publish integration and selenium tests ECR iamge
# Build, Tag, and Publish integration and selenium tests ECR image

Go to BB2 local repo base directory and do the followings (assume aws cli installed and configured properly):

Expand Down
12,432 changes: 12,432 additions & 0 deletions apps/fhir/bluebutton/views/b64card.py

Large diffs are not rendered by default.

88 changes: 83 additions & 5 deletions apps/fhir/bluebutton/views/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import copy
from jsonpath_ng.ext import parse as ext_parse
from rest_framework import (permissions)
from rest_framework.response import Response
from voluptuous import (
Required,
All,
Expand All @@ -7,15 +11,86 @@
Schema,
REMOVE_EXTRA,
)
from rest_framework import (permissions)
from rest_framework.response import Response

from apps.fhir.bluebutton.constants import DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE
from apps.fhir.bluebutton.views.generic import FhirDataView
from apps.fhir.bluebutton.views.home import get_response_json
from apps.authorization.permissions import DataAccessGrantPermission
from apps.capabilities.permissions import TokenHasProtectedCapability
from ..permissions import (SearchCrosswalkPermission, ResourcePermission, ApplicationActivePermission)
from apps.fhir.bluebutton.views.b64card import B64_BLU_CARD, B64_RED_BLU_CARD, B64_BLU_CARD_BG, B64_HUMANA_PTD


# image mapping to part A, B, C, D
# A: B64_BLU_CARD_BG large vertical figma card as background
# B: B64_RED_BLU_CARD classic medicare card image
# C: B64_BLU_CARD horizontal figma card
# D: B64_HUMANA_PTD medicare RX humana part D card
INS_TYPE2CARD = {
"Part A": ''.join(B64_BLU_CARD_BG.splitlines()),
"Part B": ''.join(B64_RED_BLU_CARD.splitlines()),
"Part C": ''.join(B64_BLU_CARD.splitlines()),
"Part D": ''.join(B64_HUMANA_PTD.splitlines())
}

C4BB_COVERAGE_PROFILE_URL = "http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-Coverage"

C4DIC_COVERAGE_PROFILE_URL = "http://hl7.org/fhir/us/insurance-card/StructureDefinition/C4DIC-Coverage"

C4DIC_SUPPORTING_IMAGE_EXT = {
"extension": [
{
"url": "description",
"valueString": "Beneficiary's proof of insurance"
},
{
"url": "image",
"valueAttachment": {
"contentType": "image/png",
"data": "<replace with base64 encoded image png here>"
}
},
{
"url": "label",
"valueString": "CMS Insurance card"
}
],
"url": "http://hl7.org/fhir/us/insurance-card/StructureDefinition/C4DIC-SupportingImage-extension"
}


# POC helper
def lookup_by_path(expr, json_obj):
jsonpath_expr = ext_parse(expr)
return jsonpath_expr.find(json_obj)


# POC helper
def lookup_1_and_get(expr, attribute, json_obj):
r = lookup_by_path(expr, json_obj)
if r and isinstance(r, list):
return r[0].value[attribute]


# POC helper: generate supporting image extension per coverage class type
def get_supporting_image_extension(b64encoded: str):
ext = copy.deepcopy(C4DIC_SUPPORTING_IMAGE_EXT)
for e in ext['extension']:
if e['url'] == 'image':
e['valueAttachment']['data'] = b64encoded
break
return ext


# POC helper
def enrich_supporting_image(resp: Response):
for e in resp.data['entry']:
extensions = e['resource']['extension']
class_type = lookup_1_and_get("$.resource.class[?(@.type.coding[0].code=='plan')]", "value", e)
class_type = "Part A" if class_type is None else class_type
extensions.append(get_supporting_image_extension(INS_TYPE2CARD[class_type]))

return resp


class SearchView(FhirDataView):
Expand All @@ -41,7 +116,8 @@ class SearchView(FhirDataView):
QUERY_SCHEMA = {
Required('startIndex', default=0): Coerce(int),
Required('_count', default=DEFAULT_PAGE_SIZE): All(Coerce(int), Range(min=0, max=MAX_PAGE_SIZE)),
'_lastUpdated': [Match(REGEX_LASTUPDATED_VALUE, msg="the _lastUpdated operator is not valid")]
'_lastUpdated': [Match(REGEX_LASTUPDATED_VALUE, msg="the _lastUpdated operator is not valid")],
'_profile': Match('.+', msg="_profile value takes a non empty url like string")
}

def __init__(self, version=1):
Expand Down Expand Up @@ -100,10 +176,12 @@ def build_parameters(self, request, *args, **kwargs):
def get(self, request, *args, **kwargs):
profile = request.query_params.get('_profile', '')
return_c4dic = False
if return_c4dic and profile == "http://hl7.org/fhir/us/insurance-card/StructureDefinition/C4DIC-Coverage":
if return_c4dic and profile == C4DIC_COVERAGE_PROFILE_URL:
return Response(get_response_json("bfd-c4dic-coverage-search"))
else:
return super().get(request, *args, **kwargs)
resp = super().get(request, *args, **kwargs)
# C4DIC POC: inject c4dic supportingImage extension if the _profile indicate C4DIC Coverage search
return enrich_supporting_image(resp) if profile == C4DIC_COVERAGE_PROFILE_URL else resp


class SearchViewExplanationOfBenefit(SearchView):
Expand Down
Loading
Loading