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

Pass resource filters to optimize fetch requests #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ public FhirContext getFhirContext() {
return fhirContext;
}

/**
* TODO - Activate sending data througn IL
*/
public IGenericClient getFhirClient() throws Exception {
FhirContext fhirContextNew = FhirContext.forR4();
fhirContextNew.getRestfulClientFactory().setSocketTimeout(200 * 1000);
BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(ILUtils.getShrToken());
// BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(ILUtils.getShrToken());
IGenericClient client = fhirContextNew.getRestfulClientFactory().newGenericClient(ILUtils.getShrServerUrl());
client.registerInterceptor(authInterceptor);
// client.registerInterceptor(authInterceptor);
return client;
}

Expand Down Expand Up @@ -187,12 +190,12 @@ public Bundle fetchEncounterResource(Patient patient) {
}
}

public Bundle fetchObservationResource(String patientId) {
public Bundle fetchObservationResource(String patientId, String obsCategory) {
try {
String encodedParam2 = URLEncoder.encode(patientId, "UTF-8");

String url = ILUtils.getShrServerUrl() + "Observation?subject:Patient=Patient/"
+ patientId;
+ patientId + "&category="+obsCategory;
URL localUrl = new URL(url);

IGenericClient client = getFhirClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,59 +48,62 @@ public static SimpleObject constructSHrSummary(String patientUuid) throws Malfor
String patientUniqueNumber = upi.get(0).getIdentifier();

Bundle diagnosisBundle = fhirConfig.fetchConditions(patientUniqueNumber,
"http://terminology.hl7.org/CodeSystem/condition-category|encounter-diagnosis");
"encounter-diagnosis");

Bundle conditionsBundle = fhirConfig.fetchConditions(patientUniqueNumber,
"http://terminology.hl7.org/CodeSystem/condition-category|conditions");
"problem-list-item");


Bundle allergyBundle = fhirConfig.fetchPatientAllergies(patientUniqueNumber);

Bundle referralsBundle = fhirConfig.fetchPatientReferrals(patientUniqueNumber);

Bundle allObs = fhirConfig.fetchObservationResource(patientUniqueNumber);
Bundle vitalsObs = fhirConfig.fetchObservationResource(patientUniqueNumber, "vital-signs");

if (allObs != null && allObs.getEntry() != null && !allObs.getEntry().isEmpty()) {
for (Bundle.BundleEntryComponent resource : allObs.getEntry()) {
Observation observation = (Observation) resource.getResource();
Bundle labResultsObs = fhirConfig.fetchObservationResource(patientUniqueNumber, "laboratory");

if (observation.hasCode() && observation.getCode().hasCoding() && observation.hasCategory() &&
observation.getCategoryFirstRep().hasCoding() &&
observation.getCategoryFirstRep().getCodingFirstRep().getCode().equals("vital-signs")) {
SimpleObject local = new SimpleObject();
local.put("uuid", observation.getId().split("/")[4]);
local.put("name", observation.getCode().getCodingFirstRep().getDisplay());
local.put("dateRecorded", observation.getIssued() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(observation.getIssued()) : "");
local.put("value", fhirValueProcessor(observation.getValue()));
vitals.add(local);
}
Bundle examObs = fhirConfig.fetchObservationResource(patientUniqueNumber, "exam");

if (observation.hasCode() && observation.getCode().hasCoding() && observation.hasCategory()
&& observation.getCategoryFirstRep().hasCoding() &&
observation.getCategoryFirstRep().getCodingFirstRep().getCode().equals("laboratory")) {
SimpleObject local = new SimpleObject();
local.put("uuid", observation.getId().split("/")[4]);
local.put("name", observation.getCode().getCodingFirstRep().getDisplay());
local.put("dateRecorded", observation.getIssued() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(observation.getIssued()) : "");
local.put("value", fhirValueProcessor(observation.getValue()));
labResults.add(local);
}

if (observation.hasCode() && observation.getCode().hasCoding() && observation.hasCategory() &&
observation.getCategoryFirstRep().hasCoding() &&
observation.getCategoryFirstRep().getCodingFirstRep().getCode().equals("exam")) {
SimpleObject local = new SimpleObject();
local.put("uuid", observation.getId().split("/")[4]);
local.put("name", observation.getCode().getCodingFirstRep().getDisplay());
local.put("dateRecorded", observation.getIssued() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(observation.getIssued()) : "");
local.put("onsetDate", "");
local.put("value", fhirValueProcessor(observation.getValue()));
complaints.add(local);
}
for (Bundle.BundleEntryComponent resource : vitalsObs.getEntry()) {
Observation observation = (Observation) resource.getResource();

if (observation.hasCode() && observation.getCode().hasCoding()) {
SimpleObject local = new SimpleObject();
local.put("uuid", observation.getId().split("/")[4]);
local.put("name", observation.getCode().getCodingFirstRep().getDisplay());
local.put("dateRecorded", observation.getIssued() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(observation.getIssued()) : "");
local.put("value", fhirValueProcessor(observation.getValue()));
vitals.add(local);
}
}

for (Bundle.BundleEntryComponent resource : labResultsObs.getEntry()) {
Observation observation = (Observation) resource.getResource();

if (observation.hasCode() && observation.getCode().hasCoding()) {
SimpleObject local = new SimpleObject();
local.put("uuid", observation.getId().split("/")[4]);
local.put("name", observation.getCode().getCodingFirstRep().getDisplay());
local.put("dateRecorded", observation.getIssued() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(observation.getIssued()) : "");
local.put("value", fhirValueProcessor(observation.getValue()));
labResults.add(local);
}
}

for (Bundle.BundleEntryComponent resource : examObs.getEntry()) {
Observation observation = (Observation) resource.getResource();

if (observation.hasCode() && observation.getCode().hasCoding()) {
SimpleObject local = new SimpleObject();
local.put("uuid", observation.getId().split("/")[4]);
local.put("name", observation.getCode().getCodingFirstRep().getDisplay());
local.put("dateRecorded", observation.getIssued() != null ?
new SimpleDateFormat("yyyy-MM-dd").format(observation.getIssued()) : "");
local.put("value", fhirValueProcessor(observation.getValue()));
complaints.add(local);
}
}

Expand Down