use of org.hl7.fhir.dstu2.model.DateTimeType in project MobileAccessGateway by i4mi.
the class Iti65RequestConverter method processDocumentManifest.
/**
* ITI-65: process DocumentManifest resource from Bundle
* @param manifest
* @param submissionSet
*/
private void processDocumentManifest(DocumentManifest manifest, SubmissionSet submissionSet) {
// masterIdentifier SubmissionSet.uniqueId
Identifier masterIdentifier = manifest.getMasterIdentifier();
submissionSet.setUniqueId(noPrefix(masterIdentifier.getValue()));
submissionSet.assignEntryUuid();
manifest.setId(submissionSet.getEntryUuid());
CodeableConcept type = manifest.getType();
submissionSet.setContentTypeCode(transformCodeableConcept(type));
DateTimeType created = manifest.getCreatedElement();
submissionSet.setSubmissionTime(timestampFromDate(created));
// subject SubmissionSet.patientId
Reference ref = manifest.getSubject();
submissionSet.setPatientId(transformReferenceToIdentifiable(ref, manifest));
// Author
Extension authorRoleExt = manifest.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-author-authorrole");
if (manifest.hasAuthor() || (authorRoleExt != null)) {
Identifiable identifiable = null;
Reference author = manifest.getAuthorFirstRep();
if (authorRoleExt != null) {
Coding coding = authorRoleExt.castToCoding(authorRoleExt.getValue());
if (coding != null) {
identifiable = new Identifiable(coding.getCode(), new AssigningAuthority(noPrefix(coding.getSystem())));
}
}
submissionSet.setAuthor(transformAuthor(author, manifest.getContained(), identifiable));
}
// recipient SubmissionSet.intendedRecipient
for (Reference recipientRef : manifest.getRecipient()) {
Resource res = findResource(recipientRef, manifest.getContained());
if (res instanceof Practitioner) {
Recipient recipient = new Recipient();
recipient.setPerson(transform((Practitioner) res));
recipient.setTelecom(transform(((Practitioner) res).getTelecomFirstRep()));
submissionSet.getIntendedRecipients().add(recipient);
} else if (res instanceof Organization) {
Recipient recipient = new Recipient();
recipient.setOrganization(transform((Organization) res));
recipient.setTelecom(transform(((Organization) res).getTelecomFirstRep()));
submissionSet.getIntendedRecipients().add(recipient);
} else if (res instanceof PractitionerRole) {
Recipient recipient = new Recipient();
PractitionerRole role = (PractitionerRole) res;
recipient.setOrganization(transform((Organization) findResource(role.getOrganization(), manifest.getContained())));
recipient.setPerson(transform((Practitioner) findResource(role.getPractitioner(), manifest.getContained())));
recipient.setTelecom(transform(role.getTelecomFirstRep()));
submissionSet.getIntendedRecipients().add(recipient);
} else if (res instanceof Patient) {
Recipient recipient = new Recipient();
recipient.setPerson(transform((Patient) res));
recipient.setTelecom(transform(((Patient) res).getTelecomFirstRep()));
} else if (res instanceof RelatedPerson) {
Recipient recipient = new Recipient();
recipient.setPerson(transform((RelatedPerson) res));
recipient.setTelecom(transform(((RelatedPerson) res).getTelecomFirstRep()));
}
}
// source SubmissionSet.sourceId
String source = noPrefix(manifest.getSource());
submissionSet.setSourceId(source);
String description = manifest.getDescription();
if (description != null)
submissionSet.setTitle(localizedString(description));
}
use of org.hl7.fhir.dstu2.model.DateTimeType in project MobileAccessGateway by i4mi.
the class Iti65RequestConverter method processDocumentManifest.
/**
* ITI-65: process ListResource resource from Bundle
* @param manifest
* @param submissionSet
*/
private void processDocumentManifest(ListResource manifest, SubmissionSet submissionSet) {
for (Identifier id : manifest.getIdentifier()) {
if (id.getUse() == null || id.getUse().equals(Identifier.IdentifierUse.OFFICIAL)) {
} else if (id.getUse().equals(Identifier.IdentifierUse.USUAL)) {
String uniqueId = noPrefix(id.getValue());
submissionSet.setUniqueId(uniqueId);
}
}
submissionSet.assignEntryUuid();
manifest.setId(submissionSet.getEntryUuid());
Extension designationType = manifest.getExtensionByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType");
if (designationType != null && designationType.getValue() instanceof CodeableConcept) {
submissionSet.setContentTypeCode(transformCodeableConcept((CodeableConcept) designationType.getValue()));
}
DateTimeType created = manifest.getDateElement();
submissionSet.setSubmissionTime(timestampFromDate(created));
// subject SubmissionSet.patientId
Reference ref = manifest.getSubject();
submissionSet.setPatientId(transformReferenceToIdentifiable(ref, manifest));
// Author
Extension authorRoleExt = manifest.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-author-authorrole");
if (manifest.hasSource() || (authorRoleExt != null)) {
Identifiable identifiable = null;
Reference author = manifest.getSource();
if (authorRoleExt != null) {
Coding coding = authorRoleExt.castToCoding(authorRoleExt.getValue());
if (coding != null) {
identifiable = new Identifiable(coding.getCode(), new AssigningAuthority(noPrefix(coding.getSystem())));
}
}
submissionSet.setAuthor(transformAuthor(author, manifest.getContained(), identifiable));
}
for (Extension recipientExt : manifest.getExtensionsByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-intendedRecipient")) {
Reference recipientRef = (Reference) recipientExt.getValue();
Resource res = findResource(recipientRef, manifest.getContained());
if (res instanceof Practitioner) {
Recipient recipient = new Recipient();
recipient.setPerson(transform((Practitioner) res));
recipient.setTelecom(transform(((Practitioner) res).getTelecomFirstRep()));
submissionSet.getIntendedRecipients().add(recipient);
} else if (res instanceof Organization) {
Recipient recipient = new Recipient();
recipient.setOrganization(transform((Organization) res));
recipient.setTelecom(transform(((Organization) res).getTelecomFirstRep()));
submissionSet.getIntendedRecipients().add(recipient);
} else if (res instanceof PractitionerRole) {
Recipient recipient = new Recipient();
PractitionerRole role = (PractitionerRole) res;
recipient.setOrganization(transform((Organization) findResource(role.getOrganization(), manifest.getContained())));
recipient.setPerson(transform((Practitioner) findResource(role.getPractitioner(), manifest.getContained())));
recipient.setTelecom(transform(role.getTelecomFirstRep()));
submissionSet.getIntendedRecipients().add(recipient);
} else if (res instanceof Patient) {
Recipient recipient = new Recipient();
recipient.setPerson(transform((Patient) res));
recipient.setTelecom(transform(((Patient) res).getTelecomFirstRep()));
} else if (res instanceof RelatedPerson) {
Recipient recipient = new Recipient();
recipient.setPerson(transform((RelatedPerson) res));
recipient.setTelecom(transform(((RelatedPerson) res).getTelecomFirstRep()));
}
}
Extension source = manifest.getExtensionByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-sourceId");
if (source != null && source.getValue() instanceof Identifier) {
submissionSet.setSourceId(noPrefix(((Identifier) source.getValue()).getValue()));
}
String title = manifest.getTitle();
if (title != null)
submissionSet.setTitle(localizedString(title));
Annotation note = manifest.getNoteFirstRep();
if (note != null && note.hasText()) {
submissionSet.setComments(localizedString(note.getText()));
}
}
use of org.hl7.fhir.dstu2.model.DateTimeType in project synthea by synthetichealth.
the class FhirR4 method medicationAdministration.
/**
* Add a MedicationAdministration if needed for the given medication.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the MedicationAdministration to
* @param encounterEntry Current Encounter entry
* @param medication The Medication
* @param medicationRequest The related medicationRequest
* @return The added Entry
*/
private static BundleEntryComponent medicationAdministration(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication, MedicationRequest medicationRequest) {
MedicationAdministration medicationResource = new MedicationAdministration();
medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
medicationResource.setContext(new Reference(encounterEntry.getFullUrl()));
Code code = medication.codes.get(0);
String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
medicationResource.setEffective(new DateTimeType(new Date(medication.start)));
medicationResource.setStatus(MedicationAdministration.MedicationAdministrationStatus.COMPLETED);
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
MedicationAdministrationDosageComponent dosage = new MedicationAdministrationDosageComponent();
// as_needed is false
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
dosage.setDose((SimpleQuantity) dose);
if (rxInfo.has("instructions")) {
for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
JsonObject instruction = instructionElement.getAsJsonObject();
dosage.setText(instruction.get("display").getAsString());
}
}
}
if (rxInfo.has("refills")) {
SimpleQuantity rate = new SimpleQuantity();
rate.setValue(rxInfo.get("refills").getAsLong());
dosage.setRate(rate);
}
medicationResource.setDosage(dosage);
}
if (!medication.reasons.isEmpty()) {
// Only one element in list
Code reason = medication.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
medicationResource.addReasonReference().setReference(entry.getFullUrl());
}
}
}
}
BundleEntryComponent medicationAdminEntry = newEntry(rand, bundle, medicationResource);
return medicationAdminEntry;
}
use of org.hl7.fhir.dstu2.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.dstu2.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;
}
Aggregations