Search in sources :

Example 71 with CodeType

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;
}
Also used : ResourceInteractionComponent(org.hl7.fhir.r4.model.CapabilityStatement.ResourceInteractionComponent) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) CodeType(org.hl7.fhir.r4.model.CodeType) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) CapabilityStatementRestResourceComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceComponent) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CapabilityStatementRestResourceOperationComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceOperationComponent) Nonnull(javax.annotation.Nonnull)

Example 72 with CodeType

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;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) CapabilityStatementImplementationComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementImplementationComponent) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) CapabilityStatementSoftwareComponent(org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementSoftwareComponent) CodeType(org.hl7.fhir.r4.model.CodeType) Metadata(ca.uhn.fhir.rest.annotation.Metadata)

Example 73 with CodeType

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);
}
Also used : ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) UrlType(org.hl7.fhir.r4.model.UrlType) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) File(java.io.File) ComponentScan(org.springframework.context.annotation.ComponentScan) ImportExecutor(au.csiro.pathling.update.ImportExecutor) Objects(java.util.Objects) SpringApplication(org.springframework.boot.SpringApplication) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) FileFilter(java.io.FileFilter) Stream(java.util.stream.Stream) WildcardFileFilter(jodd.io.filter.WildcardFileFilter) Parameters(org.hl7.fhir.r4.model.Parameters) CodeType(org.hl7.fhir.r4.model.CodeType) CommandLineRunner(org.springframework.boot.CommandLineRunner) Nonnull(javax.annotation.Nonnull) FilenameUtils(org.apache.commons.io.FilenameUtils) SparkSession(org.apache.spark.sql.SparkSession) Parameters(org.hl7.fhir.r4.model.Parameters) CodeType(org.hl7.fhir.r4.model.CodeType) ResourceType(org.hl7.fhir.r4.model.Enumerations.ResourceType) FileFilter(java.io.FileFilter) WildcardFileFilter(jodd.io.filter.WildcardFileFilter) File(java.io.File) WildcardFileFilter(jodd.io.filter.WildcardFileFilter) UrlType(org.hl7.fhir.r4.model.UrlType) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 74 with CodeType

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;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) Period(org.hl7.fhir.r4.model.Period) CodeType(org.hl7.fhir.r4.model.CodeType) List(java.util.List) ArrayList(java.util.ArrayList) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 75 with CodeType

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();
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Observation(org.hl7.fhir.r4.model.Observation) CodeType(org.hl7.fhir.r4.model.CodeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

CodeType (org.hl7.fhir.r5.model.CodeType)52 ArrayList (java.util.ArrayList)31 CodeType (org.hl7.fhir.r4.model.CodeType)28 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 CodeType (org.hl7.fhir.r4b.model.CodeType)17 Date (java.util.Date)15 CodeType (org.hl7.fhir.dstu3.model.CodeType)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 File (java.io.File)11 Extension (org.hl7.fhir.dstu3.model.Extension)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)10 StringType (org.hl7.fhir.r5.model.StringType)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 Coding (org.hl7.fhir.r4.model.Coding)9 Coding (org.hl7.fhir.dstu3.model.Coding)8 FileOutputStream (java.io.FileOutputStream)7 List (java.util.List)7 Parameters (org.hl7.fhir.r4.model.Parameters)7 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)7