use of org.hl7.fhir.r4.model.CodeType in project pathling by aehrc.
the class ConformanceProvider method buildResources.
@Nonnull
private List<CapabilityStatementRestResourceComponent> buildResources() {
final List<CapabilityStatementRestResourceComponent> resources = new ArrayList<>();
final Set<ResourceType> supported = FhirServer.supportedResourceTypes();
final Set<ResourceType> supportedResourceTypes = supported.isEmpty() ? EnumSet.noneOf(ResourceType.class) : EnumSet.copyOf(supported);
for (final ResourceType resourceType : supportedResourceTypes) {
final CapabilityStatementRestResourceComponent resource = new CapabilityStatementRestResourceComponent(new CodeType(resourceType.toCode()));
resource.setProfile(FHIR_RESOURCE_BASE + resourceType.toCode());
// Add the search operation to all resources.
final ResourceInteractionComponent search = new ResourceInteractionComponent();
search.setCode(TypeRestfulInteraction.SEARCHTYPE);
resource.getInteraction().add(search);
// Add the create and update operations to all resources.
final ResourceInteractionComponent create = new ResourceInteractionComponent();
final ResourceInteractionComponent update = new ResourceInteractionComponent();
create.setCode(TypeRestfulInteraction.CREATE);
update.setCode(TypeRestfulInteraction.UPDATE);
resource.getInteraction().add(create);
resource.getInteraction().add(update);
// Add the `aggregate` operation to all resources.
final CanonicalType aggregateOperationUri = new CanonicalType(getOperationUri("aggregate"));
final CapabilityStatementRestResourceOperationComponent aggregateOperation = new CapabilityStatementRestResourceOperationComponent(new StringType("aggregate"), aggregateOperationUri);
resource.addOperation(aggregateOperation);
// Add the `fhirPath` search parameter to all resources.
final CapabilityStatementRestResourceOperationComponent searchOperation = new CapabilityStatementRestResourceOperationComponent();
searchOperation.setName("fhirPath");
searchOperation.setDefinition(getOperationUri("search"));
resource.addOperation(searchOperation);
resources.add(resource);
}
// Add the read operation to the OperationDefinition resource.
final String opDefCode = ResourceType.OPERATIONDEFINITION.toCode();
final CapabilityStatementRestResourceComponent opDefResource = new CapabilityStatementRestResourceComponent(new CodeType(opDefCode));
opDefResource.setProfile(FHIR_RESOURCE_BASE + opDefCode);
final ResourceInteractionComponent readInteraction = new ResourceInteractionComponent();
readInteraction.setCode(TypeRestfulInteraction.READ);
opDefResource.addInteraction(readInteraction);
resources.add(opDefResource);
return resources;
}
use of org.hl7.fhir.r4.model.CodeType in project pathling by aehrc.
the class ConformanceProvider method getServerConformance.
@Override
@Metadata(cacheMillis = 0)
public CapabilityStatement getServerConformance(@Nullable final HttpServletRequest httpServletRequest, @Nullable final RequestDetails requestDetails) {
log.debug("Received request for server capabilities");
final CapabilityStatement capabilityStatement = new CapabilityStatement();
capabilityStatement.setUrl(getCapabilityUri());
capabilityStatement.setVersion(version.getBuildVersion().orElse(UNKNOWN_VERSION));
capabilityStatement.setTitle("Pathling FHIR API");
capabilityStatement.setName("pathling-fhir-api");
capabilityStatement.setStatus(PublicationStatus.ACTIVE);
capabilityStatement.setExperimental(true);
capabilityStatement.setPublisher("Australian e-Health Research Centre, CSIRO");
capabilityStatement.setCopyright("Dedicated to the public domain via CC0: https://creativecommons.org/publicdomain/zero/1.0/");
capabilityStatement.setKind(CapabilityStatementKind.INSTANCE);
final CapabilityStatementSoftwareComponent software = new CapabilityStatementSoftwareComponent(new StringType("Pathling"));
software.setVersion(version.getDescriptiveVersion().orElse(UNKNOWN_VERSION));
capabilityStatement.setSoftware(software);
final CapabilityStatementImplementationComponent implementation = new CapabilityStatementImplementationComponent(new StringType(configuration.getImplementationDescription()));
final Optional<String> serverBase = getServerBase(Optional.ofNullable(httpServletRequest));
serverBase.ifPresent(implementation::setUrl);
capabilityStatement.setImplementation(implementation);
capabilityStatement.setFhirVersion(FHIRVersion._4_0_1);
capabilityStatement.setFormat(Arrays.asList(new CodeType("json"), new CodeType("xml")));
capabilityStatement.setRest(buildRestComponent());
return capabilityStatement;
}
use of org.hl7.fhir.r4.model.CodeType in project pathling by aehrc.
the class TestDataImporter method run.
@Override
public void run(final String... args) {
final String sourcePath = args[0];
final File srcNdJsonDir = new File(sourcePath);
final FileFilter fileFilter = new WildcardFileFilter("*.ndjson");
final File[] srcNdJsonFiles = srcNdJsonDir.listFiles(fileFilter);
final List<ParametersParameterComponent> sources = Stream.of(Objects.requireNonNull(srcNdJsonFiles)).map(file -> {
final String resourceName = FilenameUtils.getBaseName(file.getName());
final ResourceType subjectResource = ResourceType.valueOf(resourceName.toUpperCase());
final ParametersParameterComponent source = new ParametersParameterComponent();
source.setName("source");
final ParametersParameterComponent resourceType = new ParametersParameterComponent();
resourceType.setName("resourceType");
resourceType.setValue(new CodeType(subjectResource.toCode()));
source.addPart(resourceType);
final ParametersParameterComponent url = new ParametersParameterComponent();
url.setName("url");
url.setValue(new UrlType("file://" + file.toPath()));
source.addPart(url);
return source;
}).collect(Collectors.toList());
final Parameters parameters = new Parameters();
parameters.setParameter(sources);
importExecutor.execute(parameters);
}
use of org.hl7.fhir.r4.model.CodeType in project eCRNow by drajer-health.
the class CdaFhirUtilities method getXmlForType.
public static String getXmlForType(Type dt, String elName, Boolean valFlag) {
String val = "";
if (dt != null) {
if (dt instanceof Coding) {
Coding cd = (Coding) dt;
List<Coding> cds = new ArrayList<>();
cds.add(cd);
if (!valFlag)
val += getCodingXml(cds, elName, "");
else
val += getCodingXmlForValue(cds, elName);
} else if (dt instanceof CodeableConcept) {
CodeableConcept cd = (CodeableConcept) dt;
List<Coding> cds = cd.getCoding();
if (!valFlag)
val += getCodingXml(cds, elName, "");
else
val += getCodingXmlForValue(cds, elName);
} else if (dt instanceof Quantity) {
Quantity qt = (Quantity) dt;
val += getQuantityXml(qt, elName, valFlag);
} else if (dt instanceof DateTimeType) {
DateTimeType d = (DateTimeType) dt;
val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
} else if (dt instanceof Period) {
Period pt = (Period) dt;
val += getPeriodXml(pt, elName);
} else if (dt instanceof Timing) {
Timing t = (Timing) (dt);
if (t.getRepeat() != null && t.getRepeat().getBounds() != null) {
logger.debug("Found the bounds element for creating xml");
String v = getXmlForType(t.getRepeat().getBounds(), elName, valFlag);
val += v;
}
} else if (dt instanceof CodeType) {
CodeType cd = (CodeType) dt;
if (!valFlag)
val += CdaGeneratorUtils.getXmlForCD(elName, cd.getCode());
else
val += CdaGeneratorUtils.getXmlForValueString(cd.getCode());
} else if (dt instanceof StringType) {
StringType st = (StringType) dt;
if (!valFlag)
val += CdaGeneratorUtils.getXmlForText(elName, st.getValue());
else
val += CdaGeneratorUtils.getXmlForValueString(st.getValue());
}
logger.debug("Printing the class name {}", dt.getClass());
return val;
}
if (!valFlag)
val += CdaGeneratorUtils.getNFXMLForElement(elName, CdaGeneratorConstants.NF_NI);
else
val += CdaGeneratorUtils.getNFXmlForValueString(CdaGeneratorConstants.NF_NI);
return val;
}
use of org.hl7.fhir.r4.model.CodeType in project eCRNow by drajer-health.
the class CdaSocialHistoryGenerator method generateSocialHistorySection.
public static String generateSocialHistorySection(R4FhirData data, LaunchDetails details) {
StringBuilder sb = new StringBuilder(2000);
// Will have to wait to discuss with vendors on Travel History, Pregnancy, and Birth Sex
// Observations.
// Then we can generte the entries. Till then it will be empty section.
CodeType birthSex = CdaFhirUtilities.getCodeExtension(data.getPatient().getExtension(), CdaGeneratorConstants.FHIR_USCORE_BIRTHSEX_EXT_URL);
List<Observation> pregObs = data.getPregnancyObs();
List<Condition> pregCond = data.getPregnancyConditions();
List<Observation> travelHistory = data.getTravelObs();
List<Observation> occHistory = data.getOccupationObs();
if (birthSex != null || (pregObs != null && !pregObs.isEmpty()) || (pregCond != null && !pregCond.isEmpty()) || (occHistory != null && !occHistory.isEmpty()) || (travelHistory != null && !travelHistory.isEmpty())) {
sb.append(generateSocialHistorySectionHeader(""));
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
// Create Table Header.
List<String> list = new ArrayList<>();
list.add(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_TITLE);
list.add(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_TITLE);
sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
// Add Table Body
sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
String birthSexXml = "";
String pregObsXml = "";
StringBuilder pregCondXml = new StringBuilder();
StringBuilder occHistoryXml = new StringBuilder();
StringBuilder travelHistoryXml = new StringBuilder();
int index = 0;
Map<String, String> bodyvals = new LinkedHashMap<>();
if (birthSex != null) {
logger.info("Found Birth Sex");
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_BODY_CONTENT, CdaGeneratorConstants.BIRTH_SEX_DISPLAY);
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_BODY_CONTENT, CdaFhirUtilities.getStringForType(birthSex));
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, index));
index++;
birthSexXml = generateBirthSexEntry(birthSex);
}
if (pregCond != null && !pregCond.isEmpty()) {
logger.info("Pregnancy Condition Found");
for (Condition c : pregCond) {
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_BODY_CONTENT, CdaGeneratorConstants.PREGNANCY_CONDITION_DISPLAY);
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_BODY_CONTENT, CdaFhirUtilities.getCodeableConceptDisplayForCodeSystem(c.getCode(), CdaGeneratorConstants.FHIR_SNOMED_URL, true).getValue0());
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, index));
index++;
pregCondXml.append(generatePregnancyEntry(c));
}
}
if (pregObs != null && !pregObs.isEmpty()) {
logger.info("Pregnancy Status Observation Found - Will be added as needed.");
// These are not available in FHIR right now reliably, so nothing to process until further
// discussion with vendors.
// Setup Table Text Entries
// Setup XML Entries
}
if (occHistory != null && !occHistory.isEmpty()) {
logger.info("Occupation History Observation Found");
for (Observation obs : occHistory) {
if (obs.getValue() != null && (obs.getValue() instanceof StringType || obs.getValue() instanceof CodeableConcept)) {
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_BODY_CONTENT, CdaGeneratorConstants.OCCUPATION_HISTORY_DISPLAY);
String display = CdaFhirUtilities.getStringForType(obs.getValue());
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_BODY_CONTENT, display);
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, index));
index++;
occHistoryXml.append(generateOccHistoryEntry(obs));
}
}
}
if (travelHistory != null && !travelHistory.isEmpty()) {
logger.info("Travel History Observation Found ");
for (Observation obs : travelHistory) {
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_BODY_CONTENT, CdaGeneratorConstants.TRAVEL_HISTORY_DISPLAY);
String display = CdaFhirUtilities.getCombinationStringForCodeSystem(obs.getCode(), obs.getValue(), CdaGeneratorConstants.FHIR_SNOMED_URL, true);
bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_BODY_CONTENT, display);
sb.append(CdaGeneratorUtils.addTableRow(bodyvals, index));
index++;
travelHistoryXml.append(generateTravelHistoryEntry(obs, display));
}
}
// Close the Table.
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
// Add entry
if (!StringUtils.isEmpty(birthSexXml)) {
sb.append(birthSexXml);
}
if (!StringUtils.isEmpty(pregCondXml)) {
sb.append(pregCondXml);
}
if (!StringUtils.isEmpty(pregObsXml)) {
sb.append(pregObsXml);
}
if (!StringUtils.isEmpty(occHistoryXml)) {
sb.append(occHistoryXml);
}
if (!StringUtils.isEmpty(travelHistoryXml)) {
sb.append(travelHistoryXml);
}
sb.append(generateSocialHistorySectionEndHeader());
} else {
sb.append(generateEmptySocialHistorySection());
}
return sb.toString();
}
Aggregations