use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeBaseDefinition.
public static StructureDefinition makeBaseDefinition(FHIRVersion fhirVersion) {
StructureDefinition base = new StructureDefinition();
base.setId("Base");
base.setUrl("http://hl7.org/fhir/StructureDefinition/Base");
base.setVersion(fhirVersion.toCode());
base.setName("Base");
base.setStatus(PublicationStatus.ACTIVE);
base.setDate(new Date());
base.setFhirVersion(fhirVersion);
base.setKind(StructureDefinitionKind.COMPLEXTYPE);
base.setAbstract(true);
base.setType("Base");
ElementDefinition e = base.getSnapshot().getElementFirstRep();
e.setId("Base");
e.setPath("Base");
e.setMin(0);
e.setMax("*");
e.getBase().setPath("Base");
e.getBase().setMin(0);
e.getBase().setMax("*");
e.setIsModifier(false);
e = base.getDifferential().getElementFirstRep();
e.setId("Base");
e.setPath("Base");
e.setMin(0);
e.setMax("*");
return base;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project eCRNow by drajer-health.
the class LaunchController method getEncounterById.
public IBaseResource getEncounterById(LaunchDetails launchDetails) {
String fhirVersion = launchDetails.getFhirVersion();
String encounterId = launchDetails.getEncounterId();
IBaseResource encounterResource = null;
String EncounterError = "Error in getting Encounter resource by Id: " + encounterId;
logger.info("Getting Encounter data by ID {}", encounterId);
try {
FhirContext fhirContext = fhirContextInitializer.getFhirContext(fhirVersion);
IGenericClient fhirClient = fhirContextInitializer.createClient(fhirContext, launchDetails);
if (!StringUtils.isEmpty(encounterId)) {
return fhirClient.read().resource("Encounter").withId(encounterId).execute();
}
IBaseBundle bundle = fhirContextInitializer.getResourceByPatientId(launchDetails, fhirClient, fhirContext, "Encounter");
if (bundle != null && !bundle.isEmpty()) {
if (fhirVersion.equalsIgnoreCase(FhirVersionEnum.R4.toString())) {
Bundle r4Bundle = (Bundle) bundle;
Map<org.hl7.fhir.r4.model.Encounter, Date> encounterMap = new HashMap<>();
for (BundleEntryComponent entry : r4Bundle.getEntry()) {
org.hl7.fhir.r4.model.Encounter encounterEntry = (org.hl7.fhir.r4.model.Encounter) entry.getResource();
encounterId = encounterEntry.getIdElement().getIdPart();
logger.info("Received Encounter Id ========> {}", encounterId);
encounterMap.put(encounterEntry, encounterEntry.getMeta().getLastUpdated());
}
encounterResource = Collections.max(encounterMap.entrySet(), Map.Entry.comparingByValue()).getKey();
launchDetails.setEncounterId(encounterResource.getIdElement().getIdPart());
return encounterResource;
}
if (fhirVersion.equalsIgnoreCase(FhirVersionEnum.DSTU2.toString())) {
ca.uhn.fhir.model.dstu2.resource.Bundle dstu2Bundle = (ca.uhn.fhir.model.dstu2.resource.Bundle) bundle;
Map<Encounter, Date> encounterMap = new HashMap<>();
for (Entry entry : dstu2Bundle.getEntry()) {
Encounter encounterEntry = (Encounter) entry.getResource();
encounterId = encounterEntry.getIdElement().getIdPart();
logger.info("Received Encounter Id ========> {}", encounterId);
encounterMap.put(encounterEntry, encounterEntry.getMeta().getLastUpdated());
}
encounterResource = Collections.max(encounterMap.entrySet(), Map.Entry.comparingByValue()).getKey();
launchDetails.setEncounterId(encounterResource.getIdElement().getIdPart());
return encounterResource;
}
}
logger.error(EncounterError);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, EncounterError);
} catch (ResourceNotFoundException notFoundException) {
logger.error(EncounterError, notFoundException);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, EncounterError, notFoundException);
} catch (Exception e) {
logger.error(EncounterError, e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, EncounterError, e);
}
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class CqlRule method build.
private void build(HashMap<String, byte[]> cqlFiles, HashMap<String, byte[]> jsonElmFiles, HashMap<String, byte[]> xmlElmFiles) {
// build a list of all of the CQL Libraries
List<CqlRule.CqlLibrary> cqlLibraries = new ArrayList<>();
for (String fileName : cqlFiles.keySet()) {
logger.debug("CqlRule: file: " + fileName);
CqlRule.CqlLibrary cqlLibrary = new CqlRule.CqlLibrary();
cqlLibrary.cql = cqlFiles.get(fileName);
// only add those that are the right fhir version
String fhirVersionFromCql = getFhirVersionFromCqlFile(cqlLibrary.cql);
// last character of fhirVersion ("R4" => "4") and first character of FHIR version from file ("3.0.0" => "3")
if (fhirVersion.substring(fhirVersion.length() - 1).equalsIgnoreCase(fhirVersionFromCql.substring(0, 1))) {
String fileNameWithoutExtension = fileName.substring(0, fileName.length() - 4);
String xmlElmName = fileNameWithoutExtension + ".xml";
if (xmlElmFiles.containsKey(xmlElmName)) {
cqlLibrary.xlmElm = true;
cqlLibrary.elm = xmlElmFiles.get(xmlElmName);
}
String jsonElmName = fileNameWithoutExtension + ".json";
if (jsonElmFiles.containsKey(jsonElmName)) {
cqlLibrary.xlmElm = false;
cqlLibrary.elm = jsonElmFiles.get(jsonElmName);
}
cqlLibraries.add(cqlLibrary);
}
}
precompiled = false;
for (CqlLibrary cqlLibrary : cqlLibraries) {
if (precompiled) {
if (cqlLibrary.elm == null) {
throw new RuntimeException("Package indicated CQL was precompiled, but elm xml missing.");
}
// TODO: need to set rulePackage.elmLibraries and mainCqlLibraryId
} else {
InputStream cqlStream = new ByteArrayInputStream(cqlLibrary.cql);
VersionedIdentifier id = getIdFromCqlFile(cqlLibrary.cql);
String fhirVersionFromFile = getFhirVersionFromCqlFile(cqlLibrary.cql);
logger.info("CqlRule::Constructor() add id: " + id.getId() + ", fhir version: " + fhirVersionFromFile);
if (rawCqlLibraries.containsKey(fhirVersionFromFile)) {
// logger.info("CqlRule::Constructor() add rawCqlLibraries add: " + id.getId());
rawCqlLibraries.get(fhirVersionFromFile).put(id, cqlStream);
} else {
HashMap<VersionedIdentifier, InputStream> map = new HashMap<>();
map.put(id, cqlStream);
// logger.info("CqlRule::Constructor() add rawCqlLibraries new: " + id.getId());
rawCqlLibraries.put(fhirVersionFromFile, map);
}
if (id.getId().equals(mainCqlLibraryName)) {
// logger.info("CqlRule::Constructor() add mainCqlLibraryId: " + id.getId());
mainCqlLibraryId.put(fhirVersionFromFile, id);
}
}
}
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class FhirController method questionnaireForOrderOperation.
/**
* FHIR Operation to retrieve all of the Questionnaires and CQL files associated with a given request.
* @param fhirVersion (converted to uppercase)
* @return FHIR Bundle
* @throws IOException
*/
@PostMapping(path = "/fhir/{fhirVersion}/Questionnaire/$questionnaire-package", consumes = { MediaType.APPLICATION_JSON_VALUE, "application/fhir+json" })
public ResponseEntity<String> questionnaireForOrderOperation(HttpServletRequest request, HttpEntity<String> entity, @PathVariable String fhirVersion) {
fhirVersion = fhirVersion.toUpperCase();
String baseUrl = Utils.getApplicationBaseUrl(request).toString() + "/";
logger.info("POST /fhir/" + fhirVersion + "/Questionnaire/$Questionnaire-package");
String resource = null;
if (fhirVersion.equalsIgnoreCase("R4")) {
QuestionnairePackageOperation operation = new QuestionnairePackageOperation(fileStore, baseUrl);
resource = operation.execute(entity.getBody());
if (resource == null) {
logger.warning("bad parameters");
HttpStatus status = HttpStatus.BAD_REQUEST;
MediaType contentType = MediaType.TEXT_PLAIN;
return ResponseEntity.status(status).contentType(contentType).body("Bad Parameters");
}
} else {
logger.warning("unsupported FHIR version: " + fhirVersion + ", not storing");
HttpStatus status = HttpStatus.BAD_REQUEST;
MediaType contentType = MediaType.TEXT_PLAIN;
return ResponseEntity.status(status).contentType(contentType).body("Bad Request");
}
return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(resource);
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class FhirController method searchFhirResource.
/**
* Retrieve a FHIR resource by name.
* @param fhirVersion (converted to uppercase)
* @param resource (converted to lowercase)
* @param name (converted to lowercase)
* @param url The Canonical URL of the resource.
* @return
* @throws IOException
*/
// ?name={TopicFormName}
@GetMapping(path = "/fhir/{fhirVersion}/{resource}")
public ResponseEntity<Resource> searchFhirResource(HttpServletRequest request, @PathVariable String fhirVersion, @PathVariable String resource, @RequestParam(required = false) String name, @RequestParam(required = false) String url, @RequestParam(required = false) String topic) throws IOException {
fhirVersion = fhirVersion.toUpperCase();
resource = resource.toLowerCase();
String baseUrl = Utils.getApplicationBaseUrl(request).toString() + "/";
FileResource fileResource = null;
if (name != null) {
name = name.toLowerCase();
logger.info("GET /fhir/" + fhirVersion + "/" + resource + "?name=" + name);
fileResource = fileStore.getFhirResourceByName(fhirVersion, resource, name, baseUrl);
} else if (url != null) {
logger.info("GET /fhir/" + fhirVersion + "/" + resource + "?url=" + url);
fileResource = fileStore.getFhirResourceByUrl(fhirVersion, resource, url, baseUrl);
} else if (topic != null) {
topic = topic.toLowerCase();
logger.info("GET /fhir/" + fhirVersion + "/" + resource + "?topic=" + topic);
fileResource = fileStore.getFhirResourcesByTopicAsBundle(fhirVersion, resource, topic, baseUrl);
}
return processFileResource(fileResource);
}
Aggregations