Search in sources :

Example 1 with InstantDt

use of ca.uhn.fhir.model.primitive.InstantDt in project gpconnect-demonstrator by nhsconnect.

the class SlotResourceProvider method validateStartDateParamAndEndDateParam.

private void validateStartDateParamAndEndDateParam(DateParam startDate, DateParam endDate) {
    Pattern dateTimePattern = Pattern.compile(SystemVariable.DATE_TIME_REGEX);
    Pattern dateOnlyPattern = Pattern.compile(SystemVariable.DATE_REGEX);
    String startString = startDate.getValueAsString();
    String endString = endDate.getValueAsString();
    validateOffset("start", startDate);
    validateOffset("end", endDate);
    // If the time is included then match against the date/time regex
    if ((startDate.getPrecision().getCalendarConstant() > TemporalPrecisionEnum.DAY.getCalendarConstant() && !dateTimePattern.matcher(startString).matches()) || (endDate.getPrecision().getCalendarConstant() > TemporalPrecisionEnum.DAY.getCalendarConstant() && !dateTimePattern.matcher(endString).matches())) {
        throwUnprocessableEntityInvalid422_ParameterException("Invalid date/time used");
    } else // if only a date then match against the date regex
    if ((startDate.getPrecision().getCalendarConstant() <= TemporalPrecisionEnum.DAY.getCalendarConstant() && !dateOnlyPattern.matcher(startString).matches()) || (endDate.getPrecision().getCalendarConstant() <= TemporalPrecisionEnum.DAY.getCalendarConstant() && !dateOnlyPattern.matcher(endString).matches())) {
        throwUnprocessableEntityInvalid422_ParameterException("Invalid date used");
    }
    InstantDt instantDt = startDate.getValueAsInstantDt();
    InstantDt instantDt2 = endDate.getValueAsInstantDt();
    if (instantDt != null && instantDt2 != null) {
        Date start = instantDt.getValue();
        Date end = instantDt2.getValue();
        if (start != null && end != null) {
            long period = ChronoUnit.DAYS.between(start.toInstant(), end.toInstant());
            if (period < 0l || period > 14l) {
                throwUnprocessableEntityInvalid422_ParameterException("Invalid time period, was " + period + " days between (max is 14)");
            }
        } else {
            throwUnprocessableEntity422_BadRequestException("Invalid timePeriod one or both of start and end date are not valid dates");
        }
    } else {
        throwUnprocessableEntityInvalid422_ParameterException("Invalid timePeriod one or both of start and end date were missing");
    }
}
Also used : Pattern(java.util.regex.Pattern) Date(java.util.Date) InstantDt(ca.uhn.fhir.model.primitive.InstantDt)

Example 2 with InstantDt

use of ca.uhn.fhir.model.primitive.InstantDt in project synthea by synthetichealth.

the class FhirDstu2 method report.

/**
 * Map the given Report to a FHIR DiagnosticReport resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Entry for the Person
 * @param bundle
 *          Bundle to add the Report to
 * @param encounterEntry
 *          Current Encounter entry
 * @param report
 *          The Report
 * @return The added Entry
 */
private static Entry report(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Report report) {
    DiagnosticReport reportResource = new DiagnosticReport();
    reportResource.setStatus(DiagnosticReportStatusEnum.FINAL);
    /*
     * Technically, the CodeableConcept system should be "http://hl7.org/fhir/v2/0074"
     * But the official Argonauts profiles incorrectly list the category pattern as
     * the ValueSet (which contains the above system) as
     * "http://hl7.org/fhir/ValueSet/diagnostic-service-sections", so we repeat the
     * error here.
     */
    CodeableConceptDt category = new CodeableConceptDt("http://hl7.org/fhir/ValueSet/diagnostic-service-sections", "LAB");
    reportResource.setCategory(category);
    reportResource.setCode(mapCodeToCodeableConcept(report.codes.get(0), LOINC_URI));
    reportResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    reportResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    reportResource.setEffective(convertFhirDateTime(report.start, true));
    reportResource.setIssued(new InstantDt(new Date(report.start)));
    ca.uhn.fhir.model.dstu2.resource.Encounter encounter = (ca.uhn.fhir.model.dstu2.resource.Encounter) encounterEntry.getResource();
    reportResource.setPerformer(encounter.getServiceProvider());
    for (Observation observation : report.observations) {
        ResourceReferenceDt reference = new ResourceReferenceDt(observation.fullUrl);
        reference.setDisplay(observation.codes.get(0).display);
        List<ResourceReferenceDt> result = new ArrayList<ResourceReferenceDt>();
        result.add(reference);
        reportResource.setResult(result);
    }
    return newEntry(rand, bundle, reportResource);
}
Also used : CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) ArrayList(java.util.ArrayList) DiagnosticReport(ca.uhn.fhir.model.dstu2.resource.DiagnosticReport) Date(java.util.Date) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) InstantDt(ca.uhn.fhir.model.primitive.InstantDt)

Example 3 with InstantDt

use of ca.uhn.fhir.model.primitive.InstantDt in project synthea by synthetichealth.

the class FhirDstu2 method observation.

/**
 * Map the given Observation into a FHIR Observation resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Person Entry
 * @param bundle
 *          The Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param observation
 *          The Observation
 * @return The added Entry
 */
private static Entry observation(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Observation observation) {
    ca.uhn.fhir.model.dstu2.resource.Observation observationResource = new ca.uhn.fhir.model.dstu2.resource.Observation();
    observationResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    observationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    observationResource.setStatus(ObservationStatusEnum.FINAL);
    Code code = observation.codes.get(0);
    observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
    Code category = new Code("http://hl7.org/fhir/observation-category", observation.category, observation.category);
    observationResource.setCategory(mapCodeToCodeableConcept(category, "http://hl7.org/fhir/observation-category"));
    if (observation.value != null) {
        IDatatype value = mapValueToFHIRType(observation.value, observation.unit);
        observationResource.setValue(value);
    } else if (observation.observations != null && !observation.observations.isEmpty()) {
        // multi-observation (ex blood pressure)
        for (Observation subObs : observation.observations) {
            Component comp = new Component();
            comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
            IDatatype value = mapValueToFHIRType(subObs.value, subObs.unit);
            comp.setValue(value);
            observationResource.addComponent(comp);
        }
    }
    observationResource.setEffective(convertFhirDateTime(observation.start, true));
    observationResource.setIssued(new InstantDt(new Date(observation.start)));
    Entry entry = newEntry(rand, bundle, observationResource);
    observation.fullUrl = entry.getFullUrl();
    return entry;
}
Also used : IDatatype(ca.uhn.fhir.model.api.IDatatype) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Component(ca.uhn.fhir.model.dstu2.resource.Observation.Component) InstantDt(ca.uhn.fhir.model.primitive.InstantDt)

Aggregations

InstantDt (ca.uhn.fhir.model.primitive.InstantDt)3 Date (java.util.Date)3 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)2 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)2 IDatatype (ca.uhn.fhir.model.api.IDatatype)1 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)1 Component (ca.uhn.fhir.model.dstu2.resource.Observation.Component)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)1