use of org.hl7.fhir.r4b.formats.IParser in project beneficiary-fhir-data by CMSgov.
the class OutpatientClaimTransformerV2Test method before.
@BeforeEach
public void before() {
claim = generateClaim();
ExplanationOfBenefit genEob = OutpatientClaimTransformerV2.transform(new MetricRegistry(), claim, Optional.empty());
IParser parser = fhirContext.newJsonParser();
String json = parser.encodeResourceToString(genEob);
eob = parser.parseResource(ExplanationOfBenefit.class, json);
}
use of org.hl7.fhir.r4b.formats.IParser in project health-patterns by LinuxForHealth.
the class DeIdentifier method postResource.
/**
* Posts the given Resource to the FHIR server
*
* @param fhirResource the resource to post
* @return the FHIR response of executing the POST operation
* @throws DeIdentifierException if there is a problem posting the resource
*/
@SuppressWarnings("unchecked")
private String postResource(JsonNode fhirResource) throws DeIdentifierException {
System.out.println("Initializing FHIR create resource...");
IParser parser = fhirClient.getFhirContext().newJsonParser();
// We don't know exactly what type of Resource we are going to POST to FHiR and the FHIR requires
// that when parsing a Resource a concrete class is used, so we load the concrete type reflexively
ClassLoader classLoader = this.getClass().getClassLoader();
Class<? extends Resource> aClass = null;
String resourceType = getResourceType(fhirResource);
try {
aClass = (Class<? extends Resource>) classLoader.loadClass("org.hl7.fhir.r4.model." + resourceType);
} catch (ClassNotFoundException e) {
throw new DeIdentifierException("A Resource of type '" + resourceType + "' could not be found in the current HAPI FHIR JAR: " + e.getMessage(), e);
}
Resource resource = parser.parseResource(aClass, fhirResource.toString());
MethodOutcome outcome;
try {
outcome = fhirClient.create().resource(resource).encodedJson().execute();
} catch (BaseServerResponseException e) {
throw new DeIdentifierException("The FHIR transaction could not be executed: " + e.getMessage(), e);
}
System.out.println("FHIR create resource done!");
return outcome.getId().toString();
}
use of org.hl7.fhir.r4b.formats.IParser in project health-patterns by LinuxForHealth.
the class CohortService method getPatientsForCohort.
/**
* Gets the FHIR response with the patients that matched the cohort defined by the given library ID.
*
* @param libraryID the library ID
* @param patientsSubset the subset of patients over which to execute the cohort
* @param reverseMatch run the CQL such that only the patients that don't match it are returned
* @return the FHIR JSON response (a Bundle) with all the patients that matched
* @throws CQLExecutionException if there is a problem executing the library
*/
public String getPatientsForCohort(String libraryID, List<String> patientsSubset, boolean reverseMatch) throws CQLExecutionException {
List<String> cohortPatients = getPatientIdsForCohort(libraryID, patientsSubset, reverseMatch);
if (cohortPatients == null) {
return null;
}
String theSearchUrl = fhir.getServerBase() + "/Patient?_id=" + String.join(",", cohortPatients);
Bundle cohortBundle = fhir.search().byUrl(theSearchUrl).returnBundle(Bundle.class).execute();
IParser parser = fhir.getFhirContext().newJsonParser();
String serialized = parser.encodeResourceToString(cohortBundle);
return serialized;
}
use of org.hl7.fhir.r4b.formats.IParser in project BridgeServer2 by Sage-Bionetworks.
the class CRCController method postAppointment.
@PutMapping("/v1/cuimc/appointments")
public ResponseEntity<StatusMessage> postAppointment() {
App app = httpBasicAuthentication();
IParser parser = FHIR_CONTEXT.newJsonParser();
JsonNode data = parseJson(JsonNode.class);
Appointment appointment = parser.parseResource(Appointment.class, data.toString());
String userId = findUserId(appointment);
// They send appointment when it is booked, cancelled, or (rarely) enteredinerror.
AccountStates state = TESTS_SCHEDULED;
String apptStatus = data.get("status").asText();
if ("entered-in-error".equals(apptStatus)) {
deleteReportAndUpdateState(app, userId);
return ResponseEntity.ok(new StatusMessage("Appointment deleted."));
} else if ("cancelled".equals(apptStatus)) {
state = TESTS_CANCELLED;
}
// Columbia wants us to call back to them to get information about the location.
// And UI team wants geocoding of location to render a map.
String locationString = findLocation(appointment);
if (locationString != null) {
AccountId accountId = parseAccountId(app.getIdentifier(), userId);
Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
addLocation(data, account, locationString);
}
int status = writeReportAndUpdateState(app, userId, data, APPOINTMENT_REPORT, state, true);
if (status == 200) {
return ResponseEntity.ok(new StatusMessage("Appointment updated (status = " + apptStatus + ")."));
}
return ResponseEntity.created(URI.create("/v1/cuimc/appointments/" + userId)).body(new StatusMessage("Appointment created (status = " + apptStatus + ")."));
}
use of org.hl7.fhir.r4b.formats.IParser in project BridgeServer2 by Sage-Bionetworks.
the class CRCController method postObservation.
@PutMapping("/v1/cuimc/observations")
public ResponseEntity<StatusMessage> postObservation() {
App app = httpBasicAuthentication();
IParser parser = FHIR_CONTEXT.newJsonParser();
JsonNode data = parseJson(JsonNode.class);
Observation observation = parser.parseResource(Observation.class, data.toString());
AccountStates state = TESTS_AVAILABLE;
// There are two conditions under which the type of report is considered to be unknown. Either the code
// is for a test other than the serum test, or the result value is not recognized by our client application,
// and that's also treated as an unknown type of report.
String code = getObservationCoding(observation);
String valueString = getObservationValue(observation);
if (code == null || valueString == null || !SERUM_TEST_CODES.contains(code) || !SERUM_TEST_STATES.contains(valueString)) {
state = TESTS_AVAILABLE_TYPE_UNKNOWN;
LOG.warn("CRC observation in unknown format: code=" + code + ", valueString=" + valueString);
}
String userId = findUserId(observation.getSubject());
int status = writeReportAndUpdateState(app, userId, data, OBSERVATION_REPORT, state, true);
if (status == 200) {
return ResponseEntity.ok(new StatusMessage("Observation updated."));
}
return ResponseEntity.created(URI.create("/v1/cuimc/observations/" + userId)).body(new StatusMessage("Observation created."));
}
Aggregations