use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processAllergyProblemAct.
protected void processAllergyProblemAct(ListResource list, Element concern) throws Exception {
cda.checkTemplateId(concern, "2.16.840.1.113883.10.20.22.4.30");
// Allergy Problem Act - this is a concern - we treat the concern as information about it's place in the list
checkNoNegationOrNullFlavor(concern, "Allergy Problem Act");
checkNoSubject(concern, "Allergy Problem Act");
// SHALL contain exactly one [1..1] Allergy - intolerance Observation
for (Element entry : cda.getChildren(concern, "entryRelationship")) {
Element obs = cda.getChild(entry, "observation");
cda.checkTemplateId(obs, "2.16.840.1.113883.10.20.22.4.7");
checkNoNegationOrNullFlavor(obs, "Allergy - intolerance Observation");
checkNoSubject(obs, "Allergy Problem Act");
AllergyIntolerance ai = new AllergyIntolerance();
ListEntryComponent item = addItemToList(list, ai);
// SHALL contain at least one [1..*] id (CONF:7472).
for (Element e : cda.getChildren(concern, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] statusCode, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.80.68 HITSPProblemStatus DYNAMIC (CONF:7485)
// the status code is about the concern (e.g. the entry in the list)
// possible values: active, suspended, aborted, completed, with an effective time
String s = cda.getStatus(concern);
item.setFlag(Factory.newCodeableConcept(s, "http://hl7.org/fhir/v3/ActStatus", s));
if (// only on this condition?
s.equals("aborted"))
item.setDeleted(true);
// SHALL contain exactly one [1..1] effectiveTime (CONF:7498)
Period p = convert.makePeriodFromIVL(cda.getChild(concern, "effectiveTime"));
item.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/list-period", p, false));
if (p.getEnd() != null)
item.setDate(p.getEnd());
else
item.setDate(p.getStart());
// SHALL contain at least one [1..*] id (CONF:7382)
for (Element e : cda.getChildren(obs, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] effectiveTime (CONF:7387)
ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergyintolerance-period", convert.makePeriodFromIVL(cda.getChild(obs, "effectiveTime")), false));
// SHALL contain exactly one [1..1] value with @xsi:type="CD" (CONF:7390)
CodeableConcept type = convert.makeCodeableConceptFromCD(cda.getChild(obs, "value"));
// This value SHALL contain @code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.6.2 Allergy/Adverse Event Type
String ss = type.getCoding().get(0).getCode();
if (ss.equals("416098002") || ss.equals("414285001"))
ai.setType(AllergyIntoleranceType.ALLERGY);
else if (ss.equals("59037007") || ss.equals("235719002"))
ai.setType(AllergyIntoleranceType.INTOLERANCE);
ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergy-category", type, false));
// SHOULD contain zero or one [0..1] participant (CONF:7402) such that it
// ......This playingEntity SHALL contain exactly one [1..1] code
ai.setCode(convert.makeCodeableConceptFromCD(cda.getDescendent(obs, "participant/participantRole/playingEntity/code")));
// SHOULD contain zero or more [0..*] entryRelationship (CONF:7447) such that it SHALL contain exactly one [1..1] Reaction Observation (templateId:2.16.840.1.113883.10.20.22.4.9) (CONF:7450).
for (Element e : cda.getChildren(obs, "entryRelationship")) {
Element child = cda.getChild(e, "observation");
if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.28") && ai.getClinicalStatus() == null) {
// SHALL contain exactly one [1..1] value with @xsi:type="CE", where the @code SHALL be selected from ValueSet Problem Status Value Set 2.16.840.1.113883.3.88.12.80.68 DYNAMIC (CONF:7322).
// 55561003 SNOMED CT Active
// 73425007 SNOMED CT Inactive
// 413322009 SNOMED CT Resolved
String sc = cda.getChild(child, "value").getAttribute("code");
if (sc.equals("55561003")) {
ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
ai.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
} else
ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
} else if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.9")) {
ai.getReaction().add(processAdverseReactionObservation(child));
}
}
// SHOULD contain zero or one [0..1] entryRelationship (CONF:9961) such that it SHALL contain exactly one [1..1] Severity Observation (templateId:2.16.840.1.113883.10.20.22.4.8) (CONF:9963).
ai.setCriticality(readCriticality(cda.getSeverity(obs)));
}
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processProcedure.
protected void processProcedure(ListResource list, Element procedure, ProcedureType type) throws Exception {
switch(type) {
case Procedure:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14");
break;
case Observation:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13");
break;
case Act:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12");
}
checkNoNegationOrNullFlavor(procedure, "Procedure (" + type + ")");
checkNoSubject(procedure, "Procedure (" + type + ")");
Procedure p = new Procedure();
addItemToList(list, p);
// moodCode is either INT or EVN. INT is not handled yet. INT is deprecated anyway
if (procedure.getAttribute("moodCode").equals("INT"))
p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-planned", Factory.newBoolean(true), false));
// SHALL contain at least one [1..*] id (CONF:7655).
for (Element e : cda.getChildren(procedure, "id")) p.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] code (CONF:7656).
// This code @code in a procedure activity SHOULD be selected from LOINC or SNOMED CT and MAY be selected from CPT-4, ICD9 Procedures, ICD10 Procedures
p.setCode(convert.makeCodeableConceptFromCD(cda.getChild(procedure, "code")));
// SHALL contain exactly one [1..1] statusCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.11.20.9.22 ProcedureAct
// completed | active | aborted | cancelled - not in FHIR
p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-status", Factory.newCode(cda.getStatus(procedure)), false));
// SHOULD contain zero or one [0..1] effectiveTime (CONF:7662).
p.setPerformed(convert.makePeriodFromIVL(cda.getChild(procedure, "effectiveTime")));
// MAY contain zero or one [0..1] priorityCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.1.11.16866 ActPriority DYNAMIC (CONF:7668)
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-priority", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "priorityCode")), false));
// MAY contain zero or one [0..1] methodCode (CONF:7670).
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-method", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "methodCode")), false));
if (type == ProcedureType.Observation) {
// for Procedure-Observation:
// 9. SHALL contain exactly one [1..1] value (CONF:16846).
// don't know what this is. It's not the actual result of the procedure (that goes in results "This section records ... procedure observations"), and there seems to be no value. The example as <value xsi:type="CD"/> which is not valid
// so we ignore this for now
}
// SHOULD contain zero or more [0..*] targetSiteCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.8.9 Body site DYNAMIC (CONF:7683).
for (Element e : cda.getChildren(procedure, "targetSiteCode")) p.addBodySite(convert.makeCodeableConceptFromCD(e));
// SHOULD contain zero or more [0..*] performer (CONF:7718) such that it
for (Element e : cda.getChildren(procedure, "performer")) {
ProcedurePerformerComponent pp = new ProcedurePerformerComponent();
p.getPerformer().add(pp);
pp.setActor(makeReferenceToPractitionerForAssignedEntity(e, p));
}
for (Element participant : cda.getChildren(procedure, "participant")) {
Element participantRole = cda.getlastChild(participant);
if (type == ProcedureType.Procedure && cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.37")) {
// MAY contain zero or more [0..*] participant (CONF:7751) such that it SHALL contain exactly one [1..1] @typeCode="DEV" Device
// implanted devices
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/implanted-devices", Factory.makeReference(processDevice(participantRole, p)), false));
} else if (cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.32")) {
// MAY contain zero or more [0..*] participant (CONF:7765) such that it SHALL contain exactly one [1..1] Service Delivery Location (templateId:2.16.840.1.113883.10.20.22.4.32) (CONF:7767)
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/location", Factory.makeReference(processSDLocation(participantRole, p)), false));
}
}
for (Element e : cda.getChildren(procedure, "entryRelationship")) {
Element a = /* act*/
cda.getlastChild(e);
if (a.getLocalName().equals("encounter")) {
// MAY contain zero or more [0..*] entryRelationship (CONF:7768) such that it SHALL contain exactly one encounter which SHALL contain exactly one [1..1] id (CONF:7773).
// todo - and process as a full encounter while we're at it
} else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.20")) {
// MAY contain zero or one [0..1] entryRelationship (CONF:7775) such that it SHALL contain exactly one [1..1] Instructions (templateId:2.16.840.1.113883.10.20.22.4.20) (CONF:7778).
// had code for type, plus text for instructions
Extension n = Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions", null, true);
n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-type", convert.makeCodeableConceptFromCD(cda.getChild(a, "code")), false));
n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-text", convert.makeStringFromED(cda.getChild(a, "text")), false));
p.getExtension().add(n);
} else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.19")) {
// MAY contain zero or more [0..*] entryRelationship (CONF:7779) such that it SHALL contain exactly one [1..1] Indication (templateId:2.16.840.1.113883.10.20.22.4.19) (CONF:7781).
p.addReasonCode(processIndication(a));
} else if (cda.hasTemplateId(cda.getlastChild(e), "2.16.840.1.113883.10.20.22.4.16")) {
// MAY contain zero or one [0..1] entryRelationship (CONF:7886) such that it SHALL contain exactly one [1..1] Medication Activity (templateId:2.16.840.1.113883.10.20.22.4.16) (CONF:7888).
// todo
}
}
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processSocialObservation.
protected void processSocialObservation(ListResource list, Element so, SocialHistoryType type) throws Exception {
Observation obs = new Observation();
addItemToList(list, obs);
switch(type) {
case SocialHistory:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.22.4.38");
// SHALL contain exactly one [1..1] code (CONF:8558/).
obs.setCode(convert.makeCodeableConceptFromCD(cda.getChild(so, "code")));
break;
case Pregnancy:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.15.3.8");
// SHALL contain exactly one [1..1] code (CONF:8558/), which SHALL be an assertion
obs.setCode(Factory.newCodeableConcept("11449-6", "http://loinc.org", "Pregnancy Status"));
break;
case SmokingStatus:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.22.4.78");
// SHALL contain exactly one [1..1] code (CONF:8558/), which SHALL be an assertion
obs.setCode(Factory.newCodeableConcept("72166-2", "http://loinc.org", "Tobacco Smoking Status"));
break;
case TobaccoUse:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.22.4.12");
// SHALL contain exactly one [1..1] code (CONF:8558/), which SHALL be an assertion
obs.setCode(Factory.newCodeableConcept("11367-0", "http://loinc.org", "History of Tobacco Use"));
}
// SHALL contain at least one [1..*] id (8551).
for (Element e : cda.getChildren(so, "id")) obs.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] statusCode (CONF:8553/455/14809).
// a. This statusCode SHALL contain exactly one [1..1] @code="completed" Completed (CodeSystem: ActStatus 2.16.840.1.113883.5.14 STATIC) (CONF:19117).
obs.setStatus(ObservationStatus.FINAL);
// SHOULD contain zero or one [0..1] effectiveTime (CONF:2018/14814).
// for smoking status/tobacco: low only. in R2, this is just value. So we treat low only as just a value
Element et = cda.getChild(so, "effectiveTime");
if (et != null) {
if (cda.getChild(et, "low") != null)
obs.setEffective(convert.makeDateTimeFromTS(cda.getChild(et, "low")));
else
obs.setEffective(convert.makeDateTimeFromIVL(et));
}
// a. Observation/value can be any data type.
for (Element e : cda.getChildren(so, "value")) if (obs.getValue() == null) {
// special case for pregnancy:
if (type == SocialHistoryType.Pregnancy && "true".equals(e.getAttribute("negationInd"))) {
obs.setValue(Factory.newCodeableConcept("60001007", "http://snomed.info/sct", "Not pregnant"));
} else {
// negationInd is not described. but it might well be used. For now, we blow up
checkNoNegation(so, "Social Observation (" + type + ")");
if (so.hasAttribute("nullFlavor"))
obs.setValue(convert.makeCodeableConceptFromNullFlavor(so.getAttribute("nullFlavor")));
else if (e.hasAttribute("nullFlavor") && !"OTH".equals(e.getAttribute("nullFlavor")))
obs.setValue(convert.makeCodeableConceptFromNullFlavor(e.getAttribute("nullFlavor")));
else
obs.setValue(convert.makeTypeFromANY(e));
}
} else
throw new Exception("too many values on Social Observation");
if (type == SocialHistoryType.Pregnancy) {
for (Element e : cda.getChildren(so, "entyRelationship")) {
Element dd = cda.getChild(e, "observation");
checkNoNegationOrNullFlavor(dd, "Estimated Date of Delivery");
// MAY contain zero or one [0..1] entryRelationship (CONF:458) such that it
// SHALL contain exactly one [1..1] @typeCode="REFR" Refers to (CodeSystem: HL7ActRelationshipType 2.16.840.1.113883.5.1002 STATIC) (CONF:459).
// SHALL contain exactly one [1..1] Estimated Date of Delivery (templateId:2.16.840.1.113883.10.20.15.3.1) (CONF:15584).
Observation co = new Observation();
String id = nextRef();
co.setId(id);
obs.getContained().add(co);
ObservationRelatedComponent or = new ObservationRelatedComponent();
obs.getRelated().add(or);
or.setType(ObservationRelationshipType.HASMEMBER);
or.setTarget(Factory.makeReference("#" + id));
co.setCode(Factory.newCodeableConcept("11778-8", "http://loinc.org", "Delivery date Estimated"));
// not legal, see gForge http://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&tracker_item_id=3125&start=0
co.setValue(convert.makeDateTimeFromTS(cda.getChild(dd, "value")));
}
}
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project org.hl7.fhir.core by hapifhir.
the class PackagePreparer method main.
public static void main(String[] args) {
for (File f : new File("C:\\work\\fhirserver\\resources\\mihin").listFiles()) {
try {
org.hl7.fhir.dstu3.model.Resource r = new org.hl7.fhir.dstu3.formats.JsonParser().parse(new FileInputStream(f));
if (r instanceof Bundle) {
Bundle b = (Bundle) r;
for (BundleEntryComponent be : b.getEntry()) {
try {
org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_30_40.convertResource(be.getResource());
if (r4.getId().startsWith(r4.fhirType() + "-"))
be.getResource().setId(r4.getId().substring(r4.fhirType().length() + 1));
if (be.getResource().hasId())
new org.hl7.fhir.r4.formats.JsonParser().compose(new FileOutputStream(Utilities.path("C:\\work\\fhirserver\\resources\\fhir.test.data\\3.5.0\\package", be.getResource().fhirType() + "-" + be.getResource().getId() + ".json")), r4);
else
System.out.println(f.getName() + " bundle entry has no id");
} catch (Exception e) {
System.out.println(f.getName() + ": " + e.getMessage());
}
}
} else if (r.hasId())
new org.hl7.fhir.r4.formats.JsonParser().compose(new FileOutputStream(Utilities.path(Utilities.getDirectoryForFile(f.getAbsolutePath()), r.fhirType() + "-" + r.getId() + ".json")), VersionConvertorFactory_30_40.convertResource(r));
else
System.out.println(f.getName() + " has no id");
} catch (Exception e) {
System.out.println(f.getName() + ": " + e.getMessage());
e.printStackTrace();
}
}
System.out.println("Completed OK");
}
use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project pathling by aehrc.
the class ImportExecutor method execute.
/**
* Executes an import request.
*
* @param inParams a FHIR {@link Parameters} object describing the import request
* @return a FHIR {@link OperationOutcome} resource describing the result
*/
@Nonnull
public OperationOutcome execute(@Nonnull @ResourceParam final Parameters inParams) {
// Parse and validate the JSON request.
final List<ParametersParameterComponent> sourceParams = inParams.getParameter().stream().filter(param -> "source".equals(param.getName())).collect(Collectors.toList());
if (sourceParams.isEmpty()) {
throw new InvalidUserInputError("Must provide at least one source parameter");
}
log.info("Received $import request");
// the corresponding table in the warehouse.
for (final ParametersParameterComponent sourceParam : sourceParams) {
final ParametersParameterComponent resourceTypeParam = sourceParam.getPart().stream().filter(param -> "resourceType".equals(param.getName())).findFirst().orElseThrow(() -> new InvalidUserInputError("Must provide resourceType for each source"));
final ParametersParameterComponent urlParam = sourceParam.getPart().stream().filter(param -> "url".equals(param.getName())).findFirst().orElseThrow(() -> new InvalidUserInputError("Must provide url for each source"));
// The mode parameter defaults to 'overwrite'.
final ImportMode importMode = sourceParam.getPart().stream().filter(param -> "mode".equals(param.getName()) && param.getValue() instanceof CodeType).findFirst().map(param -> ImportMode.fromCode(((CodeType) param.getValue()).asStringValue())).orElse(ImportMode.OVERWRITE);
final String resourceCode = ((CodeType) resourceTypeParam.getValue()).getCode();
final ResourceType resourceType = ResourceType.fromCode(resourceCode);
// Get an encoder based on the declared resource type within the source parameter.
final ExpressionEncoder<IBaseResource> fhirEncoder;
try {
fhirEncoder = fhirEncoders.of(resourceType.toCode());
} catch (final UnsupportedResourceError e) {
throw new InvalidUserInputError("Unsupported resource type: " + resourceCode);
}
// Read the resources from the source URL into a dataset of strings.
final Dataset<String> jsonStrings = readStringsFromUrl(urlParam);
// Parse each line into a HAPI FHIR object, then encode to a Spark dataset.
final Dataset<IBaseResource> resources = jsonStrings.map(jsonToResourceConverter(), fhirEncoder);
log.info("Importing {} resources (mode: {})", resourceType.toCode(), importMode.getCode());
if (importMode == ImportMode.OVERWRITE) {
database.overwrite(resourceType, resources.toDF());
} else {
database.merge(resourceType, resources.toDF());
}
}
// We return 200, as this operation is currently synchronous.
log.info("Import complete");
// Construct a response.
final OperationOutcome opOutcome = new OperationOutcome();
final OperationOutcomeIssueComponent issue = new OperationOutcomeIssueComponent();
issue.setSeverity(IssueSeverity.INFORMATION);
issue.setCode(IssueType.INFORMATIONAL);
issue.setDiagnostics("Data import completed successfully");
opOutcome.getIssue().add(issue);
return opOutcome;
}
Aggregations