use of org.hl7.fhir.dstu3.model.DateTimeType in project bunsen by cerner.
the class TestData method newCondition.
/**
* Returns a FHIR Condition for testing purposes.
*/
public static Condition newCondition() {
Condition condition = new Condition();
// Condition based on example from FHIR:
// https://www.hl7.org/fhir/condition-example.json.html
condition.setId("Condition/example");
condition.setLanguage("en_US");
// Narrative text
Narrative narrative = new Narrative();
narrative.setStatusAsString("generated");
narrative.setDivAsString("This data was generated for test purposes.");
XhtmlNode node = new XhtmlNode();
node.setNodeType(NodeType.Text);
node.setValue("Severe burn of left ear (Date: 24-May 2012)");
condition.setText(narrative);
condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));
condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);
// Condition code
CodeableConcept code = new CodeableConcept();
code.addCoding().setSystem("http://snomed.info/sct").setCode("39065001").setDisplay("Severe");
condition.setSeverity(code);
// Severity code
CodeableConcept severity = new CodeableConcept();
severity.addCoding().setSystem("http://snomed.info/sct").setCode("24484000").setDisplay("Burn of ear").setUserSelected(true);
condition.setSeverity(severity);
// Onset date time
DateTimeType onset = new DateTimeType();
onset.setValueAsString("2012-05-24");
condition.setOnset(onset);
return condition;
}
use of org.hl7.fhir.dstu3.model.DateTimeType in project gpconnect-demonstrator by nhsconnect.
the class MedicationStatementResourceProvider method getMedicationStatementResource.
public MedicationStatement getMedicationStatementResource(MedicationStatementDetail statementDetail) {
MedicationStatement medicationStatement = new MedicationStatement();
medicationStatement.setId(statementDetail.getId().toString());
List<Identifier> identifiers = new ArrayList<>();
Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(statementDetail.getGuid());
identifiers.add(identifier);
medicationStatement.setIdentifier(identifiers);
medicationStatement.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_STATEMENT));
medicationStatement.addExtension(new Extension(SystemURL.SD_CC_EXT_MEDICATION_STATEMENT_LAST_ISSUE, new DateTimeType(statementDetail.getLastIssueDate(), TemporalPrecisionEnum.DAY)));
if (statementDetail.getMedicationRequestPlanId() != null) {
medicationStatement.addBasedOn(new Reference(new IdType("MedicationRequest", statementDetail.getMedicationRequestPlanId())));
}
try {
medicationStatement.setStatus(MedicationStatementStatus.fromCode(statementDetail.getStatusCode()));
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
if (statementDetail.getMedicationId() != null) {
medicationStatement.setMedication(new Reference(new IdType("Medication", statementDetail.getMedicationId())));
}
medicationStatement.setEffective(new Period().setStart(statementDetail.getStartDate()).setEnd(statementDetail.getEndDate()));
medicationStatement.setDateAsserted(statementDetail.getDateAsserted());
if (statementDetail.getPatientId() != null)
medicationStatement.setSubject(new Reference(new IdType("Patient", statementDetail.getPatientId())));
try {
medicationStatement.setTaken(statementDetail.getTakenCode() != null ? MedicationStatementTaken.fromCode(statementDetail.getTakenCode()) : MedicationStatementTaken.UNK);
} catch (FHIRException e) {
throw new UnprocessableEntityException(e.getMessage());
}
setReasonCodes(medicationStatement, statementDetail);
setNotes(medicationStatement, statementDetail);
String dosageText = statementDetail.getDosageText();
medicationStatement.addDosage(new Dosage().setText(dosageText == null || dosageText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageText).setPatientInstruction(statementDetail.getDosagePatientInstruction()));
String prescribingAgency = statementDetail.getPrescribingAgency();
if (prescribingAgency != null && !prescribingAgency.trim().isEmpty()) {
String prescribingAgencyDisplay = "";
if (prescribingAgency.equalsIgnoreCase("prescribed-at-gp-practice")) {
prescribingAgencyDisplay = "Prescribed at GP practice";
} else if (prescribingAgency.equalsIgnoreCase("prescribed-by-another-organisation")) {
prescribingAgencyDisplay = "Prescribed by another organisation";
}
Coding coding = new Coding(SystemURL.CS_CC_PRESCRIBING_AGENCY_STU3, prescribingAgency, prescribingAgencyDisplay);
CodeableConcept codeableConcept = new CodeableConcept().addCoding(coding);
medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_PRESCRIBING_AGENCY, codeableConcept));
}
// #281 1.2.5 add dosageLastChanged
Date dosageLastChanged = statementDetail.getDosageLastChanged();
if (dosageLastChanged != null) {
medicationStatement.addExtension(new Extension(SystemURL.SD_EXTENSION_CC_DOSAGE_LAST_CHANGED, new DateTimeType(dosageLastChanged)));
}
return medicationStatement;
}
use of org.hl7.fhir.dstu3.model.DateTimeType in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method registerPatientResourceConverterToPatientDetail.
private PatientDetails registerPatientResourceConverterToPatientDetail(Patient patientResource) {
PatientDetails patientDetails = new PatientDetails();
HumanName name = patientResource.getNameFirstRep();
String givenNames = name.getGiven().stream().map(n -> n.getValue()).collect(Collectors.joining(","));
patientDetails.setForename(givenNames);
patientDetails.setSurname(name.getFamily());
patientDetails.setDateOfBirth(patientResource.getBirthDate());
if (patientResource.getGender() != null) {
patientDetails.setGender(patientResource.getGender().toString());
}
patientDetails.setNhsNumber(patientResource.getIdentifierFirstRep().getValue());
DateTimeType deceased = (DateTimeType) patientResource.getDeceased();
if (deceased != null) {
try {
patientDetails.setDeceased((deceased.getValue()));
} catch (ClassCastException cce) {
throwUnprocessableEntity422_InvalidResourceException("The multiple deceased property is expected to be a datetime");
}
}
// activate patient as temporary
patientDetails.setRegistrationStartDateTime(new Date());
// patientDetails.setRegistrationEndDateTime(getRegistrationEndDate(patientResource));
patientDetails.setRegistrationStatus(ACTIVE_REGISTRATION_STATUS);
patientDetails.setRegistrationType(TEMPORARY_RESIDENT_REGISTRATION_TYPE);
updateAddressAndTelecom(patientResource, patientDetails);
// set some standard values for defaults, ensure managing org is always returned
// added at 1.2.2 7 is A20047 the default GP Practice
patientDetails.setManagingOrganization("7");
return patientDetails;
}
use of org.hl7.fhir.dstu3.model.DateTimeType in project gpconnect-demonstrator by nhsconnect.
the class StructuredAllergyIntoleranceBuilder method buildStructuredAllergyIntolerence.
public Bundle buildStructuredAllergyIntolerence(String NHS, Set<String> practitionerIds, Bundle bundle, Boolean includedResolved) {
List<StructuredAllergyIntoleranceEntity> allergyData = structuredAllergySearch.getAllergyIntollerence(NHS);
ListResource activeList = initiateListResource(NHS, ACTIVE_ALLERGIES_DISPLAY, allergyData);
ListResource resolvedList = initiateListResource(NHS, RESOLVED_ALLERGIES_DISPLAY, allergyData);
// This is patient 5 example 2 only
if (allergyData.size() == 1 && allergyData.get(0).getClinicalStatus().equals(SystemConstants.NO_KNOWN)) {
StructuredAllergyIntoleranceEntity noKnownAllergy = allergyData.get(0);
// #214 had incorrect code and value for no known allergies
CodeableConcept noKnownAllergies = createCoding(SystemURL.VS_LIST_EMPTY_REASON_CODE, NO_CONTENT_RECORDED, NO_CONTENT_RECORDED_DISPLAY);
noKnownAllergies.setText("No Known Allergies");
// activeList.setEmptyReason(noKnownAllergies);
// see spec example 2 no known allergies positively asserted
Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyData.get(0).getPatientRef());
String noKnownAllergyId = noKnownAllergy.getGuid();
Reference allergyIntolerance = new Reference("AllergyIntolerance/" + noKnownAllergyId);
Resource noKnownAllergyResource = createNoKnownAllergy(noKnownAllergy);
activeList.setSubject(patient);
// reference to AllergyIntolerance item
activeList.addEntry().setItem(allergyIntolerance);
activeList.setOrderedBy(createCoding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date"));
bundle.addEntry().setResource(activeList);
bundle.addEntry().setResource(noKnownAllergyResource);
if (includedResolved) {
resolvedList.setSubject(patient);
resolvedList.setEmptyReason(noKnownAllergies);
bundle.addEntry().setResource(resolvedList);
}
return bundle;
}
for (StructuredAllergyIntoleranceEntity allergyIntoleranceEntity : allergyData) {
AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
allergyIntolerance.setOnset(new DateTimeType(allergyIntoleranceEntity.getOnSetDateTime()));
allergyIntolerance.setMeta(createMeta(SystemURL.SD_CC_ALLERGY_INTOLERANCE));
allergyIntolerance.setId(allergyIntoleranceEntity.getId().toString());
List<Identifier> identifiers = new ArrayList<>();
Identifier identifier1 = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(allergyIntoleranceEntity.getGuid());
identifiers.add(identifier1);
allergyIntolerance.setIdentifier(identifiers);
if (allergyIntoleranceEntity.getClinicalStatus().equals(SystemConstants.ACTIVE)) {
allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
} else {
allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
}
if (allergyIntoleranceEntity.getCategory().equals(SystemConstants.MEDICATION)) {
allergyIntolerance.addCategory(AllergyIntoleranceCategory.MEDICATION);
} else {
allergyIntolerance.addCategory(AllergyIntoleranceCategory.ENVIRONMENT);
}
allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.UNCONFIRMED);
// CODE
codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getConceptCode(), allergyIntoleranceEntity.getConceptDisplay()).addDescription(allergyIntoleranceEntity.getDescCode(), allergyIntoleranceEntity.getDescDisplay()).addTranslation(allergyIntoleranceEntity.getCodeTranslationRef());
allergyIntolerance.setCode(codeableConceptBuilder.build());
codeableConceptBuilder.clear();
allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
allergyIntolerance.setPatient(patient);
Annotation noteAnnotation = new Annotation(new StringType(allergyIntoleranceEntity.getNote()));
allergyIntolerance.setNote(Collections.singletonList(noteAnnotation));
AllergyIntoleranceReactionComponent reaction = new AllergyIntoleranceReactionComponent();
// MANIFESTATION
List<CodeableConcept> theManifestation = new ArrayList<>();
codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getManifestationCoding(), allergyIntoleranceEntity.getManifestationDisplay()).addDescription(allergyIntoleranceEntity.getManifestationDescCoding(), allergyIntoleranceEntity.getManifestationDescDisplay()).addTranslation(allergyIntoleranceEntity.getManTranslationRef());
theManifestation.add(codeableConceptBuilder.build());
codeableConceptBuilder.clear();
reaction.setManifestation(theManifestation);
reaction.setDescription(allergyIntoleranceEntity.getNote());
// SEVERITY
try {
reaction.setSeverity(AllergyIntoleranceSeverity.fromCode(allergyIntoleranceEntity.getSeverity()));
} catch (FHIRException e) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Unknown severity: " + allergyIntoleranceEntity.getSeverity()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
}
// EXPOSURE
CodeableConcept exposureRoute = new CodeableConcept();
reaction.setExposureRoute(exposureRoute);
allergyIntolerance.addReaction(reaction);
// RECORDER
final Reference refValue = new Reference();
final Identifier identifier = new Identifier();
final String recorder = allergyIntoleranceEntity.getRecorder();
// This is just an example to demonstrate using Reference element instead of Identifier element
if (recorder.equals(patient2NhsNo.trim())) {
Reference rec = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
allergyIntolerance.setRecorder(rec);
} else if (patientRepository.findByNhsNumber(recorder) != null) {
identifier.setSystem(SystemURL.ID_NHS_NUMBER);
identifier.setValue(recorder);
refValue.setIdentifier(identifier);
allergyIntolerance.setRecorder(refValue);
} else if (practitionerSearch.findPractitionerByUserId(recorder) != null) {
refValue.setReference("Practitioner/" + recorder);
allergyIntolerance.setRecorder(refValue);
practitionerIds.add(recorder);
}
// CLINICAL STATUS
List<Extension> extensions = new ArrayList<>();
if (allergyIntolerance.getClinicalStatus().getDisplay().contains("Active")) {
listResourceBuilder(activeList, allergyIntolerance, false);
bundle.addEntry().setResource(allergyIntolerance);
} else if (allergyIntolerance.getClinicalStatus().getDisplay().equals("Resolved") && includedResolved.equals(true)) {
listResourceBuilder(resolvedList, allergyIntolerance, true);
allergyIntolerance.setLastOccurrence(allergyIntoleranceEntity.getEndDate());
final Extension allergyEndExtension = createAllergyEndExtension(allergyIntoleranceEntity);
extensions.add(allergyEndExtension);
}
if (!extensions.isEmpty()) {
allergyIntolerance.setExtension(extensions);
}
// ASSERTER
Reference asserter = allergyIntolerance.getAsserter();
if (asserter != null && asserter.getReference() != null && asserter.getReference().startsWith("Practitioner")) {
String[] split = asserter.getReference().split("/");
practitionerIds.add(split[1]);
}
}
if (!activeList.hasEntry()) {
addEmptyListNote(activeList);
addEmptyReasonCode(activeList);
}
bundle.addEntry().setResource(activeList);
if (includedResolved && !resolvedList.hasEntry()) {
addEmptyListNote(resolvedList);
addEmptyReasonCode(resolvedList);
}
if (includedResolved) {
bundle.addEntry().setResource(resolvedList);
}
return bundle;
}
use of org.hl7.fhir.dstu3.model.DateTimeType in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method patientDetailsToMinimalPatient.
private Patient patientDetailsToMinimalPatient(PatientDetails patientDetails) throws FHIRException {
Patient patient = new Patient();
Date lastUpdated = patientDetails.getLastUpdated() == null ? new Date() : patientDetails.getLastUpdated();
String resourceId = String.valueOf(patientDetails.getId());
String versionId = String.valueOf(lastUpdated.getTime());
String resourceType = patient.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
patient.setId(id);
patient.getMeta().setVersionId(versionId);
patient.getMeta().setLastUpdated(lastUpdated);
patient.getMeta().addProfile(SystemURL.SD_GPC_PATIENT);
Identifier patientNhsNumber = new Identifier().setSystem(SystemURL.ID_NHS_NUMBER).setValue(patientDetails.getNhsNumber());
Extension extension = createCodingExtension("01", "Number present and verified", SystemURL.CS_CC_NHS_NUMBER_VERIF, SystemURL.SD_CC_EXT_NHS_NUMBER_VERIF);
patientNhsNumber.addExtension(extension);
patient.addIdentifier(patientNhsNumber);
patient.setBirthDate(patientDetails.getDateOfBirth());
String gender = patientDetails.getGender();
if (gender != null) {
patient.setGender(AdministrativeGender.fromCode(gender.toLowerCase(Locale.UK)));
}
Date registrationEndDateTime = patientDetails.getRegistrationEndDateTime();
Date registrationStartDateTime = patientDetails.getRegistrationStartDateTime();
Extension regDetailsExtension = new Extension(SystemURL.SD_EXTENSION_CC_REG_DETAILS);
Period registrationPeriod = new Period().setStart(registrationStartDateTime).setEnd(registrationEndDateTime);
Extension regPeriodExt = new Extension(SystemURL.SD_CC_EXT_REGISTRATION_PERIOD, registrationPeriod);
regDetailsExtension.addExtension(regPeriodExt);
String registrationStatusValue = patientDetails.getRegistrationStatus();
patient.setActive(ACTIVE_REGISTRATION_STATUS.equals(registrationStatusValue) || null == registrationStatusValue);
String registrationTypeValue = patientDetails.getRegistrationType();
if (registrationTypeValue != null) {
Coding regTypeCode = new Coding();
regTypeCode.setCode(registrationTypeValue);
// Should always be Temporary
regTypeCode.setDisplay("Temporary");
regTypeCode.setSystem(SystemURL.CS_REGISTRATION_TYPE);
CodeableConcept regTypeConcept = new CodeableConcept();
regTypeConcept.addCoding(regTypeCode);
Extension regTypeExt = new Extension(SystemURL.SD_CC_EXT_REGISTRATION_TYPE, regTypeConcept);
regDetailsExtension.addExtension(regTypeExt);
}
patient.addExtension(regDetailsExtension);
String maritalStatus = patientDetails.getMaritalStatus();
if (maritalStatus != null) {
CodeableConcept marital = new CodeableConcept();
Coding maritalCoding = new Coding();
maritalCoding.setSystem(SystemURL.VS_CC_MARITAL_STATUS);
maritalCoding.setCode(patientDetails.getMaritalStatus());
maritalCoding.setDisplay("Married");
marital.addCoding(maritalCoding);
patient.setMaritalStatus(marital);
}
patient.setMultipleBirth(patientDetails.isMultipleBirth());
if (patientDetails.isDeceased()) {
DateTimeType decesed = new DateTimeType(patientDetails.getDeceased());
patient.setDeceased(decesed);
}
return patient;
}
Aggregations