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");
}
}
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);
}
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;
}
Aggregations